ModernLifePatch/src-source/main/java/com/dairymoose/modernlife/blocks/PicnicTableBlock.java
2024-10-26 09:40:21 +08:00

176 lines
8.4 KiB
Java

package com.dairymoose.modernlife.blocks;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
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.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
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.DirectionProperty;
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/PicnicTableBlock.class */
public class PicnicTableBlock extends Block {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final EnumProperty<BenchHalf> HALF = EnumProperty.create("half", BenchHalf.class);
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);
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/PicnicTableBlock$BenchHalf.class */
public enum BenchHalf implements StringRepresentable {
back,
front;
public String getSerializedName() {
return name().toLowerCase();
}
}
public PicnicTableBlock(Properties p_i48413_1_) {
super(p_i48413_1_);
registerDefaultState((BlockState) ((BlockState) this.stateDefinition.any().setValue(FACING, Direction.NORTH)).setValue(HALF, BenchHalf.back));
}
public int getFlammability(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
if (this.material.isFlammable()) {
return 20;
}
return 0;
}
public int getFireSpreadSpeed(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
if (this.material.isFlammable()) {
return 5;
}
return 0;
}
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 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_) {
Direction checkDir;
BenchHalf lvt_7_1_ = (BenchHalf) p_196271_1_.getValue(HALF);
if (p_196271_1_.getValue(FACING) == Direction.EAST) {
checkDir = Direction.WEST;
} else if (p_196271_1_.getValue(FACING) == Direction.WEST) {
checkDir = Direction.EAST;
} else if (p_196271_1_.getValue(FACING) == Direction.NORTH) {
checkDir = Direction.SOUTH;
} else {
checkDir = Direction.NORTH;
}
if (lvt_7_1_ == BenchHalf.back && p_196271_5_.relative(checkDir).equals(p_196271_6_) && !p_196271_3_.is(this)) {
return Blocks.AIR.defaultBlockState();
}
if (lvt_7_1_ == BenchHalf.front && p_196271_5_.relative(checkDir.getOpposite()).equals(p_196271_6_) && !p_196271_3_.is(this)) {
return Blocks.AIR.defaultBlockState();
}
return 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_) {
BenchHalf BenchHalf2 = (BenchHalf) p_241471_2_.getValue(HALF);
if (BenchHalf2 == BenchHalf.front) {
BlockPos blockpos = p_241471_1_.below();
BlockState blockstate = p_241471_0_.getBlockState(blockpos);
if (blockstate.getBlock() == p_241471_2_.getBlock() && blockstate.getValue(HALF) == BenchHalf.back) {
p_241471_0_.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 35);
p_241471_0_.levelEvent(p_241471_3_, 2001, blockpos, Block.getId(blockstate));
}
}
}
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_);
}
public BlockState rotate(BlockState p_52790_, Rotation p_52791_) {
return (BlockState) p_52790_.setValue(FACING, p_52791_.rotate(p_52790_.getValue(FACING)));
}
public BlockState mirror(BlockState p_52787_, Mirror p_52788_) {
return p_52788_ == Mirror.NONE ? p_52787_ : p_52787_.rotate(p_52788_.getRotation(p_52787_.getValue(FACING)));
}
@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_.relative(p_196258_1_.getHorizontalDirection())).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().getOpposite())).setValue(HALF, BenchHalf.back);
}
return null;
}
@Deprecated
public InteractionResult use(BlockState p_225533_1_, Level p_225533_2_, BlockPos p_225533_3_, Player player, InteractionHand p_225533_5_, BlockHitResult p_225533_6_) {
return InteractionResult.CONSUME;
}
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_.relative(p_180633_4_.getDirection()), (BlockState) p_180633_3_.setValue(HALF, BenchHalf.front), 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) == BenchHalf.back ? 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) == BenchHalf.back ? 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});
}
}