From 1d5e883640fbf7eca40595c796312ac14bb49787 Mon Sep 17 00:00:00 2001 From: Gkoliver <37561701+TrueGkoliver@users.noreply.github.com> Date: Sat, 9 May 2020 14:00:08 -0500 Subject: [PATCH] Code cleanup --- .../common/block/crop/FakeGrowableBlock.java | 30 +++++++++++++- .../common/block/other/NWISWaterLogBlock.java | 41 ++++++++----------- .../pickelreedtype/PickelreedDoubleBlock.java | 12 +++++- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/gkoliver/nwis/common/block/crop/FakeGrowableBlock.java b/src/main/java/com/gkoliver/nwis/common/block/crop/FakeGrowableBlock.java index 903a9ad..05b6964 100644 --- a/src/main/java/com/gkoliver/nwis/common/block/crop/FakeGrowableBlock.java +++ b/src/main/java/com/gkoliver/nwis/common/block/crop/FakeGrowableBlock.java @@ -7,7 +7,12 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.IGrowable; +import net.minecraft.block.IWaterLoggable; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.Fluids; +import net.minecraft.fluid.IFluidState; +import net.minecraft.state.BooleanProperty; import net.minecraft.state.IntegerProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; @@ -19,12 +24,14 @@ import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; +import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; -public class FakeGrowableBlock extends Block { +public class FakeGrowableBlock extends Block implements IWaterLoggable { int stages; ECropTypes type; + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final IntegerProperty AGE = BlockStateProperties.AGE_0_7; //Stage block sizes private static final VoxelShape[] CARROT_SHAPES = new VoxelShape[]{ @@ -91,6 +98,7 @@ public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, } protected void fillStateContainer(StateContainer.Builder builder) { builder.add(AGE); + builder.add(WATERLOGGED); } @Override @@ -120,4 +128,24 @@ public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockP } return ActionResultType.SUCCESS; } + + public IFluidState getFluidState(BlockState state) { + return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); + } + + public boolean receiveFluid(IWorld worldIn, BlockPos pos, BlockState state, IFluidState fluidStateIn) { + return IWaterLoggable.super.receiveFluid(worldIn, pos, state, fluidStateIn); + } + + public boolean canContainFluid(IBlockReader worldIn, BlockPos pos, BlockState state, Fluid fluidIn) { + return IWaterLoggable.super.canContainFluid(worldIn, pos, state, fluidIn); + } + public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { + if (stateIn.get(WATERLOGGED)) { + worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); + } + + return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); + } + } diff --git a/src/main/java/com/gkoliver/nwis/common/block/other/NWISWaterLogBlock.java b/src/main/java/com/gkoliver/nwis/common/block/other/NWISWaterLogBlock.java index 09daebb..9fe7bbf 100644 --- a/src/main/java/com/gkoliver/nwis/common/block/other/NWISWaterLogBlock.java +++ b/src/main/java/com/gkoliver/nwis/common/block/other/NWISWaterLogBlock.java @@ -32,32 +32,25 @@ protected void fillStateContainer(Builder builder) { builder.add(WATERLOGGED); } public IFluidState getFluidState(BlockState state) { - return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); - } - - public boolean receiveFluid(IWorld worldIn, BlockPos pos, BlockState state, IFluidState fluidStateIn) { - return IWaterLoggable.super.receiveFluid(worldIn, pos, state, fluidStateIn); - } - - public boolean canContainFluid(IBlockReader worldIn, BlockPos pos, BlockState state, Fluid fluidIn) { - return IWaterLoggable.super.canContainFluid(worldIn, pos, state, fluidIn); - } + return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); + } - /** - * Update the provided state given the provided neighbor facing and neighbor state, returning a new state. - * For example, fences make their connections to the passed in state if possible, and wet concrete powder immediately - * returns its solidified counterpart. - * Note that this method should ideally consider only the specific face passed in. - */ - public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { - if (stateIn.get(WATERLOGGED)) { - worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); - } + public boolean receiveFluid(IWorld worldIn, BlockPos pos, BlockState state, IFluidState fluidStateIn) { + return IWaterLoggable.super.receiveFluid(worldIn, pos, state, fluidStateIn); + } - return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); - } - @Override - public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + public boolean canContainFluid(IBlockReader worldIn, BlockPos pos, BlockState state, Fluid fluidIn) { + return IWaterLoggable.super.canContainFluid(worldIn, pos, state, fluidIn); + } + public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { + if (stateIn.get(WATERLOGGED)) { + worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); + } + + return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); + } + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { boolean isSapling = (state.getBlock() == BlockRegistry.FAKE_OAK_SAPLING.get() || state.getBlock() == BlockRegistry.FAKE_BIRCH_SAPLING.get() || state.getBlock() == BlockRegistry.FAKE_SPRUCE_SAPLING.get() || diff --git a/src/main/java/com/gkoliver/nwis/common/block/vegitation/swex/pickelreedtype/PickelreedDoubleBlock.java b/src/main/java/com/gkoliver/nwis/common/block/vegitation/swex/pickelreedtype/PickelreedDoubleBlock.java index 1afde8d..c996b31 100644 --- a/src/main/java/com/gkoliver/nwis/common/block/vegitation/swex/pickelreedtype/PickelreedDoubleBlock.java +++ b/src/main/java/com/gkoliver/nwis/common/block/vegitation/swex/pickelreedtype/PickelreedDoubleBlock.java @@ -1,5 +1,15 @@ package com.gkoliver.nwis.common.block.vegitation.swex.pickelreedtype; -public class PickelreedDoubleBlock { +import net.minecraft.block.Block; +import net.minecraft.block.IWaterLoggable; +import net.minecraft.state.EnumProperty; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.state.properties.Half; +public class PickelreedDoubleBlock extends Block implements IWaterLoggable { + public PickelreedDoubleBlock(Properties properties) { + super(properties); + } + + public static final EnumProperty HALF = BlockStateProperties.HALF; }