252 lines
13 KiB
Java
252 lines
13 KiB
Java
package com.dairymoose.modernlife.blocks;
|
|
|
|
import com.dairymoose.entity.DummyEntity;
|
|
import com.dairymoose.modernlife.core.CustomBlocks;
|
|
import com.dairymoose.modernlife.util.ModernLifeUtil;
|
|
import java.util.stream.Stream;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.sounds.SoundEvents;
|
|
import net.minecraft.sounds.SoundSource;
|
|
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.Items;
|
|
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.SimpleWaterloggedBlock;
|
|
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.BooleanProperty;
|
|
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.FluidState;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.level.material.PushReaction;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.phys.shapes.BooleanOp;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
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/BathtubBlock.class */
|
|
public class BathtubBlock extends Block implements SimpleWaterloggedBlock {
|
|
protected static final VoxelShape SHAPE_EAST = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(0.0d, 0.0d, 0.0d, 16.0d, 1.0d, 16.0d), Block.box(0.0d, 1.0d, 0.0d, 3.0d, 10.0d, 16.0d), Block.box(3.0d, 1.0d, 0.0d, 16.0d, 10.0d, 2.0d), Block.box(3.0d, 1.0d, 14.0d, 16.0d, 10.0d, 16.0d)}).reduce((v1, v2) -> {
|
|
return Shapes.join((VoxelShape) v1, (VoxelShape) v2, BooleanOp.OR);
|
|
}).get();
|
|
protected static final VoxelShape SHAPE_SOUTH = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_EAST);
|
|
protected static final VoxelShape SHAPE_WEST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH);
|
|
protected static final VoxelShape SHAPE_NORTH = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST);
|
|
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
|
public static final EnumProperty<TubHalf> HALF = EnumProperty.create("half", TubHalf.class);
|
|
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
|
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/BathtubBlock$TubHalf.class */
|
|
public enum TubHalf implements StringRepresentable {
|
|
back,
|
|
front;
|
|
|
|
public String getSerializedName() {
|
|
return name().toLowerCase();
|
|
}
|
|
}
|
|
|
|
public BathtubBlock(Properties p_i48413_1_) {
|
|
super(p_i48413_1_);
|
|
registerDefaultState((BlockState) ((BlockState) ((BlockState) this.stateDefinition.any().setValue(FACING, Direction.NORTH)).setValue(HALF, TubHalf.back)).setValue(WATERLOGGED, Boolean.FALSE));
|
|
}
|
|
|
|
public FluidState getFluidState(BlockState p_204507_1_) {
|
|
if (((Boolean) p_204507_1_.getValue(WATERLOGGED)).booleanValue()) {
|
|
return Fluids.FLOWING_WATER.getFlowing(3, false);
|
|
}
|
|
return super.getFluidState(p_204507_1_);
|
|
}
|
|
|
|
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)));
|
|
}
|
|
|
|
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);
|
|
if (p_220053_1_.getValue(HALF) == TubHalf.front) {
|
|
switch (C00091.$SwitchMap$net$minecraft$core$Direction[lvt_5_1_.ordinal()]) {
|
|
case 1:
|
|
default:
|
|
return SHAPE_EAST;
|
|
case 2:
|
|
return SHAPE_SOUTH;
|
|
case 3:
|
|
return SHAPE_WEST;
|
|
case 4:
|
|
return SHAPE_NORTH;
|
|
}
|
|
}
|
|
switch (C00091.$SwitchMap$net$minecraft$core$Direction[lvt_5_1_.ordinal()]) {
|
|
case 1:
|
|
default:
|
|
return SHAPE_WEST;
|
|
case 2:
|
|
return SHAPE_NORTH;
|
|
case 3:
|
|
return SHAPE_EAST;
|
|
case 4:
|
|
return SHAPE_SOUTH;
|
|
}
|
|
}
|
|
|
|
/* renamed from: com.dairymoose.modernlife.blocks.BathtubBlock$1 */
|
|
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/BathtubBlock$1.class */
|
|
static /* synthetic */ class C00091 {
|
|
static final /* synthetic */ int[] $SwitchMap$net$minecraft$core$Direction = new int[Direction.values().length];
|
|
|
|
static {
|
|
try {
|
|
$SwitchMap$net$minecraft$core$Direction[Direction.EAST.ordinal()] = 1;
|
|
} catch (NoSuchFieldError e) {
|
|
}
|
|
try {
|
|
$SwitchMap$net$minecraft$core$Direction[Direction.SOUTH.ordinal()] = 2;
|
|
} catch (NoSuchFieldError e2) {
|
|
}
|
|
try {
|
|
$SwitchMap$net$minecraft$core$Direction[Direction.WEST.ordinal()] = 3;
|
|
} catch (NoSuchFieldError e3) {
|
|
}
|
|
try {
|
|
$SwitchMap$net$minecraft$core$Direction[Direction.NORTH.ordinal()] = 4;
|
|
} catch (NoSuchFieldError e4) {
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
TubHalf lvt_7_1_ = (TubHalf) 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_ == TubHalf.back && p_196271_5_.relative(checkDir).equals(p_196271_6_) && !p_196271_3_.is(this)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
if (lvt_7_1_ == TubHalf.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_) {
|
|
TubHalf BenchHalf = (TubHalf) p_241471_2_.getValue(HALF);
|
|
if (BenchHalf == TubHalf.front) {
|
|
BlockPos blockpos = p_241471_1_.below();
|
|
BlockState blockstate = p_241471_0_.getBlockState(blockpos);
|
|
if (blockstate.getBlock() == p_241471_2_.getBlock() && blockstate.getValue(HALF) == TubHalf.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_);
|
|
}
|
|
|
|
@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, TubHalf.back);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public ItemStack pickupBlock(LevelAccessor p_154560_, BlockPos p_154561_, BlockState p_154562_) {
|
|
if (((Boolean) p_154562_.getValue(BlockStateProperties.WATERLOGGED)).booleanValue()) {
|
|
p_154560_.setBlock(p_154561_, (BlockState) p_154562_.setValue(BlockStateProperties.WATERLOGGED, false), 3);
|
|
return new ItemStack(Items.WATER_BUCKET);
|
|
}
|
|
return ItemStack.EMPTY;
|
|
}
|
|
|
|
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_) {
|
|
if (player.getVehicle() != null && p_225533_1_.getValue(HALF) == TubHalf.front) {
|
|
if (((Boolean) p_225533_1_.getValue(WATERLOGGED)).booleanValue()) {
|
|
pickupBlock(p_225533_2_, p_225533_3_, p_225533_1_);
|
|
BlockPos otherPos = p_225533_3_.relative(p_225533_1_.getValue(FACING));
|
|
BlockState otherState = p_225533_2_.getBlockState(otherPos);
|
|
if (otherState.is(CustomBlocks.BLOCK_BATHTUB.get())) {
|
|
pickupBlock(p_225533_2_, otherPos, otherState);
|
|
}
|
|
} else {
|
|
placeLiquid(p_225533_2_, p_225533_3_, p_225533_1_, Fluids.WATER.getSource().defaultFluidState());
|
|
BlockPos otherPos2 = p_225533_3_.relative(p_225533_1_.getValue(FACING));
|
|
BlockState otherState2 = p_225533_2_.getBlockState(otherPos2);
|
|
if (otherState2.is(CustomBlocks.BLOCK_BATHTUB.get())) {
|
|
placeLiquid(p_225533_2_, otherPos2, otherState2, Fluids.WATER.getSource().defaultFluidState());
|
|
}
|
|
p_225533_2_.playSound((Player) null, p_225533_3_, SoundEvents.GENERIC_SPLASH, SoundSource.BLOCKS, 1.0f, 1.0f);
|
|
}
|
|
} else if (!p_225533_2_.isClientSide) {
|
|
DummyEntity dummy = DummyEntity.getEntity(-0.1f, p_225533_2_, p_225533_3_, true);
|
|
dummy.ride(player);
|
|
}
|
|
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, TubHalf.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) == TubHalf.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) == TubHalf.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, WATERLOGGED});
|
|
}
|
|
}
|