mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 03:59:45 +00:00
Fix #856 Crash when clicking the fluid slot in NEI squeezer recipe
This commit is contained in:
1 parent
19a9c2681c
commit
cc5c8af338
5 files changed
+21
-29
No files matched your search
@@ -21,7 +21,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
@@ -196,23 +195,6 @@ public final class FluidHelper {
|
||||
return output.stackSize + drainedItem.stackSize <= output.getMaxStackSize();
|
||||
}
|
||||
|
||||
public static boolean isFillableContainer(ItemStack stack, FluidStack liquid) {
|
||||
ItemStack empty = ItemStackUtil.createSplitStack(stack, 1);
|
||||
Item item = empty.getItem();
|
||||
if (item instanceof IFluidContainerItem) {
|
||||
IFluidContainerItem containerItem = (IFluidContainerItem) item;
|
||||
return containerItem.fill(empty, liquid, false) > 0;
|
||||
}
|
||||
|
||||
for (FluidContainerData cont : FluidContainerRegistry.getRegisteredFluidContainerData()) {
|
||||
if (cont.fluid.isFluidEqual(liquid) && (cont.emptyContainer != null && cont.emptyContainer.isItemEqual(empty))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isEmptyContainer(ItemStack empty) {
|
||||
|
||||
if (FluidContainerRegistry.isEmptyContainer(empty)) {
|
||||
@@ -299,8 +281,7 @@ public final class FluidHelper {
|
||||
|
||||
Item item = empty.getItem();
|
||||
if (item instanceof IFluidContainerItem) {
|
||||
ItemStack full = empty.copy();
|
||||
full.stackSize = 1;
|
||||
ItemStack full = ItemStackUtil.createSplitStack(empty, 1);
|
||||
IFluidContainerItem containerItem = (IFluidContainerItem) item;
|
||||
containerItem.fill(full, liquid, true);
|
||||
return full;
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class SqueezerContainerRecipe implements ISqueezerContainerRecipe {
|
||||
|
||||
@@ -52,9 +53,14 @@ public class SqueezerContainerRecipe implements ISqueezerContainerRecipe {
|
||||
|
||||
@Override
|
||||
public ISqueezerRecipe getSqueezerRecipe(ItemStack filledContainer) {
|
||||
if (filledContainer == null) {
|
||||
return null;
|
||||
}
|
||||
FluidStack fluidOutput = FluidHelper.getFluidStackInContainer(filledContainer);
|
||||
ItemStack filledContainerCopy = filledContainer.copy();
|
||||
filledContainerCopy.stackSize = 1;
|
||||
if (fluidOutput == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack filledContainerCopy = ItemStackUtil.createSplitStack(filledContainer, 1);
|
||||
return new SqueezerRecipe(processingTime, new ItemStack[]{filledContainerCopy}, fluidOutput, remnants, remnantsChance);
|
||||
}
|
||||
|
||||
|
||||
@@ -221,10 +221,12 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase {
|
||||
}
|
||||
for (ISqueezerContainerRecipe containerRecipe : TileSqueezer.RecipeManager.containerRecipes.values()) {
|
||||
ItemStack emptyContainer = containerRecipe.getEmptyContainer();
|
||||
if (FluidHelper.isFillableContainer(emptyContainer, result)) {
|
||||
ItemStack filledContainer = FluidHelper.getFilledContainer(result, emptyContainer);
|
||||
ItemStack filledContainer = FluidHelper.getFilledContainer(result, emptyContainer);
|
||||
if (filledContainer != null) {
|
||||
ISqueezerRecipe recipe = containerRecipe.getSqueezerRecipe(filledContainer);
|
||||
this.arecipes.add(new CachedSqueezerRecipe(recipe, true));
|
||||
if (recipe != null) {
|
||||
this.arecipes.add(new CachedSqueezerRecipe(recipe, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa
|
||||
@Override
|
||||
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
|
||||
if (slotIndex == SLOT_RESOURCE) {
|
||||
return FluidHelper.isFillableContainer(itemStack, Fluids.WATER.getFluid(1000));
|
||||
return FluidHelper.getFilledContainer(Fluids.WATER.getFluid(1000), itemStack) != null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -415,9 +415,12 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
|
||||
public static ISqueezerRecipe findMatchingRecipe(ItemStack[] items) {
|
||||
// Find container recipes
|
||||
for (ItemStack itemStack : items) {
|
||||
ISqueezerContainerRecipe recipe = findMatchingContainerRecipe(itemStack);
|
||||
if (recipe != null) {
|
||||
return recipe.getSqueezerRecipe(itemStack);
|
||||
ISqueezerContainerRecipe containerRecipe = findMatchingContainerRecipe(itemStack);
|
||||
if (containerRecipe != null) {
|
||||
ISqueezerRecipe recipe = containerRecipe.getSqueezerRecipe(itemStack);
|
||||
if (recipe != null) {
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user