113 lines
4.8 KiB
Java
113 lines
4.8 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
import net.minecraft.world.Container;
|
|
import net.minecraft.world.Containers;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
|
|
public abstract class AbstractFurnaceBlock extends BaseEntityBlock {
|
|
public static final DirectionProperty FACING;
|
|
public static final BooleanProperty LIT;
|
|
|
|
protected AbstractFurnaceBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)AbstractFurnaceBlock.FACING, Direction.NORTH)).<Comparable, Boolean>setValue((Property<Comparable>)AbstractFurnaceBlock.LIT, false));
|
|
}
|
|
|
|
@Override
|
|
public int getLightEmission(final BlockState byg) {
|
|
return byg.<Boolean>getValue((Property<Boolean>)AbstractFurnaceBlock.LIT) ? super.getLightEmission(byg) : 0;
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
|
|
if (bjt.isClientSide) {
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
this.openContainer(bjt, fk, ayg);
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
|
|
protected abstract void openContainer(final Level bjt, final BlockPos fk, final Player ayg);
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)AbstractFurnaceBlock.FACING, bcn.getHorizontalDirection().getOpposite());
|
|
}
|
|
|
|
@Override
|
|
public void setPlacedBy(final Level bjt, final BlockPos fk, final BlockState byg, final LivingEntity akw, final ItemStack bek) {
|
|
if (bek.hasCustomHoverName()) {
|
|
final BlockEntity bwi7 = bjt.getBlockEntity(fk);
|
|
if (bwi7 instanceof AbstractFurnaceBlockEntity) {
|
|
((AbstractFurnaceBlockEntity)bwi7).setCustomName(bek.getHoverName());
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onRemove(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
|
|
if (byg1.getBlock() == byg4.getBlock()) {
|
|
return;
|
|
}
|
|
final BlockEntity bwi7 = bjt.getBlockEntity(fk);
|
|
if (bwi7 instanceof AbstractFurnaceBlockEntity) {
|
|
Containers.dropContents(bjt, fk, (Container)bwi7);
|
|
bjt.updateNeighbourForOutputSignal(fk, this);
|
|
}
|
|
super.onRemove(byg1, bjt, fk, byg4, boolean5);
|
|
}
|
|
|
|
@Override
|
|
public boolean hasAnalogOutputSignal(final BlockState byg) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getAnalogOutputSignal(final BlockState byg, final Level bjt, final BlockPos fk) {
|
|
return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(bjt.getBlockEntity(fk));
|
|
}
|
|
|
|
@Override
|
|
public RenderShape getRenderShape(final BlockState byg) {
|
|
return RenderShape.MODEL;
|
|
}
|
|
|
|
@Override
|
|
public BlockState rotate(final BlockState byg, final Rotation btr) {
|
|
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Direction>setValue((Property<Comparable>)AbstractFurnaceBlock.FACING, btr.rotate(byg.<Direction>getValue((Property<Direction>)AbstractFurnaceBlock.FACING)));
|
|
}
|
|
|
|
@Override
|
|
public BlockState mirror(final BlockState byg, final Mirror bsr) {
|
|
return byg.rotate(bsr.getRotation(byg.<Direction>getValue((Property<Direction>)AbstractFurnaceBlock.FACING)));
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(AbstractFurnaceBlock.FACING, AbstractFurnaceBlock.LIT);
|
|
}
|
|
|
|
static {
|
|
FACING = HorizontalDirectionalBlock.FACING;
|
|
LIT = RedstoneTorchBlock.LIT;
|
|
}
|
|
}
|