175 lines
7.2 KiB
Java
175 lines
7.2 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.mojang.serialization.MapCodec
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.world.level.block;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.tags.BlockTags;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.ScheduledTickAccess;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.BonemealableBlock;
|
|
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
|
import net.minecraft.world.level.block.VegetationBlock;
|
|
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.IntegerProperty;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.level.pathfinder.PathComputationType;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class SeaPickleBlock
|
|
extends VegetationBlock
|
|
implements SimpleWaterloggedBlock,
|
|
BonemealableBlock {
|
|
public static final MapCodec<SeaPickleBlock> CODEC = SeaPickleBlock.simpleCodec(SeaPickleBlock::new);
|
|
public static final int MAX_PICKLES = 4;
|
|
public static final IntegerProperty PICKLES = BlockStateProperties.PICKLES;
|
|
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
|
private static final VoxelShape SHAPE_ONE = Block.column(4.0, 0.0, 6.0);
|
|
private static final VoxelShape SHAPE_TWO = Block.column(10.0, 0.0, 6.0);
|
|
private static final VoxelShape SHAPE_THREE = Block.column(12.0, 0.0, 6.0);
|
|
private static final VoxelShape SHAPE_FOUR = Block.column(12.0, 0.0, 7.0);
|
|
|
|
public MapCodec<SeaPickleBlock> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
protected SeaPickleBlock(BlockBehaviour.Properties properties) {
|
|
super(properties);
|
|
this.registerDefaultState((BlockState)((BlockState)((BlockState)this.stateDefinition.any()).setValue(PICKLES, 1)).setValue(WATERLOGGED, true));
|
|
}
|
|
|
|
@Override
|
|
public @Nullable BlockState getStateForPlacement(BlockPlaceContext context) {
|
|
BlockState state = context.getLevel().getBlockState(context.getClickedPos());
|
|
if (state.is(this)) {
|
|
return (BlockState)state.setValue(PICKLES, Math.min(4, state.getValue(PICKLES) + 1));
|
|
}
|
|
FluidState replacedFluidState = context.getLevel().getFluidState(context.getClickedPos());
|
|
boolean isWaterSource = replacedFluidState.getType() == Fluids.WATER;
|
|
return (BlockState)super.getStateForPlacement(context).setValue(WATERLOGGED, isWaterSource);
|
|
}
|
|
|
|
public static boolean isDead(BlockState state) {
|
|
return state.getValue(WATERLOGGED) == false;
|
|
}
|
|
|
|
@Override
|
|
protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) {
|
|
return !state.getCollisionShape(level, pos).getFaceShape(Direction.UP).isEmpty() || state.isFaceSturdy(level, pos, Direction.UP);
|
|
}
|
|
|
|
@Override
|
|
protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
|
|
BlockPos belowPos = pos.below();
|
|
return this.mayPlaceOn(level.getBlockState(belowPos), level, belowPos);
|
|
}
|
|
|
|
@Override
|
|
protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction directionToNeighbour, BlockPos neighbourPos, BlockState neighbourState, RandomSource random) {
|
|
if (!state.canSurvive(level, pos)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
if (state.getValue(WATERLOGGED).booleanValue()) {
|
|
ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
|
|
}
|
|
return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
|
|
}
|
|
|
|
@Override
|
|
protected boolean canBeReplaced(BlockState state, BlockPlaceContext context) {
|
|
if (!context.isSecondaryUseActive() && context.getItemInHand().is(this.asItem()) && state.getValue(PICKLES) < 4) {
|
|
return true;
|
|
}
|
|
return super.canBeReplaced(state, context);
|
|
}
|
|
|
|
@Override
|
|
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
|
return switch (state.getValue(PICKLES)) {
|
|
default -> SHAPE_ONE;
|
|
case 2 -> SHAPE_TWO;
|
|
case 3 -> SHAPE_THREE;
|
|
case 4 -> SHAPE_FOUR;
|
|
};
|
|
}
|
|
|
|
@Override
|
|
protected FluidState getFluidState(BlockState state) {
|
|
if (state.getValue(WATERLOGGED).booleanValue()) {
|
|
return Fluids.WATER.getSource(false);
|
|
}
|
|
return super.getFluidState(state);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(PICKLES, WATERLOGGED);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) {
|
|
return !SeaPickleBlock.isDead(state) && level.getBlockState(pos.below()).is(BlockTags.CORAL_BLOCKS);
|
|
}
|
|
|
|
@Override
|
|
public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state) {
|
|
int span = 5;
|
|
int zSpan = 1;
|
|
int height = 2;
|
|
int count = 0;
|
|
int xStart = pos.getX() - 2;
|
|
int zOffSet = 0;
|
|
for (int x = 0; x < 5; ++x) {
|
|
for (int z = 0; z < zSpan; ++z) {
|
|
int endY = 2 + pos.getY() - 1;
|
|
for (int startY = endY - 2; startY < endY; ++startY) {
|
|
BlockState belowState;
|
|
BlockPos position = new BlockPos(xStart + x, startY, pos.getZ() - zOffSet + z);
|
|
if (position == pos || random.nextInt(6) != 0 || !level.getBlockState(position).is(Blocks.WATER) || !(belowState = level.getBlockState(position.below())).is(BlockTags.CORAL_BLOCKS)) continue;
|
|
level.setBlock(position, (BlockState)Blocks.SEA_PICKLE.defaultBlockState().setValue(PICKLES, random.nextInt(4) + 1), 3);
|
|
}
|
|
}
|
|
if (count < 2) {
|
|
zSpan += 2;
|
|
++zOffSet;
|
|
} else {
|
|
zSpan -= 2;
|
|
--zOffSet;
|
|
}
|
|
++count;
|
|
}
|
|
level.setBlock(pos, (BlockState)state.setValue(PICKLES, 4), 2);
|
|
}
|
|
|
|
@Override
|
|
protected boolean isPathfindable(BlockState state, PathComputationType type) {
|
|
return false;
|
|
}
|
|
}
|
|
|