minecraft-mod/remappedSrc/modchest/block/custom/steeringWheelBlock.java

69 lines
2.7 KiB
Java

package modchest.block.custom;
import modchest.block.entity.modBlockEntities;
import modchest.block.entity.steeringWheelEntity;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
//gibt dem Block steering_wheel eigenschaften, wie z.B. das Interaktionsmenü, oder Grafiken
public class steeringWheelBlock extends BlockWithEntity implements BlockEntityProvider {
public steeringWheelBlock(Settings settings) {
super(settings);
}
/* stuff benötigt um das Interaktionsmenü zu laden!*/
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock() != newState.getBlock()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof steeringWheelEntity) {
ItemScatterer.spawn(world, pos, (steeringWheelEntity)blockEntity);
world.updateComparators(pos,this);
}
super.onStateReplaced(state, world, pos, newState, moved);
}
}
@Override //wird bei einem rechtsklick aufgerufen (ersellt das Blockentity)
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient) {
NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos);
if (screenHandlerFactory != null) {
player.openHandledScreen(screenHandlerFactory);
}
}
return ActionResult.SUCCESS;
}
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new steeringWheelEntity(pos, state);
}
@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return validateTicker( type, modBlockEntities.steering_wheel_interface, steeringWheelEntity::tick);
}
}