From ea1a072c724525fecfdf298663e55cb030c536ef Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Sat, 16 Nov 2024 16:47:50 -0600 Subject: [PATCH] Added the ability for fluid collectors to collect water and lava from filled cauldrons. Closes #1440 --- CHANGELOG.md | 1 + .../data/FuelRecipeGenerator.java | 4 ++- .../mod/crafting/SolidFuelRecipe.java | 20 +++++++++----- .../mod/tile/TileEntityFluidCollector.java | 27 ++++++++++++++++--- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43d8562e9..890a6eebb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Fixed Farmer not playing well with non-vanilla farmland. * Added the ability to change the farmers work area with a compass. * Make blocks still drop items even when broken incorrectly. +* Added the ability for fluid collectors to collect water and lava from filled cauldrons. # 1.3.10+mc1.21.1 * Fixed Fluid placer not being harvestable. diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/FuelRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/FuelRecipeGenerator.java index 906ae57e7..3abad0aea 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/FuelRecipeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/FuelRecipeGenerator.java @@ -15,6 +15,7 @@ import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.Ingredient; +import net.neoforged.neoforge.common.Tags; import net.neoforged.neoforge.fluids.FluidStack; import javax.annotation.Nonnull; @@ -38,9 +39,10 @@ public class FuelRecipeGenerator extends RecipeProvider { addSolid(recipeOutput, "stick", Items.STICK, 2000, 100); addSolid(recipeOutput, "tiny-coal", ActuallyTags.Items.TINY_COALS, 4000, 200); addSolid(recipeOutput, "charcoal", Items.CHARCOAL, 32000, 1600); - addSolid(recipeOutput, "coal-block", Items.COAL_BLOCK, 320000, 16000); + addSolid(recipeOutput, "coal-block", Tags.Items.STORAGE_BLOCKS_COAL, 320000, 16000); addSolid(recipeOutput, "lava", Items.LAVA_BUCKET, 400000, 20000); + recipeOutput.accept(ActuallyAdditions.modLoc("liquid_fuel/canola_oil"), new LiquidFuelRecipe( new FluidStack(InitFluids.CANOLA_OIL.get(), 50), 4000, 100), null); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/SolidFuelRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/SolidFuelRecipe.java index 6dd6e5282..a721f7efe 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/SolidFuelRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/SolidFuelRecipe.java @@ -14,11 +14,13 @@ import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.SingleRecipeInput; import net.minecraft.world.level.Level; +import javax.annotation.Nonnull; + public class SolidFuelRecipe implements Recipe { public static String NAME = "solid_fuel"; - private Ingredient itemIngredient; - private int burnTime; - private int totalEnergy; + private final Ingredient itemIngredient; + private final int burnTime; + private final int totalEnergy; public SolidFuelRecipe(Ingredient itemIngredient, int totalEnergy, int burnTime) { this.itemIngredient = itemIngredient; @@ -35,7 +37,7 @@ public class SolidFuelRecipe implements Recipe { } @Override - public boolean matches(SingleRecipeInput pInv, Level pLevel) { + public boolean matches(SingleRecipeInput pInv, @Nonnull Level pLevel) { return itemIngredient.test(pInv.getItem(0)); } @@ -48,8 +50,9 @@ public class SolidFuelRecipe implements Recipe { return true; } + @Nonnull @Override - public ItemStack assemble(SingleRecipeInput pInv, HolderLookup.Provider registries) { + public ItemStack assemble(@Nonnull SingleRecipeInput pInv, @Nonnull HolderLookup.Provider registries) { return ItemStack.EMPTY; } @@ -58,16 +61,19 @@ public class SolidFuelRecipe implements Recipe { return false; } + @Nonnull @Override - public ItemStack getResultItem(HolderLookup.Provider provider) { + public ItemStack getResultItem(@Nonnull HolderLookup.Provider provider) { return ItemStack.EMPTY; } + @Nonnull @Override public RecipeSerializer getSerializer() { return ActuallyRecipes.SOLID_FUEL_RECIPE.get(); } + @Nonnull @Override public RecipeType getType() { return ActuallyRecipes.Types.SOLID_FUEL.get(); @@ -86,11 +92,13 @@ public class SolidFuelRecipe implements Recipe { SolidFuelRecipe.Serializer::toNetwork, SolidFuelRecipe.Serializer::fromNetwork ); + @Nonnull @Override public MapCodec codec() { return CODEC; } + @Nonnull @Override public StreamCodec streamCodec() { return STREAM_CODEC; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java index 1d0b1acf7..077751c12 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java @@ -31,12 +31,11 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluids; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.FluidType; import net.neoforged.neoforge.fluids.capability.IFluidHandler; @@ -104,6 +103,28 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing BlockPos coordsBlock = this.worldPosition.relative(sideToManipulate); BlockState stateToBreak = this.level.getBlockState(coordsBlock); + + // Try cauldron + if(stateToBreak.getBlock() instanceof AbstractCauldronBlock cauldron) { + if (cauldron.isFull(stateToBreak)) { + if (stateToBreak.getBlock() == Blocks.WATER_CAULDRON) { + if (this.tank.fillInternal(new FluidStack(Fluids.WATER, FluidType.BUCKET_VOLUME), IFluidHandler.FluidAction.SIMULATE) >= FluidType.BUCKET_VOLUME) { + this.tank.fillInternal(new FluidStack(Fluids.WATER, FluidType.BUCKET_VOLUME), IFluidHandler.FluidAction.EXECUTE); + level.setBlockAndUpdate(coordsBlock, Blocks.CAULDRON.defaultBlockState()); + level.playSound(null, coordsBlock, SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1.0F, 1.0F); + return; + } + } else if (stateToBreak.getBlock() == Blocks.LAVA_CAULDRON) { + if (this.tank.fillInternal(new FluidStack(Fluids.LAVA, FluidType.BUCKET_VOLUME), IFluidHandler.FluidAction.SIMULATE) >= FluidType.BUCKET_VOLUME) { + this.tank.fillInternal(new FluidStack(Fluids.LAVA, FluidType.BUCKET_VOLUME), IFluidHandler.FluidAction.EXECUTE); + level.setBlockAndUpdate(coordsBlock, Blocks.CAULDRON.defaultBlockState()); + level.playSound(null, coordsBlock, SoundEvents.BUCKET_FILL_LAVA, SoundSource.BLOCKS, 1.0F, 1.0F); + return; + } + } + } + } + Block blockToBreak = stateToBreak.getBlock(); if (!this.isPlacer && FluidType.BUCKET_VOLUME <= this.tank.getCapacity() - this.tank.getFluidAmount()) { if (blockToBreak instanceof LiquidBlock liquidBlock && liquidBlock.fluid != null && stateToBreak.getFluidState().isSource() ) {