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

Allow teapots to be filled from fluid containers, and allow milk pickup #57

Open
wants to merge 5 commits into
base: 1.20
Choose a base branch
from

Conversation

jshipley
Copy link
Contributor

@jshipley jshipley commented Oct 15, 2024

Changes to teapot to support picking up water or milk from any block with fluid handler capabilities.
Also added new config option to allow/disallow pickup from fluid handler blocks.

Milk (if it's enabled) is also supported in more cases.

Tested with Flopper, Cooking for Blockheads sink and cow bottle, and Mekanism fluid tank.

Compiled/tested against 1.19, but the changes should also work for the 1.20 branch.

Closes #46

Happy Modtoberfest 2024!

@jshipley
Copy link
Contributor Author

I did most of this before the 1.20.1 PR was merged. Please let me know if you want me to resubmit this for 1.20.1 instead of 1.19.2.

BlockEntity entity = world.getBlockEntity(pos);
Optional<IFluidHandler> fluidHandler = Optional.empty();
if (entity != null) {
fluidHandler = entity.getCapability(ForgeCapabilities.FLUID_HANDLER, side).resolve();
Copy link
Owner

@KnightMiner KnightMiner Oct 16, 2024

Choose a reason for hiding this comment

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

Don't check the block fluid handler; just make the teapot item expose a fluid handler. See vanilla water buckets as an example (we won't be able to use the same fluid handler exactly, but should be able to use something similar). We shouldn't have to change any of this pickup logic, and that has the added benefit of supporting UI based fluid tanks.

You might find this class from Tinkers' Construct useful for reference, here is how to use it. Just know that is for an empty-only handler, we want a fill only handler. For our sake we also don't need all that supplier stuff, could just statically create the fluid stack as long as it copies in the right spots.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the fluid handler to the teapot item simplified the use() method quite a bit, but there are still blocks that aren't working without accessing the fluid handler.

The main blocks I found that weren't working were the MilkJarBlock and CowJarBlock from Cooking for Blockheads. The useItem() methods for those blocks specifically check for the bucket item, and the FluidUtil.tryPickUpFluid() method fails because there's no FluidState for the blocks.

So leaving a FluidUtil.tryFillContainer() attempt if FluidUtil.tryPickUpFluid() fails makes it work in cases where it would otherwise fail.

Copy link
Owner

Choose a reason for hiding this comment

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

I'd argue that sounds like a bug with the mod that adds MilkJarBlock, it would likely also break other mods of mine like Ceramics. We can probably leave that case as not working for now unless its easy to fix that without hardcoding/adding redundant logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's probably due to milk not being a real fluid in Vanilla. Maybe I'll look into submitting a PR for Cooking for Blockheads to see if it can be improved from that side.

Comment on lines 19 to 21
fill_from_fluid_tank = builder.comment("If true, the teapot can be filled with water from a fluid tank")
.translation("simplytea.config.teapot.fill_from_fluid_tank")
.define("fill_from_fluid_tank", true);
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure this needs to be a config. The cauldron stuff was a config option mostly as cauldrons are super messy, though tbh we can clean up that cauldron code using the new vanilla API a ton. Feel free to update the cauldron logic in this PR or make a separate PR if you are interested, see CauldronInteractions.

I think for this, I would like the config to specify how much to fill. Default it to 1000, but a modpack might decide 250 makes more sense for a pot of water. If it goes down to 0 we could disable it I guess, as consuming 0 fluid does not make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this config.

I also added a teapot_capacity config option, and changed the CauldronInteraction for teapots to lower the level of the cauldron according to the teapot_capacity by rounding to the nearest 1/3 bucket.

When this is updated to NeoForge 1.21 the CauldronInteraction for teapots can probably be removed in favor of using the CauldronWrapper with the fluid handling API.

@KnightMiner
Copy link
Owner

I did most of this before the 1.20.1 PR was merged. Please let me know if you want me to resubmit this for 1.20.1 instead of 1.19.2.

Either one is fine, I'll probably copy the PR back and forth once done as the code is mostly similar. Its probably a little easier if both PRs are on 1.20 but this is fine.

Fluid fluid = fluidState.getType();
// comparing with WATER fluid instead of WATER fluid tag, because many/most modded fluids are tagged as WATER
// to get water-like interactions even if the fluid is not water
if (fluid.isSame(Fluids.WATER)) {
Copy link
Owner

@KnightMiner KnightMiner Oct 16, 2024

Choose a reason for hiding this comment

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

We should also support milk if Forge's ForgeMod#MILK.isPresent() or whatever the check is to see that the milk fluid is enabled. In world pickup is not needed unless its easy to do, but definitely support it in the fluid handler I talk about in my other comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Between using the fluid handler on the teapot and using FluidUtil to pick up fluids, milk should be working without needing to specially check whether a milk fluid is enabled.

@KnightMiner
Copy link
Owner

As another thought on fluid handlers, might be nice if the filled teapots also act as fluid handlers, so you can dump them out into tanks. Only do it for the not-hot handlers, once its hot its a food now and is relevant to the other PR's domain.

@jshipley jshipley changed the base branch from 1.19 to 1.20 October 16, 2024 14:45
@jshipley
Copy link
Contributor Author

The only problem I see with adding empty-only fluid handlers to the (cold) filled teapots is that a teapot filled with milk will only be able to be emptied if fluid milk is enabled with other mods. So the water teapot and milk teapot will often have different behavior.

I think that the suggestion from #58 to make the cold teapots dumpable with animation, sound effects, and particles would probably be better. That also keeps the teapots from becoming too much like water buckets.

@jshipley
Copy link
Contributor Author

Also, the latest round of changes/testing have all been done on the 1.20 branch.

@KnightMiner
Copy link
Owner

I think that the suggestion from #58 to make the cold teapots dumpable with animation, sound effects, and particles would probably be better. That also keeps the teapots from becoming too much like water buckets

Thats reasonable. Lets stick with teapots being fill only and disallowing empty then.

public static boolean isWater(Fluid fluid) {
// Many modded fluids use the WATER tag to give the fluids entity interaction
// Only accept Fluids.WATER and not any other fluid tagged as WATER
return fluid.isSame(Fluids.WATER);
Copy link
Owner

Choose a reason for hiding this comment

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

Probably should check fluid.isSame(Fluids.FLOWING_WATER) as well here. I doubt flowing water is actually going to show up in a tank, but just in case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it wouldn't hurt. It shouldn't change anything unless some other mod puts flowing water into a tank for some reason.

@@ -18,6 +22,9 @@ public Teapot(ForgeConfigSpec.Builder builder) {
milk_cow = builder.comment("If true, cows can be milked using a teapot to fill it with milk")
.translation("simplytea.config.teapot.milk_cow")
.define("milk_cow", true);
teapot_capacity = builder.comment("Amount of fluid a teapot can contain")
Copy link
Owner

Choose a reason for hiding this comment

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

Since we are not doing emptying, lets make this say something like "Amount of fluid consumed when filling a teapot from a tank". Contain suggests you can empty it into a tank

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


public class Teapot {
private BooleanValue infinite_water;
private BooleanValue fill_from_cauldron;
private BooleanValue fill_from_fluid_tank;
Copy link
Owner

Choose a reason for hiding this comment

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

I think this was forgotten during cleanup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.

@jshipley
Copy link
Contributor Author

I've cleaned up a couple of things and removed the last fluid transfer from TeapotItem::use()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cross-mod compatibility feature] Take liquid from fluid tanks
2 participants