160 lines
7.7 KiB
Java
160 lines
7.7 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
import net.minecraft.world.entity.player.Inventory;
|
|
import net.minecraft.world.level.pathfinder.PathComputationType;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.core.particles.ParticleOptions;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import java.util.Random;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.inventory.PlayerEnderChestContainer;
|
|
import net.minecraft.stats.Stats;
|
|
import net.minecraft.world.MenuProvider;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.world.SimpleMenuProvider;
|
|
import net.minecraft.world.Container;
|
|
import net.minecraft.world.inventory.ChestMenu;
|
|
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.world.level.material.FluidState;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
|
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.entity.BlockEntityType;
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
|
|
|
|
public class EnderChestBlock extends AbstractChestBlock<EnderChestBlockEntity> implements SimpleWaterloggedBlock {
|
|
public static final DirectionProperty FACING;
|
|
public static final BooleanProperty WATERLOGGED;
|
|
protected static final VoxelShape SHAPE;
|
|
public static final TranslatableComponent CONTAINER_TITLE;
|
|
|
|
protected EnderChestBlock(final Properties c) {
|
|
super(c, () -> BlockEntityType.ENDER_CHEST);
|
|
this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)EnderChestBlock.FACING, Direction.NORTH)).<Comparable, Boolean>setValue((Property<Comparable>)EnderChestBlock.WATERLOGGED, false));
|
|
}
|
|
|
|
@Override
|
|
public DoubleBlockCombiner.NeighborCombineResult<? extends ChestBlockEntity> combine(final BlockState byg, final Level bjt, final BlockPos fk, final boolean boolean4) {
|
|
return DoubleBlockCombiner.Combiner::acceptNone;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return EnderChestBlock.SHAPE;
|
|
}
|
|
|
|
@Override
|
|
public RenderShape getRenderShape(final BlockState byg) {
|
|
return RenderShape.ENTITYBLOCK_ANIMATED;
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
final FluidState cog3 = bcn.getLevel().getFluidState(bcn.getClickedPos());
|
|
return (((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)EnderChestBlock.FACING, bcn.getHorizontalDirection().getOpposite())).<Comparable, Boolean>setValue((Property<Comparable>)EnderChestBlock.WATERLOGGED, cog3.getType() == Fluids.WATER);
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
|
|
final PlayerEnderChestContainer bbp8 = ayg.getEnderChestInventory();
|
|
final BlockEntity bwi9 = bjt.getBlockEntity(fk);
|
|
if (bbp8 == null || !(bwi9 instanceof EnderChestBlockEntity)) {
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
final BlockPos fk2 = fk.above();
|
|
if (bjt.getBlockState(fk2).isRedstoneConductor(bjt, fk2)) {
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
if (bjt.isClientSide) {
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
final EnderChestBlockEntity bwu11 = (EnderChestBlockEntity)bwi9;
|
|
bbp8.setActiveChest(bwu11);
|
|
ayg.openMenu(new SimpleMenuProvider((integer, ayf, ayg) -> ChestMenu.threeRows(integer, ayf, bbp8), EnderChestBlock.CONTAINER_TITLE));
|
|
ayg.awardStat(Stats.OPEN_ENDERCHEST);
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
|
|
@Override
|
|
public BlockEntity newBlockEntity(final BlockGetter bjd) {
|
|
return new EnderChestBlockEntity();
|
|
}
|
|
|
|
@Override
|
|
public void animateTick(final BlockState byg, final Level bjt, final BlockPos fk, final Random random) {
|
|
for (int integer6 = 0; integer6 < 3; ++integer6) {
|
|
final int integer7 = random.nextInt(2) * 2 - 1;
|
|
final int integer8 = random.nextInt(2) * 2 - 1;
|
|
final double double9 = fk.getX() + 0.5 + 0.25 * integer7;
|
|
final double double10 = fk.getY() + random.nextFloat();
|
|
final double double11 = fk.getZ() + 0.5 + 0.25 * integer8;
|
|
final double double12 = random.nextFloat() * integer7;
|
|
final double double13 = (random.nextFloat() - 0.5) * 0.125;
|
|
final double double14 = random.nextFloat() * integer8;
|
|
bjt.addParticle(ParticleTypes.PORTAL, double9, double10, double11, double12, double13, double14);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public BlockState rotate(final BlockState byg, final Rotation btr) {
|
|
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Direction>setValue((Property<Comparable>)EnderChestBlock.FACING, btr.rotate(byg.<Direction>getValue((Property<Direction>)EnderChestBlock.FACING)));
|
|
}
|
|
|
|
@Override
|
|
public BlockState mirror(final BlockState byg, final Mirror bsr) {
|
|
return byg.rotate(bsr.getRotation(byg.<Direction>getValue((Property<Direction>)EnderChestBlock.FACING)));
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(EnderChestBlock.FACING, EnderChestBlock.WATERLOGGED);
|
|
}
|
|
|
|
@Override
|
|
public FluidState getFluidState(final BlockState byg) {
|
|
if (byg.<Boolean>getValue((Property<Boolean>)EnderChestBlock.WATERLOGGED)) {
|
|
return Fluids.WATER.getSource(false);
|
|
}
|
|
return super.getFluidState(byg);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (byg1.<Boolean>getValue((Property<Boolean>)EnderChestBlock.WATERLOGGED)) {
|
|
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
|
|
return false;
|
|
}
|
|
|
|
static {
|
|
FACING = HorizontalDirectionalBlock.FACING;
|
|
WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
|
SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 14.0, 15.0);
|
|
CONTAINER_TITLE = new TranslatableComponent("container.enderchest", new Object[0]);
|
|
}
|
|
}
|