2020-07-22 06:23:34 +01:00
|
|
|
package net.minecraft.world.level.block;
|
|
|
|
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
|
|
|
import net.minecraft.network.chat.Component;
|
|
|
|
import net.minecraft.world.inventory.ChestMenu;
|
|
|
|
import net.minecraft.world.entity.player.Inventory;
|
|
|
|
import net.minecraft.world.CompoundContainer;
|
|
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
|
|
import net.minecraft.world.level.pathfinder.PathComputationType;
|
|
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import net.minecraft.world.phys.AABB;
|
|
|
|
import net.minecraft.world.entity.animal.Cat;
|
2020-07-22 06:25:47 +01:00
|
|
|
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
|
|
|
import net.minecraft.world.level.block.entity.LidBlockEntity;
|
|
|
|
import java.util.function.BiPredicate;
|
2020-07-22 06:23:34 +01:00
|
|
|
import net.minecraft.stats.Stats;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.stats.Stat;
|
2020-07-22 06:25:47 +01:00
|
|
|
import net.minecraft.world.InteractionResult;
|
2020-07-22 06:23:34 +01:00
|
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
|
|
import net.minecraft.world.InteractionHand;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.Containers;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import net.minecraft.world.level.material.FluidState;
|
|
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.level.BlockGetter;
|
|
|
|
import net.minecraft.world.level.LevelReader;
|
|
|
|
import net.minecraft.world.level.material.Fluids;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
|
|
import net.minecraft.core.Direction;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
2020-07-22 06:25:47 +01:00
|
|
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
|
|
import java.util.function.Supplier;
|
2020-07-22 06:23:34 +01:00
|
|
|
import net.minecraft.world.MenuProvider;
|
|
|
|
import net.minecraft.world.Container;
|
2020-07-22 06:25:47 +01:00
|
|
|
import java.util.Optional;
|
2020-07-22 06:23:34 +01:00
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
|
|
import net.minecraft.world.level.block.state.properties.ChestType;
|
|
|
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
|
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
2020-07-22 06:25:47 +01:00
|
|
|
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
2020-07-22 06:23:34 +01:00
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public class ChestBlock extends AbstractChestBlock<ChestBlockEntity> implements SimpleWaterloggedBlock {
|
2020-07-22 06:23:34 +01:00
|
|
|
public static final DirectionProperty FACING;
|
|
|
|
public static final EnumProperty<ChestType> TYPE;
|
|
|
|
public static final BooleanProperty WATERLOGGED;
|
|
|
|
protected static final VoxelShape NORTH_AABB;
|
|
|
|
protected static final VoxelShape SOUTH_AABB;
|
|
|
|
protected static final VoxelShape WEST_AABB;
|
|
|
|
protected static final VoxelShape EAST_AABB;
|
|
|
|
protected static final VoxelShape AABB;
|
2020-07-22 06:25:47 +01:00
|
|
|
private static final DoubleBlockCombiner.Combiner<ChestBlockEntity, Optional<Container>> CHEST_COMBINER;
|
|
|
|
private static final DoubleBlockCombiner.Combiner<ChestBlockEntity, Optional<MenuProvider>> MENU_PROVIDER_COMBINER;
|
2020-07-22 06:23:34 +01:00
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
protected ChestBlock(final Properties c, final Supplier<BlockEntityType<? extends ChestBlockEntity>> supplier) {
|
|
|
|
super(c, supplier);
|
2020-07-22 06:23:34 +01:00
|
|
|
this.registerDefaultState(((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)ChestBlock.FACING, Direction.NORTH)).setValue(ChestBlock.TYPE, ChestType.SINGLE)).<Comparable, Boolean>setValue((Property<Comparable>)ChestBlock.WATERLOGGED, false));
|
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public static DoubleBlockCombiner.BlockType getBlockType(final BlockState byg) {
|
|
|
|
final ChestType byz2 = byg.<ChestType>getValue(ChestBlock.TYPE);
|
|
|
|
if (byz2 == ChestType.SINGLE) {
|
|
|
|
return DoubleBlockCombiner.BlockType.SINGLE;
|
|
|
|
}
|
|
|
|
if (byz2 == ChestType.RIGHT) {
|
|
|
|
return DoubleBlockCombiner.BlockType.FIRST;
|
|
|
|
}
|
|
|
|
return DoubleBlockCombiner.BlockType.SECOND;
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public RenderShape getRenderShape(final BlockState byg) {
|
2020-07-22 06:23:34 +01:00
|
|
|
return RenderShape.ENTITYBLOCK_ANIMATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
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>)ChestBlock.WATERLOGGED)) {
|
|
|
|
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
if (byg3.getBlock() == this && fp.getAxis().isHorizontal()) {
|
|
|
|
final ChestType byz8 = byg3.<ChestType>getValue(ChestBlock.TYPE);
|
|
|
|
if (byg1.<ChestType>getValue(ChestBlock.TYPE) == ChestType.SINGLE && byz8 != ChestType.SINGLE && byg1.<Comparable>getValue((Property<Comparable>)ChestBlock.FACING) == byg3.<Comparable>getValue((Property<Comparable>)ChestBlock.FACING) && getConnectedDirection(byg3) == fp.getOpposite()) {
|
|
|
|
return ((AbstractStateHolder<O, BlockState>)byg1).<ChestType, ChestType>setValue(ChestBlock.TYPE, byz8.getOpposite());
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
else if (getConnectedDirection(byg1) == fp) {
|
|
|
|
return ((AbstractStateHolder<O, BlockState>)byg1).<ChestType, ChestType>setValue(ChestBlock.TYPE, ChestType.SINGLE);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
|
|
if (byg.<ChestType>getValue(ChestBlock.TYPE) == ChestType.SINGLE) {
|
2020-07-22 06:23:34 +01:00
|
|
|
return ChestBlock.AABB;
|
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
switch (getConnectedDirection(byg)) {
|
2020-07-22 06:23:34 +01:00
|
|
|
default: {
|
|
|
|
return ChestBlock.NORTH_AABB;
|
|
|
|
}
|
|
|
|
case SOUTH: {
|
|
|
|
return ChestBlock.SOUTH_AABB;
|
|
|
|
}
|
|
|
|
case WEST: {
|
|
|
|
return ChestBlock.WEST_AABB;
|
|
|
|
}
|
|
|
|
case EAST: {
|
|
|
|
return ChestBlock.EAST_AABB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public static Direction getConnectedDirection(final BlockState byg) {
|
|
|
|
final Direction fp2 = byg.<Direction>getValue((Property<Direction>)ChestBlock.FACING);
|
|
|
|
return (byg.<ChestType>getValue(ChestBlock.TYPE) == ChestType.LEFT) ? fp2.getClockWise() : fp2.getCounterClockWise();
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
|
|
ChestType byz3 = ChestType.SINGLE;
|
|
|
|
Direction fp4 = bcn.getHorizontalDirection().getOpposite();
|
|
|
|
final FluidState cog5 = bcn.getLevel().getFluidState(bcn.getClickedPos());
|
|
|
|
final boolean boolean6 = bcn.isSecondaryUseActive();
|
|
|
|
final Direction fp5 = bcn.getClickedFace();
|
|
|
|
if (fp5.getAxis().isHorizontal() && boolean6) {
|
|
|
|
final Direction fp6 = this.candidatePartnerFacing(bcn, fp5.getOpposite());
|
|
|
|
if (fp6 != null && fp6.getAxis() != fp5.getAxis()) {
|
|
|
|
fp4 = fp6;
|
|
|
|
byz3 = ((fp4.getCounterClockWise() == fp5.getOpposite()) ? ChestType.RIGHT : ChestType.LEFT);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
if (byz3 == ChestType.SINGLE && !boolean6) {
|
|
|
|
if (fp4 == this.candidatePartnerFacing(bcn, fp4.getClockWise())) {
|
|
|
|
byz3 = ChestType.LEFT;
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
else if (fp4 == this.candidatePartnerFacing(bcn, fp4.getCounterClockWise())) {
|
|
|
|
byz3 = ChestType.RIGHT;
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
return ((((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue((Property<Comparable>)ChestBlock.FACING, fp4)).setValue(ChestBlock.TYPE, byz3)).<Comparable, Boolean>setValue((Property<Comparable>)ChestBlock.WATERLOGGED, cog5.getType() == Fluids.WATER);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public FluidState getFluidState(final BlockState byg) {
|
|
|
|
if (byg.<Boolean>getValue((Property<Boolean>)ChestBlock.WATERLOGGED)) {
|
2020-07-22 06:23:34 +01:00
|
|
|
return Fluids.WATER.getSource(false);
|
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
return super.getFluidState(byg);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2020-07-22 06:25:47 +01:00
|
|
|
private Direction candidatePartnerFacing(final BlockPlaceContext bcn, final Direction fp) {
|
|
|
|
final BlockState byg4 = bcn.getLevel().getBlockState(bcn.getClickedPos().relative(fp));
|
|
|
|
return (byg4.getBlock() == this && byg4.<ChestType>getValue(ChestBlock.TYPE) == ChestType.SINGLE) ? byg4.<Direction>getValue((Property<Direction>)ChestBlock.FACING) : null;
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
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 ChestBlockEntity) {
|
|
|
|
((ChestBlockEntity)bwi7).setCustomName(bek.getHoverName());
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public void onRemove(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
|
|
|
|
if (byg1.getBlock() == byg4.getBlock()) {
|
2020-07-22 06:23:34 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
final BlockEntity bwi7 = bjt.getBlockEntity(fk);
|
|
|
|
if (bwi7 instanceof Container) {
|
|
|
|
Containers.dropContents(bjt, fk, (Container)bwi7);
|
|
|
|
bjt.updateNeighbourForOutputSignal(fk, this);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
super.onRemove(byg1, bjt, fk, byg4, boolean5);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
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;
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
final MenuProvider ajl8 = this.getMenuProvider(byg, bjt, fk);
|
|
|
|
if (ajl8 != null) {
|
|
|
|
ayg.openMenu(ajl8);
|
|
|
|
ayg.awardStat(this.getOpenChestStat());
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
return InteractionResult.SUCCESS;
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected Stat<ResourceLocation> getOpenChestStat() {
|
|
|
|
return Stats.CUSTOM.get(Stats.OPEN_CHEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2020-07-22 06:25:47 +01:00
|
|
|
public static Container getContainer(final ChestBlock bpt, final BlockState byg, final Level bjt, final BlockPos fk, final boolean boolean5) {
|
|
|
|
return bpt.combine(byg, bjt, fk, boolean5).<Optional<Container>>apply(ChestBlock.CHEST_COMBINER).orElse(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DoubleBlockCombiner.NeighborCombineResult<? extends ChestBlockEntity> combine(final BlockState byg, final Level bjt, final BlockPos fk, final boolean boolean4) {
|
|
|
|
BiPredicate<LevelAccessor, BlockPos> biPredicate6;
|
|
|
|
if (boolean4) {
|
|
|
|
biPredicate6 = ((bju, fk) -> false);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
else {
|
|
|
|
biPredicate6 = ChestBlock::isChestBlockedAt;
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
return DoubleBlockCombiner.combineWithNeigbour(this.blockEntityType.get(), ChestBlock::getBlockType, ChestBlock::getConnectedDirection, ChestBlock.FACING, byg, bjt, fk, biPredicate6);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
2020-07-22 06:25:47 +01:00
|
|
|
@Override
|
|
|
|
public MenuProvider getMenuProvider(final BlockState byg, final Level bjt, final BlockPos fk) {
|
|
|
|
return this.combine(byg, bjt, fk, false).<Optional<MenuProvider>>apply(ChestBlock.MENU_PROVIDER_COMBINER).orElse(null);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public static DoubleBlockCombiner.Combiner<ChestBlockEntity, Float2FloatFunction> opennessCombiner(final LidBlockEntity bxb) {
|
|
|
|
return new DoubleBlockCombiner.Combiner<ChestBlockEntity, Float2FloatFunction>() {
|
|
|
|
@Override
|
|
|
|
public Float2FloatFunction acceptDouble(final ChestBlockEntity bwm1, final ChestBlockEntity bwm2) {
|
|
|
|
return float3 -> Math.max(bwm1.getOpenNess(float3), bwm2.getOpenNess(float3));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Float2FloatFunction acceptSingle(final ChestBlockEntity bwm) {
|
|
|
|
return bwm::getOpenNess;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Float2FloatFunction acceptNone() {
|
|
|
|
return bxb::getOpenNess;
|
|
|
|
}
|
|
|
|
};
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public BlockEntity newBlockEntity(final BlockGetter bjd) {
|
2020-07-22 06:23:34 +01:00
|
|
|
return new ChestBlockEntity();
|
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public static boolean isChestBlockedAt(final LevelAccessor bju, final BlockPos fk) {
|
|
|
|
return isBlockedChestByBlock(bju, fk) || isCatSittingOnChest(bju, fk);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
private static boolean isBlockedChestByBlock(final BlockGetter bjd, final BlockPos fk) {
|
|
|
|
final BlockPos fk2 = fk.above();
|
|
|
|
return bjd.getBlockState(fk2).isRedstoneConductor(bjd, fk2);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
private static boolean isCatSittingOnChest(final LevelAccessor bju, final BlockPos fk) {
|
|
|
|
final List<Cat> list3 = bju.<Cat>getEntitiesOfClass(Cat.class, new AABB(fk.getX(), fk.getY() + 1, fk.getZ(), fk.getX() + 1, fk.getY() + 2, fk.getZ() + 1));
|
2020-07-22 06:23:34 +01:00
|
|
|
if (!list3.isEmpty()) {
|
2020-07-22 06:25:47 +01:00
|
|
|
for (final Cat atb5 : list3) {
|
|
|
|
if (atb5.isSitting()) {
|
2020-07-22 06:23:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public boolean hasAnalogOutputSignal(final BlockState byg) {
|
2020-07-22 06:23:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public int getAnalogOutputSignal(final BlockState byg, final Level bjt, final BlockPos fk) {
|
|
|
|
return AbstractContainerMenu.getRedstoneSignalFromContainer(getContainer(this, byg, bjt, fk, false));
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public BlockState rotate(final BlockState byg, final Rotation btr) {
|
|
|
|
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Direction>setValue((Property<Comparable>)ChestBlock.FACING, btr.rotate(byg.<Direction>getValue((Property<Direction>)ChestBlock.FACING)));
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public BlockState mirror(final BlockState byg, final Mirror bsr) {
|
|
|
|
return byg.rotate(bsr.getRotation(byg.<Direction>getValue((Property<Direction>)ChestBlock.FACING)));
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
|
|
a.add(ChestBlock.FACING, ChestBlock.TYPE, ChestBlock.WATERLOGGED);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public boolean isPathfindable(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final PathComputationType cqo) {
|
2020-07-22 06:23:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
|
|
|
FACING = HorizontalDirectionalBlock.FACING;
|
|
|
|
TYPE = BlockStateProperties.CHEST_TYPE;
|
|
|
|
WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
|
|
|
NORTH_AABB = Block.box(1.0, 0.0, 0.0, 15.0, 14.0, 15.0);
|
|
|
|
SOUTH_AABB = Block.box(1.0, 0.0, 1.0, 15.0, 14.0, 16.0);
|
|
|
|
WEST_AABB = Block.box(0.0, 0.0, 1.0, 15.0, 14.0, 15.0);
|
|
|
|
EAST_AABB = Block.box(1.0, 0.0, 1.0, 16.0, 14.0, 15.0);
|
|
|
|
AABB = Block.box(1.0, 0.0, 1.0, 15.0, 14.0, 15.0);
|
2020-07-22 06:25:47 +01:00
|
|
|
CHEST_COMBINER = new DoubleBlockCombiner.Combiner<ChestBlockEntity, Optional<Container>>() {
|
2020-07-22 06:23:34 +01:00
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public Optional<Container> acceptDouble(final ChestBlockEntity bwm1, final ChestBlockEntity bwm2) {
|
|
|
|
return Optional.of(new CompoundContainer(bwm1, bwm2));
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public Optional<Container> acceptSingle(final ChestBlockEntity bwm) {
|
|
|
|
return Optional.of(bwm);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Optional<Container> acceptNone() {
|
|
|
|
return Optional.<Container>empty();
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
};
|
2020-07-22 06:25:47 +01:00
|
|
|
MENU_PROVIDER_COMBINER = new DoubleBlockCombiner.Combiner<ChestBlockEntity, Optional<MenuProvider>>() {
|
2020-07-22 06:23:34 +01:00
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public Optional<MenuProvider> acceptDouble(final ChestBlockEntity bwm1, final ChestBlockEntity bwm2) {
|
|
|
|
final Container ajb4 = new CompoundContainer(bwm1, bwm2);
|
|
|
|
return Optional.of(new MenuProvider() {
|
2020-07-22 06:23:34 +01:00
|
|
|
@Nullable
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public AbstractContainerMenu createMenu(final int integer, final Inventory ayf, final Player ayg) {
|
|
|
|
if (bwm1.canOpen(ayg) && bwm2.canOpen(ayg)) {
|
|
|
|
bwm1.unpackLootTable(ayf.player);
|
|
|
|
bwm2.unpackLootTable(ayf.player);
|
|
|
|
return ChestMenu.sixRows(integer, ayf, ajb4);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Component getDisplayName() {
|
2020-07-22 06:25:47 +01:00
|
|
|
if (bwm1.hasCustomName()) {
|
|
|
|
return bwm1.getDisplayName();
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
if (bwm2.hasCustomName()) {
|
|
|
|
return bwm2.getDisplayName();
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
return new TranslatableComponent("container.chestDouble", new Object[0]);
|
|
|
|
}
|
2020-07-22 06:25:47 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Optional<MenuProvider> acceptSingle(final ChestBlockEntity bwm) {
|
|
|
|
return Optional.of(bwm);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-22 06:25:47 +01:00
|
|
|
public Optional<MenuProvider> acceptNone() {
|
|
|
|
return Optional.<MenuProvider>empty();
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|