From 3319a9673a292f4f1cbf5c98f3d76365027ed384 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 5 Feb 2020 14:30:17 +0100 Subject: [PATCH] added waterlogging to non-full blocks Closes #75 --- .../blocks/BlockAnimalContainer.java | 5 +++ .../naturesaura/blocks/BlockAutoCrafter.java | 3 +- .../blocks/BlockBlastFurnaceBooster.java | 8 +++- .../naturesaura/blocks/BlockChunkLoader.java | 5 +++ .../blocks/BlockContainerImpl.java | 43 +++++++++++++++++++ .../naturesaura/blocks/BlockFieldCreator.java | 2 +- .../blocks/BlockFurnaceHeater.java | 8 +++- .../naturesaura/blocks/BlockGratedChute.java | 8 +++- .../naturesaura/blocks/BlockNatureAltar.java | 5 +++ .../blocks/BlockOfferingTable.java | 5 +++ .../naturesaura/blocks/BlockPowderPlacer.java | 5 +++ .../naturesaura/blocks/BlockSpawnLamp.java | 5 +++ .../naturesaura/blocks/BlockWoodStand.java | 5 +++ .../models/block/furnace_heater.json | 15 +++---- 14 files changed, 107 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockAnimalContainer.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAnimalContainer.java index 7526351b..6682e784 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockAnimalContainer.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAnimalContainer.java @@ -24,6 +24,11 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali super("animal_container", TileEntityAnimalContainer::new, ModBlocks.prop(Blocks.STONE)); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return SHAPE; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockAutoCrafter.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAutoCrafter.java index f46c4c1b..f9fcf4b7 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockAutoCrafter.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAutoCrafter.java @@ -21,12 +21,13 @@ public class BlockAutoCrafter extends BlockContainerImpl implements ICustomBlock @Override protected void fillStateContainer(StateContainer.Builder builder) { + super.fillStateContainer(builder); builder.add(FACING); } @Override public BlockState getStateForPlacement(BlockItemUseContext context) { - return this.getDefaultState().with(FACING, context.getPlayer().getHorizontalFacing()); + return super.getStateForPlacement(context).with(FACING, context.getPlayer().getHorizontalFacing()); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockBlastFurnaceBooster.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockBlastFurnaceBooster.java index 30d4735c..c2b4270a 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockBlastFurnaceBooster.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockBlastFurnaceBooster.java @@ -24,6 +24,11 @@ public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICus super("blast_furnace_booster", TileEntityBlastFurnaceBooster::new, Block.Properties.from(Blocks.BLAST_FURNACE)); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return SHAPE; @@ -31,12 +36,13 @@ public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICus @Override protected void fillStateContainer(StateContainer.Builder builder) { + super.fillStateContainer(builder); builder.add(FACING); } @Override public BlockState getStateForPlacement(BlockItemUseContext context) { - return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite()); + return super.getStateForPlacement(context).with(FACING, context.getPlacementHorizontalFacing().getOpposite()); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockChunkLoader.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockChunkLoader.java index 5c8f05e6..d97280c6 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockChunkLoader.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockChunkLoader.java @@ -29,6 +29,11 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl super("chunk_loader", TileEntityChunkLoader::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE)); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @Override @OnlyIn(Dist.CLIENT) public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockContainerImpl.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockContainerImpl.java index 6d7ed9b5..f408b160 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockContainerImpl.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockContainerImpl.java @@ -7,8 +7,15 @@ import de.ellpeck.naturesaura.reg.ModTileType; import net.minecraft.block.*; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.Fluids; +import net.minecraft.fluid.IFluidState; +import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; +import net.minecraft.state.StateContainer; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tags.FluidTags; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; @@ -17,6 +24,7 @@ import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraft.world.storage.loot.LootContext; import net.minecraft.world.storage.loot.LootParameters; +import net.minecraft.world.storage.loot.conditions.BlockStateProperty; import javax.annotation.Nullable; import java.util.List; @@ -36,6 +44,41 @@ public class BlockContainerImpl extends ContainerBlock implements IModItem { ModRegistry.add(this); ModRegistry.add(this.tileType); + + if(this.hasWaterlogging()) + this.setDefaultState(this.stateContainer.getBaseState().with(BlockStateProperties.WATERLOGGED, false)); + } + + protected boolean hasWaterlogging() { + return false; + } + + @Override + protected void fillStateContainer(StateContainer.Builder builder) { + if (this.hasWaterlogging()) + builder.add(BlockStateProperties.WATERLOGGED); + } + + @Override + public IFluidState getFluidState(BlockState state) { + return this.hasWaterlogging() && state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); + } + + @Override + public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { + if (this.hasWaterlogging() && stateIn.get(BlockStateProperties.WATERLOGGED)) + worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); + return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); + } + + @Override + @Nullable + public BlockState getStateForPlacement(BlockItemUseContext context) { + if (this.hasWaterlogging()) { + IFluidState state = context.getWorld().getFluidState(context.getPos()); + return this.getDefaultState().with(BlockStateProperties.WATERLOGGED, state.isTagged(FluidTags.WATER) && state.getLevel() == 8); + } + return super.getStateForPlacement(context); } @Nullable diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockFieldCreator.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockFieldCreator.java index 3a65c4bc..f2429f62 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockFieldCreator.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockFieldCreator.java @@ -28,7 +28,7 @@ import java.util.function.Supplier; public class BlockFieldCreator extends BlockContainerImpl implements ICustomBlockState, ICustomRenderType { public BlockFieldCreator() { - super("field_creator", TileEntityFieldCreator::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE)); + super("field_creator", TileEntityFieldCreator::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(2F).notSolid().sound(SoundType.STONE)); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockFurnaceHeater.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockFurnaceHeater.java index 5ae90a03..9abfbe22 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockFurnaceHeater.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockFurnaceHeater.java @@ -41,6 +41,11 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo super("furnace_heater", TileEntityFurnaceHeater::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(3F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @Override @OnlyIn(Dist.CLIENT) public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) { @@ -86,13 +91,14 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo @Override protected void fillStateContainer(StateContainer.Builder builder) { + super.fillStateContainer(builder); builder.add(FACING); } @Nullable @Override public BlockState getStateForPlacement(BlockItemUseContext context) { - return this.getDefaultState().with(FACING, context.getFace()); + return super.getStateForPlacement(context).with(FACING, context.getFace()); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java index 56d5b621..46ce9c35 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java @@ -52,6 +52,11 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock super("grated_chute", TileEntityGratedChute::new, ModBlocks.prop(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL)); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { switch (state.get(FACING)) { @@ -109,7 +114,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock Direction newFacing = context.getFace().getOpposite(); if (newFacing == Direction.UP) newFacing = Direction.DOWN; - return this.getDefaultState().with(FACING, newFacing); + return super.getStateForPlacement(context).with(FACING, newFacing); } @Override @@ -137,6 +142,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock @Override protected void fillStateContainer(StateContainer.Builder builder) { + super.fillStateContainer(builder); builder.add(FACING); } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java index 8e9327af..f1fcf5ab 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockNatureAltar.java @@ -36,6 +36,11 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide super("nature_altar", TileEntityNatureAltar::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(4F).harvestLevel(1).harvestTool(ToolType.PICKAXE)); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return SHAPE; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockOfferingTable.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockOfferingTable.java index 38eae0fc..8a79b020 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockOfferingTable.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockOfferingTable.java @@ -36,6 +36,11 @@ public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvi super("offering_table", TileEntityOfferingTable::new, ModBlocks.prop(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD)); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { return Helper.putStackOnTile(player, handIn, pos, 0, true); diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockPowderPlacer.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockPowderPlacer.java index 96b6d5d5..7dd5d067 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockPowderPlacer.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockPowderPlacer.java @@ -20,6 +20,11 @@ public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBloc super("powder_placer", TileEntityPowderPlacer::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(2, 5F).sound(SoundType.STONE)); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return SHAPE; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java index e411b243..9af43d86 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java @@ -42,6 +42,11 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable, MinecraftForge.EVENT_BUS.register(this); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @SubscribeEvent public void onSpawn(LivingSpawnEvent.CheckSpawn event) { if (event.getSpawner() != null) diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java index b92f590c..194abad4 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java @@ -52,6 +52,11 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider< MinecraftForge.EVENT_BUS.register(this); } + @Override + protected boolean hasWaterlogging() { + return true; + } + @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return SHAPE; diff --git a/src/main/resources/assets/naturesaura/models/block/furnace_heater.json b/src/main/resources/assets/naturesaura/models/block/furnace_heater.json index eb770fcb..06e0ae2c 100644 --- a/src/main/resources/assets/naturesaura/models/block/furnace_heater.json +++ b/src/main/resources/assets/naturesaura/models/block/furnace_heater.json @@ -11,8 +11,7 @@ "faces": { "down": { "uv": [0, 4, 12, 16], - "texture": "#texture", - "cullface": "down" + "texture": "#texture" }, "up": { "uv": [0, 4, 12, 16], @@ -20,23 +19,19 @@ }, "north": { "uv": [0, 0, 12, 4], - "texture": "#texture", - "cullface": "north" + "texture": "#texture" }, "south": { "uv": [0, 0, 12, 4], - "texture": "#texture", - "cullface": "south" + "texture": "#texture" }, "west": { "uv": [0, 0, 12, 4], - "texture": "#texture", - "cullface": "west" + "texture": "#texture" }, "east": { "uv": [0, 0, 12, 4], - "texture": "#texture", - "cullface": "east" + "texture": "#texture" } } }