73 lines
2.5 KiB
Java
73 lines
2.5 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.LevelReader;
|
|
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.IntegerProperty;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
public class NetherWartBlock extends BushBlock {
|
|
public static final MapCodec<NetherWartBlock> CODEC = simpleCodec(NetherWartBlock::new);
|
|
public static final int MAX_AGE = 3;
|
|
public static final IntegerProperty AGE = BlockStateProperties.AGE_3;
|
|
private static final VoxelShape[] SHAPE_BY_AGE = new VoxelShape[]{
|
|
Block.box(0.0, 0.0, 0.0, 16.0, 5.0, 16.0),
|
|
Block.box(0.0, 0.0, 0.0, 16.0, 8.0, 16.0),
|
|
Block.box(0.0, 0.0, 0.0, 16.0, 11.0, 16.0),
|
|
Block.box(0.0, 0.0, 0.0, 16.0, 14.0, 16.0)
|
|
};
|
|
|
|
@Override
|
|
public MapCodec<NetherWartBlock> codec() {
|
|
return CODEC;
|
|
}
|
|
|
|
protected NetherWartBlock(BlockBehaviour.Properties properties) {
|
|
super(properties);
|
|
this.registerDefaultState(this.stateDefinition.any().setValue(AGE, 0));
|
|
}
|
|
|
|
@Override
|
|
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
|
return SHAPE_BY_AGE[state.getValue(AGE)];
|
|
}
|
|
|
|
@Override
|
|
protected boolean mayPlaceOn(BlockState state, BlockGetter level, BlockPos pos) {
|
|
return state.is(Blocks.SOUL_SAND);
|
|
}
|
|
|
|
@Override
|
|
protected boolean isRandomlyTicking(BlockState state) {
|
|
return (Integer)state.getValue(AGE) < 3;
|
|
}
|
|
|
|
@Override
|
|
protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
|
|
int i = (Integer)state.getValue(AGE);
|
|
if (i < 3 && random.nextInt(10) == 0) {
|
|
state = state.setValue(AGE, i + 1);
|
|
level.setBlock(pos, state, 2);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getCloneItemStack(LevelReader level, BlockPos pos, BlockState state) {
|
|
return new ItemStack(Items.NETHER_WART);
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
builder.add(AGE);
|
|
}
|
|
}
|