232 lines
12 KiB
Java
232 lines
12 KiB
Java
package com.dairymoose.modernlife.blocks;
|
|
|
|
import com.dairymoose.modernlife.tileentities.RefrigeratorBlockEntity;
|
|
import com.dairymoose.modernlife.util.ModernLifeUtil;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.chat.TextComponent;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.world.Containers;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.MenuProvider;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.player.Inventory;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
import net.minecraft.world.inventory.ChestMenu;
|
|
import net.minecraft.world.inventory.MenuType;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.EntityBlock;
|
|
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
|
import net.minecraft.world.level.block.Mirror;
|
|
import net.minecraft.world.level.block.Rotation;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
|
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.material.PushReaction;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/RefrigeratorBlock.class */
|
|
public class RefrigeratorBlock extends Block implements EntityBlock {
|
|
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
|
public static final EnumProperty<DoubleBlockHalf> HALF = BlockStateProperties.DOUBLE_BLOCK_HALF;
|
|
protected static final VoxelShape SOUTH_AABB = Block.box(0.01d, 0.0d, 0.01d, 15.99d, 16.0d, 15.99d);
|
|
protected static final VoxelShape NORTH_AABB = Block.box(0.01d, 0.0d, 0.01d, 15.99d, 16.0d, 15.99d);
|
|
protected static final VoxelShape WEST_AABB = Block.box(0.01d, 0.0d, 0.01d, 15.99d, 16.0d, 15.99d);
|
|
protected static final VoxelShape EAST_AABB = Block.box(0.01d, 0.0d, 0.01d, 15.99d, 16.0d, 15.99d);
|
|
|
|
public RefrigeratorBlock(Properties p_i48413_1_) {
|
|
super(p_i48413_1_);
|
|
registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any().setValue(FACING, Direction.NORTH)).setValue(HALF, DoubleBlockHalf.LOWER));
|
|
}
|
|
|
|
public VoxelShape getShape(BlockState p_220053_1_, BlockGetter p_220053_2_, BlockPos p_220053_3_, CollisionContext p_220053_4_) {
|
|
Direction lvt_5_1_ = p_220053_1_.getValue(FACING);
|
|
switch (lvt_5_1_.ordinal()) {
|
|
case 1:
|
|
default:
|
|
return EAST_AABB;
|
|
case 2:
|
|
return SOUTH_AABB;
|
|
case 3:
|
|
return WEST_AABB;
|
|
case 4:
|
|
return NORTH_AABB;
|
|
}
|
|
}
|
|
|
|
public void onRemove(BlockState p_196243_1_, Level p_196243_2_, BlockPos p_196243_3_, BlockState p_196243_4_, boolean p_196243_5_) {
|
|
if (!p_196243_1_.is(p_196243_4_.getBlock())) {
|
|
BlockEntity lvt_6_1_ = p_196243_2_.getBlockEntity(p_196243_3_);
|
|
if (lvt_6_1_ instanceof RefrigeratorBlockEntity) {
|
|
Containers.dropContents(p_196243_2_, p_196243_3_, (RefrigeratorBlockEntity) lvt_6_1_);
|
|
p_196243_2_.updateNeighbourForOutputSignal(p_196243_3_, this);
|
|
}
|
|
super.onRemove(p_196243_1_, p_196243_2_, p_196243_3_, p_196243_4_, p_196243_5_);
|
|
}
|
|
}
|
|
|
|
/* renamed from: com.dairymoose.modernlife.blocks.RefrigeratorBlock$1 */
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/RefrigeratorBlock$1.class */
|
|
public class C00531 implements MenuProvider {
|
|
final /* synthetic */ Level val$p_220052_2_;
|
|
final /* synthetic */ BlockPos val$p_220052_3_;
|
|
|
|
C00531(Level level, BlockPos blockPos) {
|
|
p_220052_2_ = level;
|
|
p_220052_3_ = blockPos;
|
|
}
|
|
|
|
public AbstractContainerMenu createMenu(int paramInt, Inventory paramInventory, Player paramPlayer) {
|
|
BlockEntity tileEntity = p_220052_2_.getBlockEntity(p_220052_3_);
|
|
if (tileEntity instanceof RefrigeratorBlockEntity) {
|
|
RefrigeratorBlockEntity refrigeratorBlockEntity = (RefrigeratorBlockEntity) tileEntity;
|
|
return new ChestMenu(MenuType.GENERIC_9x4, paramInt, paramInventory, refrigeratorBlockEntity, 4);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Component getDisplayName() {
|
|
return new TextComponent("Refrigerator");
|
|
}
|
|
}
|
|
|
|
public MenuProvider getMenuProvider(BlockState p_220052_1_, Level p_220052_2_, BlockPos p_220052_3_) {
|
|
return new MenuProvider() { // from class: com.dairymoose.modernlife.blocks.RefrigeratorBlock.1
|
|
final /* synthetic */ Level val$p_220052_2_;
|
|
final /* synthetic */ BlockPos val$p_220052_3_;
|
|
|
|
C00531(Level p_220052_2_2, BlockPos p_220052_3_2) {
|
|
p_220052_2_ = p_220052_2_2;
|
|
p_220052_3_ = p_220052_3_2;
|
|
}
|
|
|
|
public AbstractContainerMenu createMenu(int paramInt, Inventory paramInventory, Player paramPlayer) {
|
|
BlockEntity tileEntity = p_220052_2_.getBlockEntity(p_220052_3_);
|
|
if (tileEntity instanceof RefrigeratorBlockEntity) {
|
|
RefrigeratorBlockEntity refrigeratorBlockEntity = (RefrigeratorBlockEntity) tileEntity;
|
|
return new ChestMenu(MenuType.GENERIC_9x4, paramInt, paramInventory, refrigeratorBlockEntity, 4);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Component getDisplayName() {
|
|
return new TextComponent("Refrigerator");
|
|
}
|
|
};
|
|
}
|
|
|
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
|
|
return ModernLifeUtil.createTickerHelper(type, RefrigeratorBlockEntity.REFRIGERATOR, RefrigeratorBlockEntity::tick);
|
|
}
|
|
|
|
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
|
if (state.getValue(HALF) == DoubleBlockHalf.UPPER) {
|
|
RefrigeratorBlockEntity toReturn = (RefrigeratorBlockEntity) RefrigeratorBlockEntity.REFRIGERATOR.create(pos, state);
|
|
return toReturn;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public InteractionResult use(BlockState p_225533_1_, Level p_225533_2_, BlockPos p_225533_3_, Player p_225533_4_, InteractionHand p_225533_5_, BlockHitResult p_225533_6_) {
|
|
MenuProvider lvt_7_1_ = getMenuProvider(p_225533_1_, p_225533_2_, p_225533_3_);
|
|
if (lvt_7_1_ != null) {
|
|
p_225533_4_.openMenu(lvt_7_1_);
|
|
}
|
|
return InteractionResult.CONSUME;
|
|
}
|
|
|
|
public BlockState updateShape(BlockState p_196271_1_, Direction p_196271_2_, BlockState p_196271_3_, LevelAccessor p_196271_4_, BlockPos p_196271_5_, BlockPos p_196271_6_) {
|
|
Comparable comparable = (DoubleBlockHalf) p_196271_1_.getValue(HALF);
|
|
if (p_196271_2_.getAxis() == Direction.Axis.Y) {
|
|
if ((comparable == DoubleBlockHalf.LOWER) == (p_196271_2_ == Direction.UP)) {
|
|
return (!p_196271_3_.is(this) || p_196271_3_.getValue(HALF) == comparable) ? Blocks.AIR.defaultBlockState() : (BlockState) p_196271_1_.setValue(FACING, p_196271_3_.getValue(FACING));
|
|
}
|
|
}
|
|
return (comparable == DoubleBlockHalf.LOWER && p_196271_2_ == Direction.DOWN && !p_196271_1_.canSurvive(p_196271_4_, p_196271_5_)) ? Blocks.AIR.defaultBlockState() : super.updateShape(p_196271_1_, p_196271_2_, p_196271_3_, p_196271_4_, p_196271_5_, p_196271_6_);
|
|
}
|
|
|
|
protected static void preventCreativeDropFromBottomPart(Level p_241471_0_, BlockPos p_241471_1_, BlockState p_241471_2_, Player p_241471_3_) {
|
|
DoubleBlockHalf doubleblockhalf = p_241471_2_.getValue(HALF);
|
|
if (doubleblockhalf == DoubleBlockHalf.UPPER) {
|
|
BlockPos blockpos = p_241471_1_.below();
|
|
BlockState blockstate = p_241471_0_.getBlockState(blockpos);
|
|
if (blockstate.getBlock() == p_241471_2_.getBlock() && blockstate.getValue(HALF) == DoubleBlockHalf.LOWER) {
|
|
p_241471_0_.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 35);
|
|
p_241471_0_.levelEvent(p_241471_3_, 2001, blockpos, Block.getId(blockstate));
|
|
}
|
|
}
|
|
}
|
|
|
|
public BlockState rotate(BlockState state, Rotation rotation) {
|
|
return (BlockState) state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
|
}
|
|
|
|
public BlockState mirror(BlockState state, Mirror mirror) {
|
|
return mirror == Mirror.NONE ? state : state.rotate(mirror.getRotation(state.getValue(FACING)));
|
|
}
|
|
|
|
public void playerWillDestroy(Level p_176208_1_, BlockPos p_176208_2_, BlockState p_176208_3_, Player p_176208_4_) {
|
|
if (!p_176208_1_.isClientSide && p_176208_4_.isCreative()) {
|
|
preventCreativeDropFromBottomPart(p_176208_1_, p_176208_2_, p_176208_3_, p_176208_4_);
|
|
}
|
|
super.playerWillDestroy(p_176208_1_, p_176208_2_, p_176208_3_, p_176208_4_);
|
|
}
|
|
|
|
@Nullable
|
|
public BlockState getStateForPlacement(BlockPlaceContext p_196258_1_) {
|
|
BlockPos lvt_2_1_ = p_196258_1_.getClickedPos();
|
|
if (lvt_2_1_.getY() < p_196258_1_.getLevel().getMaxBuildHeight() && p_196258_1_.getLevel().getBlockState(lvt_2_1_.above()).canBeReplaced(p_196258_1_)) {
|
|
Level lvt_3_1_ = p_196258_1_.getLevel();
|
|
boolean z = lvt_3_1_.hasNeighborSignal(lvt_2_1_) || lvt_3_1_.hasNeighborSignal(lvt_2_1_.above());
|
|
return (BlockState) ((BlockState) defaultBlockState().setValue(FACING, p_196258_1_.getHorizontalDirection())).setValue(HALF, DoubleBlockHalf.LOWER);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void setPlacedBy(Level p_180633_1_, BlockPos p_180633_2_, BlockState p_180633_3_, LivingEntity p_180633_4_, ItemStack p_180633_5_) {
|
|
p_180633_1_.setBlock(p_180633_2_.above(), (BlockState) p_180633_3_.setValue(HALF, DoubleBlockHalf.UPPER), 3);
|
|
}
|
|
|
|
public boolean canSurvive(BlockState p_196260_1_, LevelReader p_196260_2_, BlockPos p_196260_3_) {
|
|
BlockPos lvt_4_1_ = p_196260_3_.below();
|
|
BlockState lvt_5_1_ = p_196260_2_.getBlockState(lvt_4_1_);
|
|
return p_196260_1_.getValue(HALF) == DoubleBlockHalf.LOWER ? lvt_5_1_.isFaceSturdy(p_196260_2_, lvt_4_1_, Direction.UP) : lvt_5_1_.is(this);
|
|
}
|
|
|
|
public PushReaction getPistonPushReaction(BlockState p_149656_1_) {
|
|
return PushReaction.DESTROY;
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
public long getSeed(BlockState p_209900_1_, BlockPos p_209900_2_) {
|
|
return Mth.getSeed(p_209900_2_.getX(), p_209900_2_.below(p_209900_1_.getValue(HALF) == DoubleBlockHalf.LOWER ? 0 : 1).getY(), p_209900_2_.getZ());
|
|
}
|
|
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_206840_1_) {
|
|
p_206840_1_.add(new Property[]{HALF, FACING});
|
|
}
|
|
}
|