diff --git a/src/main/java/com/lovetropics/extras/ExtraBlocks.java b/src/main/java/com/lovetropics/extras/ExtraBlocks.java index fc821d9d..d3330a2b 100644 --- a/src/main/java/com/lovetropics/extras/ExtraBlocks.java +++ b/src/main/java/com/lovetropics/extras/ExtraBlocks.java @@ -843,7 +843,7 @@ private static BlockEntry seagrass(String blockName, @Nulla public static final BlockEntry PAPYRUS_STEM = REGISTRATE.block("papyrus_stem", PapyrusStemBlock::new) .initialProperties(() -> Blocks.SUGAR_CANE) .properties(p -> p.sound(SoundType.WOOD)) - .blockstate((ctx, prov) -> prov.getVariantBuilder(ctx.getEntry()).forAllStates(state -> { + .blockstate((ctx, prov) -> prov.getVariantBuilder(ctx.getEntry()).forAllStatesExcept(state -> { final String type = state.getValue(PapyrusStemBlock.TYPE).getSerializedName(); final String modelName = type + "_" + ctx.getName(); final ResourceLocation texture = prov.modLoc("block/papyrus/" + modelName); @@ -852,7 +852,7 @@ private static BlockEntry seagrass(String blockName, @Nulla .withExistingParent(modelName, prov.modLoc("block/papyrus_stem")) .texture("all", texture)) .build(); - })) + }, PapyrusStemBlock.WATERLOGGED)) .addLayer(() -> RenderType::cutout) .item() .model((ctx, prov) -> prov.generated(ctx, prov.modLoc("block/papyrus/plain_papyrus_stem"))) @@ -862,7 +862,7 @@ private static BlockEntry seagrass(String blockName, @Nulla public static final BlockEntry PAPYRUS_UMBEL = REGISTRATE.block("papyrus_umbel", PapyrusUmbelBlock::new) .initialProperties(() -> Blocks.SUGAR_CANE) .properties(p -> p.sound(SoundType.FLOWERING_AZALEA)) - .blockstate((ctx, prov) -> prov.getVariantBuilder(ctx.getEntry()).forAllStates(state -> { + .blockstate((ctx, prov) -> prov.getVariantBuilder(ctx.getEntry()).forAllStatesExcept(state -> { final String type = state.getValue(PapyrusStemBlock.TYPE).getSerializedName(); final String modelName = type + "_" + ctx.getName(); final ResourceLocation texture = prov.modLoc("block/papyrus/" + modelName); @@ -871,7 +871,7 @@ private static BlockEntry seagrass(String blockName, @Nulla .withExistingParent(modelName, prov.mcLoc("block/sugar_cane")) .texture("cross", texture)) .build(); - })) + }, PapyrusUmbelBlock.AGEING)) .addLayer(() -> RenderType::cutout) .item() .model((ctx, prov) -> prov.generated(ctx, prov.modLoc("block/papyrus/plain_papyrus_umbel"))) diff --git a/src/main/java/com/lovetropics/extras/block/PapyrusStemBlock.java b/src/main/java/com/lovetropics/extras/block/PapyrusStemBlock.java index 99ae338e..3e9d1089 100644 --- a/src/main/java/com/lovetropics/extras/block/PapyrusStemBlock.java +++ b/src/main/java/com/lovetropics/extras/block/PapyrusStemBlock.java @@ -14,23 +14,27 @@ import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; 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.EnumProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -public final class PapyrusStemBlock extends Block implements BonemealableBlock { - - +public final class PapyrusStemBlock extends Block implements SimpleWaterloggedBlock, BonemealableBlock { + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final EnumProperty TYPE = EnumProperty.create("type", Type.class); private static final VoxelShape SHAPE = Block.box(7.0, 0.0, 7.0, 9.0, 16.0, 9.0); protected static final int MAX_HEIGHT = 4; private static final int MIN_HEIGHT_FOR_FLOWERS = 2; public PapyrusStemBlock(final Properties properties) { - super(properties); - registerDefaultState(getStateDefinition().any().setValue(TYPE, Type.PLAIN)); + super(properties.randomTicks()); + registerDefaultState(getStateDefinition().any().setValue(TYPE, Type.PLAIN).setValue(WATERLOGGED, false)); } @Override @@ -40,13 +44,8 @@ public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, Co @Override public BlockState getStateForPlacement(BlockPlaceContext context) { - return defaultBlockState(); - } - - @Override - protected boolean isRandomlyTicking(final BlockState state) { - //TODO can stop ticking if there is a flower on top? - return true; + FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); + return defaultBlockState().setValue(WATERLOGGED, fluid.getType() == Fluids.WATER); } @Override @@ -72,6 +71,7 @@ protected void randomTick(final BlockState state, final ServerLevel level, final } private boolean canGrow(final ServerLevel level, final BlockPos pos) { + // Don't grow naturally if there is water above us boolean aboveIsEmpty = level.isEmptyBlock(pos.above()); boolean hasReachedMaxHeight = hasStemHeightInclusive(level, pos, MAX_HEIGHT); @@ -99,6 +99,9 @@ protected BlockState updateShape(BlockState state, Direction direction, BlockSta if (!state.canSurvive(level, pos)) { level.scheduleTick(pos, this, 1); } + if (state.getValue(WATERLOGGED)) { + level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); + } return super.updateShape(state, direction, neighborState, level, pos, neighborPos); } @@ -111,7 +114,7 @@ protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSou @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(TYPE); + builder.add(TYPE, WATERLOGGED); } @Override @@ -132,6 +135,11 @@ public boolean isBonemealSuccess(final Level level, final RandomSource randomSou return true; } + @Override + public FluidState getFluidState(BlockState state) { + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); + } + public enum Type implements StringRepresentable { PLAIN("plain"), DRY("dry"),