2023-10-24 19:18:51 +02:00
|
|
|
package modchest.block.custom;
|
|
|
|
|
2023-10-29 15:08:26 +01:00
|
|
|
import modchest.block.entity.modBlockEntities;
|
2023-10-24 19:18:51 +02:00
|
|
|
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;
|
2023-10-29 15:08:26 +01:00
|
|
|
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;
|
2023-10-24 19:18:51 +02:00
|
|
|
import net.minecraft.util.ItemScatterer;
|
2023-10-29 15:08:26 +01:00
|
|
|
import net.minecraft.util.hit.BlockHitResult;
|
2023-10-24 19:18:51 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-29 15:08:26 +01:00
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
2023-10-24 19:18:51 +02:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
2023-10-29 15:08:26 +01:00
|
|
|
return new steeringWheelEntity(pos, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
|
|
|
|
return checkType( type, modBlockEntities.steering_wheel_interface, steeringWheelEntity::tick);
|
2023-10-24 19:18:51 +02:00
|
|
|
}
|
|
|
|
}
|