76 lines
3.1 KiB
Java
76 lines
3.1 KiB
Java
package thaumicenergistics.common.blocks;
|
|
|
|
import java.util.List;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
import net.minecraft.world.ItemInteractionResult;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.EntityBlock;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
import net.minecraft.world.level.storage.loot.LootParams;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import thaumicenergistics.common.tiles.ThETileBase;
|
|
import thaumicenergistics.common.tiles.TileEssentiaVibrationChamber;
|
|
|
|
public abstract class OrientableEntityBlock extends Block implements EntityBlock {
|
|
|
|
public static final DirectionProperty FACING = DirectionProperty.create("facing", Direction.Plane.HORIZONTAL);
|
|
|
|
protected OrientableEntityBlock(Properties props) {
|
|
super(props);
|
|
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(FACING);
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
|
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
|
|
}
|
|
|
|
@Override
|
|
public abstract BlockEntity newBlockEntity(BlockPos pos, BlockState state);
|
|
|
|
/**
|
|
* 谐振仓:通配吸力模式,不再需要安瓿瓶切换燃料类型。
|
|
* 放行默认交互(若后续添加 GUI 则走 getMenuProvider)。
|
|
*/
|
|
@Override
|
|
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
|
if (level.isClientSide()) return ItemInteractionResult.SUCCESS;
|
|
BlockEntity be = level.getBlockEntity(pos);
|
|
if (!(be instanceof TileEssentiaVibrationChamber chamber)) return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
|
|
// 通配吸力:无需切换,直接放行
|
|
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
|
|
}
|
|
|
|
@Override
|
|
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean moved) {
|
|
if (!state.is(newState.getBlock())) {
|
|
BlockEntity be = level.getBlockEntity(pos);
|
|
if (be instanceof ThETileBase tb) tb.onBreakBlock();
|
|
}
|
|
super.onRemove(state, level, pos, newState, moved);
|
|
}
|
|
|
|
/**
|
|
* 挖掘掉落方块自身(不导出方块实体 NBT)。
|
|
*/
|
|
@Override
|
|
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
|
|
return List.of(new ItemStack(this));
|
|
}
|
|
}
|