mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-15 23:55:53 +01:00
Check for incorrect FluidBucketWrapper usage
Items that use FluidBucketWrapper incorrectly: - Will not get filling recipes - Cannot be filled with the spout
This commit is contained in:
parent
da6f2652e7
commit
e05db3cd76
2 changed files with 34 additions and 0 deletions
|
@ -12,6 +12,7 @@ import com.simibubi.create.AllBlocks;
|
|||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.compat.jei.category.animations.AnimatedSpout;
|
||||
import com.simibubi.create.content.contraptions.fluids.actors.FillingRecipe;
|
||||
import com.simibubi.create.content.contraptions.fluids.actors.GenericItemFilling;
|
||||
import com.simibubi.create.content.contraptions.fluids.potion.PotionFluidHandler;
|
||||
import com.simibubi.create.content.contraptions.processing.ProcessingRecipeBuilder;
|
||||
import com.simibubi.create.foundation.fluid.FluidIngredient;
|
||||
|
@ -71,6 +72,8 @@ public class SpoutCategory extends CreateRecipeCategory<FillingRecipe> {
|
|||
ItemStack copy = stack.copy();
|
||||
copy.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY)
|
||||
.ifPresent(fhi -> {
|
||||
if (!GenericItemFilling.isFluidHandlerValid(copy, fhi))
|
||||
return;
|
||||
FluidStack fluidCopy = fluidStack.copy();
|
||||
fluidCopy.setAmount(1000);
|
||||
fhi.fill(fluidCopy, FluidAction.EXECUTE);
|
||||
|
|
|
@ -5,9 +5,11 @@ import com.simibubi.create.content.contraptions.fluids.potion.PotionFluidHandler
|
|||
import com.simibubi.create.foundation.fluid.FluidHelper;
|
||||
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.BucketItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.MilkBucketItem;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.potion.Potions;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -20,6 +22,33 @@ import net.minecraftforge.fluids.capability.wrappers.FluidBucketWrapper;
|
|||
|
||||
public class GenericItemFilling {
|
||||
|
||||
/**
|
||||
* Checks if an ItemStack's IFluidHandlerItem is valid. Ideally, this check would
|
||||
* not be necessary. Unfortunately, some mods that copy the functionality of the
|
||||
* MilkBucketItem copy the FluidBucketWrapper capability that is patched in by
|
||||
* Forge without looking into what it actually does. In all cases this is
|
||||
* incorrect because having a non-bucket item turn into a bucket item does not
|
||||
* make sense.
|
||||
*
|
||||
* <p>This check is only necessary for filling since a FluidBucketWrapper will be
|
||||
* empty if it is initialized with a non-bucket item.
|
||||
*
|
||||
* @param stack The ItemStack.
|
||||
* @param fluidHandler The IFluidHandlerItem instance retrieved from the ItemStack.
|
||||
* @return If the IFluidHandlerItem is valid for the passed ItemStack.
|
||||
*/
|
||||
public static boolean isFluidHandlerValid(ItemStack stack, IFluidHandlerItem fluidHandler) {
|
||||
// Not instanceof in case a correct subclass is made
|
||||
if (fluidHandler.getClass() == FluidBucketWrapper.class) {
|
||||
Item item = stack.getItem();
|
||||
// Forge does not patch the FluidBucketWrapper onto subclasses of BucketItem
|
||||
if (item.getClass() != BucketItem.class && !(item instanceof MilkBucketItem)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canItemBeFilled(World world, ItemStack stack) {
|
||||
if (stack.getItem() == Items.GLASS_BOTTLE)
|
||||
return true;
|
||||
|
@ -31,6 +60,8 @@ public class GenericItemFilling {
|
|||
IFluidHandlerItem tank = capability.orElse(null);
|
||||
if (tank == null)
|
||||
return false;
|
||||
if (!isFluidHandlerValid(stack, tank))
|
||||
return false;
|
||||
for (int i = 0; i < tank.getTanks(); i++) {
|
||||
if (tank.getFluidInTank(i)
|
||||
.getAmount() < tank.getTankCapacity(i))
|
||||
|
|
Loading…
Reference in a new issue