Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for fluid tanks in feeding slabs #625

Open
wants to merge 2 commits into
base: dev-1.21.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public static class Bees
public final ModConfigSpec.DoubleValue kamikazBeeChance;
public final ModConfigSpec.BooleanValue disableWanderGoal;
public final ModConfigSpec.BooleanValue enableResinBeeEncasing;
public final ModConfigSpec.IntValue minimumMbForFlowering;

public Bees(ModConfigSpec.Builder builder) {
builder.push("Bees");
Expand Down Expand Up @@ -212,6 +213,10 @@ public Bees(ModConfigSpec.Builder builder) {
enableResinBeeEncasing = builder
.comment("Allow resin bees to encase mobs in amber. With this disabled it's only possible with an amber bee and it's also not as fun.")
.define("enableResinBeeEncasing", true);

minimumMbForFlowering = builder
.comment("The minimum amount of Mb of a fluid for bees that require a fluid to be able to pollinate")
.defineInRange("minimumMbForFlowering", 1000, 0, Integer.MAX_VALUE);

builder.pop();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cy.jdkdigital.productivebees.common.block.entity;

import cy.jdkdigital.productivebees.ProductiveBeesConfig;
import cy.jdkdigital.productivebees.common.block.Feeder;
import cy.jdkdigital.productivebees.container.FeederContainer;
import cy.jdkdigital.productivebees.init.ModBlockEntityTypes;
Expand Down Expand Up @@ -33,6 +34,8 @@
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.phys.AABB;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.IItemHandlerModifiable;

Expand Down Expand Up @@ -65,6 +68,11 @@ public Block getRandomBlockFromInventory(TagKey<Block> tag, RandomSource random)
if (tag == null || itemBlock.builtInRegistryHolder().is(tag)) {
possibleBlocks.add(itemBlock);
}
} else {
IFluidHandler stackFluidTank = stack.getCapability(Capabilities.FluidHandler.ITEM);
if (stackFluidTank != null && stackFluidTank.getFluidInTank(0).getAmount() >= ProductiveBeesConfig.BEES.minimumMbForFlowering.get()) {
possibleBlocks.add(stackFluidTank.getFluidInTank(0).getFluid().defaultFluidState().createLegacyBlock().getBlock());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about fluids that don't have blocks?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik, there's no way for fluids without blocks to be used right now so it would be consistent with the current behavior, but if I'm wrong or you want it to work for fluids without blocks, I would need to modify the call to be TagKey<Item> tag rather than TagKey<Block> tag which I'm fine doing, I was just trying not to change the existing code too much.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code again, I can't seem to find anywhere that non block fluids work at all, but if you can give me an example of how to use a fluid that doesn't have a block before this PR, I can definitely look at how that one is done.

}
}
}
return possibleBlocks.size() > 0 ? possibleBlocks.get(random.nextInt(possibleBlocks.size())) : Blocks.AIR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cy.jdkdigital.productivebees.common.entity.bee;

import cy.jdkdigital.productivebees.ProductiveBees;
import cy.jdkdigital.productivebees.ProductiveBeesConfig;
import cy.jdkdigital.productivebees.client.particle.NectarParticleType;
import cy.jdkdigital.productivebees.common.block.entity.AdvancedBeehiveBlockEntity;
import cy.jdkdigital.productivebees.common.block.entity.AmberBlockEntity;
Expand Down Expand Up @@ -55,8 +56,10 @@
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.event.entity.EntityTeleportEvent;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -454,6 +457,16 @@ public boolean isFlowerItem(ItemStack flowerItem) {
if (nbt.contains("flowerItem")) {
return flowerItem.is(BuiltInRegistries.ITEM.get(ResourceLocation.parse(nbt.getString("flowerItem"))));
}
if (nbt.contains("flowerFluid")) {
IFluidHandler flowerFluid = flowerItem.getCapability(Capabilities.FluidHandler.ITEM);
if (flowerFluid != null && flowerFluid.getFluidInTank(0).getAmount() >= ProductiveBeesConfig.BEES.minimumMbForFlowering.get()) {
if (nbt.getString("flowerFluid").contains("#")) {
return flowerFluid.getFluidInTank(0).is(new TagKey<Fluid>(BuiltInRegistries.FLUID.key(), ResourceLocation.parse(nbt.getString("flowerFluid").replace("#", ""))));
} else {
return flowerFluid.getFluidInTank(0).is(BuiltInRegistries.FLUID.get(ResourceLocation.parse(nbt.getString("flowerFluid"))));
}
}
}
}
if (flowerItem.getItem() instanceof BlockItem blockItem && BeeHelper.hasBlockConversionRecipe(this, blockItem.getBlock().defaultBlockState())) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import net.minecraft.world.level.pathfinder.PathType;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.HitResult;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -561,6 +563,10 @@ public boolean isFlowerItem(ItemStack flowerItem) {
if (flowerItem.getItem() instanceof BlockItem blockItem && isFlowerBlock(blockItem.getBlock().defaultBlockState())) {
return true;
}
IFluidHandler flowerFluid = flowerItem.getCapability(Capabilities.FluidHandler.ITEM);
if (flowerFluid != null && flowerFluid.getFluidInTank(0).getAmount() >= ProductiveBeesConfig.BEES.minimumMbForFlowering.get()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's only a check for the amount here, what about the fluid type?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was basing it mainly off the existing flower block system which uses the DEFAULT_FLOWERING_BLOCK tag, if I did it the same way, we would need to make a DEFAULT_FLOWERING_FLUID tag or have a way to grab the flowering fluid from within the ProductiveBee class. I think if you do want to check for the fluid here, adding the tags would be easier, but I'll work on doing it whichever way you want it done.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want a default flowering fluid, this here looks like it would enable any bee to flower off of a bucket of water.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that was checked for else where so I did a test. I'm not really sure how to do a proper test for this tbh, but I did 2 in game tests for half an hour each: both with 2 advanced hives and 4 Omega upgrades, 1 with a lava bucket in a feeding slab, 1 with a water bucket in a feeding slab. I put a water bee in both, and for the first test, just let it run, for the second test, I swapped the water bee to pollinate with lava to test it. Test 1, only the water hive filled with anything, test 2, only the lava hive filled with anything.

return true;
}
return BeeHelper.hasItemConversionRecipe(this, flowerItem);
}

Expand Down