-
Notifications
You must be signed in to change notification settings - Fork 12
Allow teapots to be filled from fluid containers, and allow milk pickup #57
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5564460
Add FluidHandler to teapot
jshipley 9b3f284
Allow teapots to be filled from fluid containers, and allow milk pick…
jshipley 1cdb87c
Merge branch 'fluid_teapot' into fill_from_tank
jshipley e642204
Added configurable teapot capacity
jshipley c605e79
Small cleanup changes for PR
jshipley e77cbe3
Treat water as infinite when infiniteWater config option is set inste…
jshipley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/knightminer/simplytea/fluid/FluidTeapotWrapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package knightminer.simplytea.fluid; | ||
|
|
||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import knightminer.simplytea.core.Config; | ||
| import knightminer.simplytea.core.Registration; | ||
| import net.minecraft.core.Direction; | ||
| import net.minecraft.world.item.ItemStack; | ||
| import net.minecraft.world.item.Items; | ||
| import net.minecraft.world.level.material.Fluid; | ||
| import net.minecraft.world.level.material.Fluids; | ||
| import net.minecraftforge.common.Tags; | ||
| import net.minecraftforge.common.capabilities.Capability; | ||
| import net.minecraftforge.common.capabilities.ForgeCapabilities; | ||
| import net.minecraftforge.common.capabilities.ICapabilityProvider; | ||
| import net.minecraftforge.common.util.LazyOptional; | ||
| import net.minecraftforge.fluids.FluidStack; | ||
| import net.minecraftforge.fluids.capability.IFluidHandlerItem; | ||
|
|
||
| public class FluidTeapotWrapper implements IFluidHandlerItem, ICapabilityProvider { | ||
| private final LazyOptional<IFluidHandlerItem> holder = LazyOptional.of(() -> this); | ||
|
|
||
| @NotNull | ||
| protected ItemStack container; | ||
| protected FluidStack fluid = FluidStack.EMPTY; | ||
|
|
||
| public FluidTeapotWrapper(ItemStack container) { | ||
| this.container = container; | ||
| } | ||
|
|
||
| @Override | ||
| public int getTanks() { | ||
| return 1; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull FluidStack getFluidInTank(int tank) { | ||
| return FluidStack.EMPTY; | ||
| } | ||
|
|
||
| @Override | ||
| public int getTankCapacity(int tank) { | ||
| return Config.SERVER.teapot.teapotCapacity(); | ||
| } | ||
|
|
||
| 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) || fluid.isSame(Fluids.FLOWING_WATER); | ||
| } | ||
|
|
||
| public static boolean isMilk(Fluid fluid) { | ||
| // Be more flexible with MILK because if it's tagged as MILK then it should really be milk | ||
| return fluid.is(Tags.Fluids.MILK) || fluid.getBucket() == Items.MILK_BUCKET; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isFluidValid(int tank, @NotNull FluidStack fluid) { | ||
| return isWater(fluid.getFluid()) || isMilk(fluid.getFluid()); | ||
| } | ||
|
|
||
| @Override | ||
| public int fill(FluidStack resource, FluidAction action) { | ||
| if (container.getCount() != 1 || !isFluidValid(0, resource) || resource.getAmount() < Config.SERVER.teapot.teapotCapacity()) { | ||
| return 0; | ||
| } | ||
|
|
||
| if (action.execute()) { | ||
| if (isWater(resource.getFluid())) { | ||
| this.container = new ItemStack(Registration.teapot_water); | ||
| } else if (isMilk(resource.getFluid())) { | ||
| this.container = new ItemStack(Registration.teapot_milk); | ||
| } | ||
| } | ||
|
|
||
| return Config.SERVER.teapot.teapotCapacity(); | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull FluidStack drain(FluidStack resource, FluidAction action) { | ||
| return FluidStack.EMPTY; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull FluidStack drain(int maxDrain, FluidAction action) { | ||
| return FluidStack.EMPTY; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull ItemStack getContainer() { | ||
| return container; | ||
| } | ||
|
|
||
| @Override | ||
| public <T> @NotNull LazyOptional<T> getCapability(@NotNull Capability<T> capability, @Nullable Direction side) { | ||
| return ForgeCapabilities.FLUID_HANDLER_ITEM.orEmpty(capability, holder); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work if you make the config lower than 1000 for the teapot capacity? If not we need to special case that here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the way FluidUtil is handling it, it should be treated as a successful pickup as long as the item's fluid handler returns a non-zero filled amount.
The item fluid handler (FluidTeapotWrapper) uses the configured size. It will either "fill" 0 (fail) or teapotCapacity (success).