More consolidated fluid container management- I've been meaning to get to this for a long time

This commit is contained in:
aidancbrady committed 2016-03-06 02:15:56 -05:00
1 parent d77de295f2
commit d332ad49b7
11 files changed
+321 -564

No files matched your search

@@ -65,7 +65,14 @@ public final class StackUtils
public static boolean equalsWildcardWithNBT(ItemStack wild, ItemStack check)
{
return equalsWildcard(wild, check) && (wild.stackTagCompound == null ? check.stackTagCompound == null : (wild.stackTagCompound == check.stackTagCompound || wild.stackTagCompound.equals(check.stackTagCompound)));
boolean wildcard = equalsWildcard(wild, check);
if(wild == null || check == null)
{
return wildcard;
}
return wildcard && (wild.stackTagCompound == null ? check.stackTagCompound == null : (wild.stackTagCompound == check.stackTagCompound || wild.stackTagCompound.equals(check.stackTagCompound)));
}
public static List<ItemStack> even(ItemStack stack1, ItemStack stack2)
@@ -31,6 +31,7 @@ import mekanism.common.recipe.machines.WasherRecipe;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.FluidContainerUtils;
import mekanism.common.util.FluidContainerUtils.FluidChecker;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.PipeUtils;
@@ -200,68 +201,11 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
{
if(inventory[0].getItem() instanceof IFluidContainerItem)
{
fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[0], FluidRegistry.WATER), true);
if(((IFluidContainerItem)inventory[0].getItem()).getFluid(inventory[0]) == null || fluidTank.getFluidAmount() == fluidTank.getCapacity())
{
if(inventory[1] == null)
{
inventory[1] = inventory[0].copy();
inventory[0] = null;
markDirty();
}
}
FluidContainerUtils.handleContainerItemEmpty(this, fluidTank, 0, 1, FluidChecker.check(FluidRegistry.WATER));
}
else if(FluidContainerRegistry.isFilledContainer(inventory[0]))
{
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);
if((fluidTank.getFluid() == null && itemFluid.amount <= MAX_FLUID) || fluidTank.getFluid().amount+itemFluid.amount <= MAX_FLUID)
{
if(itemFluid.getFluid() != FluidRegistry.WATER || (fluidTank.getFluid() != null && !fluidTank.getFluid().isFluidEqual(itemFluid)))
{
return;
}
ItemStack containerItem = inventory[0].getItem().getContainerItem(inventory[0]);
boolean filled = false;
if(containerItem != null)
{
if(inventory[1] == null || (ItemStack.areItemStacksEqual(inventory[1], containerItem) && inventory[1].stackSize+1 <= containerItem.getMaxStackSize()))
{
inventory[0] = null;
if(inventory[1] == null)
{
inventory[1] = containerItem;
}
else {
inventory[1].stackSize++;
}
filled = true;
}
}
else {
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
filled = true;
}
if(filled)
{
fluidTank.fill(itemFluid, true);
markDirty();
}
}
FluidContainerUtils.handleRegistryItemEmpty(this, fluidTank, 0, 1, FluidChecker.check(FluidRegistry.WATER));
}
}
}
@@ -8,6 +8,7 @@ import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.Range4D;
import mekanism.api.util.StackUtils;
import mekanism.common.Mekanism;
import mekanism.common.base.IFluidContainerManager;
import mekanism.common.block.BlockBasic;
@@ -125,7 +126,7 @@ public class TileEntityDynamicTank extends TileEntityMultiblock<SynchronizedTank
public void manageInventory()
{
int max = structure.volume * TankUpdateProtocol.FLUID_PER_TANK;
int needed = (structure.volume*TankUpdateProtocol.FLUID_PER_TANK)-(structure.fluidStored != null ? structure.fluidStored.amount : 0);
if(structure.inventory[0] != null)
{
@@ -133,152 +134,24 @@ public class TileEntityDynamicTank extends TileEntityMultiblock<SynchronizedTank
{
if(structure.editMode == ContainerEditMode.FILL && structure.fluidStored != null)
{
int prev = structure.fluidStored.amount;
structure.fluidStored.amount -= FluidContainerUtils.insertFluid(structure.fluidStored, structure.inventory[0]);
if(prev == structure.fluidStored.amount || structure.fluidStored.amount == 0)
{
if(structure.inventory[1] == null)
{
structure.inventory[1] = structure.inventory[0].copy();
structure.inventory[0] = null;
markDirty();
}
}
if(structure.fluidStored.amount == 0)
{
structure.fluidStored = null;
}
structure.fluidStored = FluidContainerUtils.handleContainerItemFill(this, structure.inventory, structure.fluidStored, 0, 1);
}
else if(structure.editMode == ContainerEditMode.EMPTY)
{
if(structure.fluidStored != null)
{
FluidStack received = FluidContainerUtils.extractFluid(max-structure.fluidStored.amount, structure.inventory[0], structure.fluidStored.getFluid());
if(received != null)
{
structure.fluidStored.amount += received.amount;
}
}
else {
structure.fluidStored = FluidContainerUtils.extractFluid(max, structure.inventory[0], null);
}
int newStored = structure.fluidStored != null ? structure.fluidStored.amount : 0;
if(((IFluidContainerItem)structure.inventory[0].getItem()).getFluid(structure.inventory[0]) == null || newStored == max)
{
if(structure.inventory[1] == null)
{
structure.inventory[1] = structure.inventory[0].copy();
structure.inventory[0] = null;
markDirty();
}
}
structure.fluidStored = FluidContainerUtils.handleContainerItemEmpty(this, structure.inventory, structure.fluidStored, needed, 0, 1, null);
}
}
else if(FluidContainerRegistry.isEmptyContainer(structure.inventory[0]) && (structure.editMode == ContainerEditMode.BOTH || structure.editMode == ContainerEditMode.FILL))
{
if(structure.fluidStored != null && structure.fluidStored.amount >= FluidContainerRegistry.BUCKET_VOLUME)
{
ItemStack filled = FluidContainerRegistry.fillFluidContainer(structure.fluidStored, structure.inventory[0]);
if(filled != null)
{
if(structure.inventory[1] == null || (ItemStack.areItemStacksEqual(structure.inventory[1], filled) && structure.inventory[1].stackSize+1 <= filled.getMaxStackSize()))
{
structure.inventory[0].stackSize--;
if(structure.inventory[0].stackSize <= 0)
{
structure.inventory[0] = null;
}
if(structure.inventory[1] == null)
{
structure.inventory[1] = filled;
}
else {
structure.inventory[1].stackSize++;
}
markDirty();
structure.fluidStored.amount -= FluidContainerRegistry.getFluidForFilledItem(filled).amount;
if(structure.fluidStored.amount == 0)
{
structure.fluidStored = null;
}
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
}
}
}
structure.fluidStored = FluidContainerUtils.handleRegistryItemFill(this, structure.inventory, structure.fluidStored, 0, 1);
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
}
else if(FluidContainerRegistry.isFilledContainer(structure.inventory[0]) && (structure.editMode == ContainerEditMode.BOTH || structure.editMode == ContainerEditMode.EMPTY))
{
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(structure.inventory[0]);
if((structure.fluidStored == null && itemFluid.amount <= max) || structure.fluidStored.amount+itemFluid.amount <= max)
{
if(structure.fluidStored != null && !structure.fluidStored.isFluidEqual(itemFluid))
{
return;
}
ItemStack containerItem = structure.inventory[0].getItem().getContainerItem(structure.inventory[0]);
boolean filled = false;
if(containerItem != null)
{
if(structure.inventory[1] == null || (ItemStack.areItemStacksEqual(structure.inventory[1], containerItem) && structure.inventory[1].stackSize+1 <= containerItem.getMaxStackSize()))
{
structure.inventory[0] = null;
if(structure.inventory[1] == null)
{
structure.inventory[1] = containerItem;
}
else {
structure.inventory[1].stackSize++;
}
filled = true;
}
}
else {
structure.inventory[0].stackSize--;
if(structure.inventory[0].stackSize == 0)
{
structure.inventory[0] = null;
}
filled = true;
}
if(filled)
{
if(structure.fluidStored == null)
{
structure.fluidStored = itemFluid.copy();
}
else {
structure.fluidStored.amount += itemFluid.amount;
}
markDirty();
}
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
}
structure.fluidStored = FluidContainerUtils.handleRegistryItemEmpty(this, structure.inventory, structure.fluidStored, needed, 0, 1, null);
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
}
}
}
@@ -91,63 +91,15 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
{
ChargeUtils.discharge(2, this);
if(inventory[0] != null)
if(inventory[0] != null && fluidTank.getFluid() != null)
{
if(fluidTank.getFluid() != null && fluidTank.getFluid().amount >= FluidContainerRegistry.BUCKET_VOLUME)
if(inventory[0].getItem() instanceof IFluidContainerItem)
{
if(inventory[0].getItem() instanceof IFluidContainerItem)
{
int prev = fluidTank.getFluidAmount();
fluidTank.drain(FluidContainerUtils.insertFluid(fluidTank, inventory[0]), true);
if(prev == fluidTank.getFluidAmount() || fluidTank.getFluidAmount() == 0)
{
if(inventory[1] == null)
{
inventory[1] = inventory[0].copy();
inventory[0] = null;
markDirty();
}
}
}
else if(FluidContainerRegistry.isEmptyContainer(inventory[0]))
{
ItemStack tempStack = FluidContainerRegistry.fillFluidContainer(fluidTank.getFluid(), inventory[0]);
if(tempStack != null)
{
if(inventory[1] == null)
{
fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
inventory[1] = tempStack;
inventory[0].stackSize--;
if(inventory[0].stackSize <= 0)
{
inventory[0] = null;
}
markDirty();
}
else if(tempStack.isItemEqual(inventory[1]) && tempStack.getMaxStackSize() > inventory[1].stackSize)
{
fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
inventory[1].stackSize++;
inventory[0].stackSize--;
if(inventory[0].stackSize <= 0)
{
inventory[0] = null;
}
markDirty();
}
}
}
FluidContainerUtils.handleContainerItemFill(this, fluidTank, 0, 1);
}
else if(FluidContainerRegistry.isEmptyContainer(inventory[0]))
{
FluidContainerUtils.handleRegistryItemFill(this, fluidTank, 0, 1);
}
}
}
@@ -171,121 +171,42 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
{
if(editMode == ContainerEditMode.FILL && fluidTank.getFluidAmount() > 0)
{
int prev = fluidTank.getFluidAmount();
fluidTank.drain(FluidContainerUtils.insertFluid(fluidTank, inventory[0]), true);
if(prev == fluidTank.getFluidAmount())
{
if(inventory[1] == null)
{
inventory[1] = inventory[0].copy();
inventory[0] = null;
markDirty();
}
}
FluidContainerUtils.handleContainerItemFill(this, fluidTank, 0, 1);
}
else if(editMode == ContainerEditMode.EMPTY)
{
fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[0]), true);
FluidStack ret = FluidContainerUtils.handleContainerItemEmpty(this, inventory, fluidTank.getFluid(), getCurrentNeeded(), 0, 1, null);
if(((IFluidContainerItem)inventory[0].getItem()).getFluid(inventory[0]) == null || fluidTank.getFluidAmount() == fluidTank.getCapacity())
if(ret != null)
{
if(inventory[1] == null)
fluidTank.setFluid(new FluidStack(ret.getFluid(), Math.min(fluidTank.getCapacity(), ret.amount)));
int rejects = Math.max(0, ret.amount - fluidTank.getCapacity());
if(rejects > 0)
{
inventory[1] = inventory[0].copy();
inventory[0] = null;
markDirty();
pushUp(new FluidStack(ret.getFluid(), rejects), true);
}
}
}
}
else if(FluidContainerRegistry.isEmptyContainer(inventory[0]) && (editMode == ContainerEditMode.BOTH || editMode == ContainerEditMode.FILL))
{
if(fluidTank.getFluid() != null && fluidTank.getFluid().amount >= FluidContainerRegistry.BUCKET_VOLUME)
{
ItemStack filled = FluidContainerRegistry.fillFluidContainer(fluidTank.getFluid(), inventory[0]);
if(filled != null)
{
if(inventory[1] == null || (ItemStack.areItemStacksEqual(inventory[1], filled) && inventory[1].stackSize+1 <= filled.getMaxStackSize()))
{
inventory[0].stackSize--;
if(inventory[0].stackSize <= 0)
{
inventory[0] = null;
}
if(inventory[1] == null)
{
inventory[1] = filled;
}
else {
inventory[1].stackSize++;
}
fluidTank.drain(FluidContainerRegistry.getFluidForFilledItem(filled).amount, true);
}
}
}
FluidContainerUtils.handleRegistryItemFill(this, fluidTank, 0, 1);
}
else if(FluidContainerRegistry.isFilledContainer(inventory[0]) && (editMode == ContainerEditMode.BOTH || editMode == ContainerEditMode.EMPTY))
{
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);
int needed = getCurrentNeeded();
if((fluidTank.getFluid() == null && itemFluid.amount <= fluidTank.getCapacity()) || itemFluid.amount <= needed)
FluidStack ret = FluidContainerUtils.handleRegistryItemEmpty(this, inventory, fluidTank.getFluid(), getCurrentNeeded(), 0, 1, null);
if(ret != null)
{
if(fluidTank.getFluid() != null && !fluidTank.getFluid().isFluidEqual(itemFluid))
fluidTank.setFluid(new FluidStack(ret.getFluid(), Math.min(fluidTank.getCapacity(), ret.amount)));
int rejects = Math.max(0, ret.amount - fluidTank.getCapacity());
if(rejects > 0)
{
return;
}
ItemStack containerItem = inventory[0].getItem().getContainerItem(inventory[0]);
boolean filled = false;
if(containerItem != null)
{
if(inventory[1] == null || (ItemStack.areItemStacksEqual(inventory[1], containerItem) && inventory[1].stackSize+1 <= containerItem.getMaxStackSize()))
{
inventory[0] = null;
if(inventory[1] == null)
{
inventory[1] = containerItem;
}
else {
inventory[1].stackSize++;
}
filled = true;
}
}
else {
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
filled = true;
}
if(filled)
{
int toFill = Math.min(needed, itemFluid.amount);
fluidTank.fill(itemFluid, true);
if(itemFluid.amount-toFill > 0)
{
pushUp(new FluidStack(itemFluid.getFluid(), itemFluid.amount-toFill), true);
}
pushUp(new FluidStack(ret.getFluid(), rejects), true);
}
}
}
@@ -383,6 +304,7 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
if(nbtTags.hasKey("fluidTank"))
{
fluidTank.setCapacity(tier.storage);
fluidTank.readFromNBT(nbtTags.getCompoundTag("fluidTank"));
}
}
@@ -393,6 +315,8 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
super.handlePacketData(dataStream);
tier = FluidTankTier.values()[dataStream.readInt()];
fluidTank.setCapacity(tier.storage);
clientActive = dataStream.readBoolean();
valve = dataStream.readInt();
editMode = ContainerEditMode.values()[dataStream.readInt()];
@@ -82,73 +82,13 @@ public class TileEntityFluidicPlenisher extends TileEntityElectricBlock implemen
if(inventory[0] != null)
{
if(inventory[0].getItem() instanceof IFluidContainerItem && ((IFluidContainerItem)inventory[0].getItem()).getFluid(inventory[0]) != null)
if(inventory[0].getItem() instanceof IFluidContainerItem)
{
if(((IFluidContainerItem)inventory[0].getItem()).getFluid(inventory[0]).getFluid().canBePlacedInWorld())
{
fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[0]), true);
if(((IFluidContainerItem) inventory[0].getItem()).getFluid(inventory[0]) == null || fluidTank.getFluidAmount() == fluidTank.getCapacity())
{
if(inventory[1] == null)
{
inventory[1] = inventory[0].copy();
inventory[0] = null;
markDirty();
}
}
}
FluidContainerUtils.handleContainerItemEmpty(this, fluidTank, 0, 1);
}
else if(FluidContainerRegistry.isFilledContainer(inventory[0]))
{
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);
if((fluidTank.getFluid() == null && itemFluid.amount <= fluidTank.getCapacity()) || fluidTank.getFluid().amount+itemFluid.amount <= fluidTank.getCapacity())
{
if((fluidTank.getFluid() != null && !fluidTank.getFluid().isFluidEqual(itemFluid)) || !itemFluid.getFluid().canBePlacedInWorld())
{
return;
}
ItemStack containerItem = inventory[0].getItem().getContainerItem(inventory[0]);
boolean filled = false;
if(containerItem != null)
{
if(inventory[1] == null || (ItemStack.areItemStacksEqual(inventory[1], containerItem) && inventory[1].stackSize+1 <= containerItem.getMaxStackSize()))
{
inventory[0] = null;
if(inventory[1] == null)
{
inventory[1] = containerItem;
}
else {
inventory[1].stackSize++;
}
filled = true;
}
}
else {
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
{
inventory[0] = null;
}
filled = true;
}
if(filled)
{
fluidTank.fill(itemFluid, true);
markDirty();
}
}
FluidContainerUtils.handleRegistryItemEmpty(this, fluidTank, 0, 1);
}
}
@@ -126,52 +126,11 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
{
if(inventory[2].getItem() instanceof IFluidContainerItem)
{
int prev = fluidTank.getFluidAmount();
fluidTank.drain(FluidContainerUtils.insertFluid(fluidTank, inventory[2]), true);
if(prev == fluidTank.getFluidAmount() || fluidTank.getFluidAmount() == 0)
{
if(inventory[3] == null)
{
inventory[3] = inventory[2].copy();
inventory[2] = null;
markDirty();
}
}
FluidContainerUtils.handleContainerItemFill(this, fluidTank, 2, 3);
}
else if(FluidContainerRegistry.isEmptyContainer(inventory[2]))
{
if(fluidTank.getFluid() != null && fluidTank.getFluid().amount >= FluidContainerRegistry.BUCKET_VOLUME)
{
ItemStack filled = FluidContainerRegistry.fillFluidContainer(fluidTank.getFluid(), inventory[2]);
if(filled != null)
{
if(inventory[3] == null || (ItemStack.areItemStacksEqual(inventory[3], filled) && inventory[3].stackSize+1 <= filled.getMaxStackSize()))
{
inventory[2].stackSize--;
if(inventory[2].stackSize <= 0)
{
inventory[2] = null;
}
if(inventory[3] == null)
{
inventory[3] = filled;
}
else {
inventory[3].stackSize++;
}
markDirty();
fluidTank.drain(FluidContainerRegistry.getFluidForFilledItem(filled).amount, true);
}
}
}
FluidContainerUtils.handleRegistryItemFill(this, fluidTank, 2, 3);
}
}
@@ -219,68 +178,11 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
{
if(inventory[2].getItem() instanceof IFluidContainerItem)
{
fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[2]), true);
if(((IFluidContainerItem)inventory[2].getItem()).getFluid(inventory[2]) == null || fluidTank.getFluidAmount() == fluidTank.getCapacity())
{
if(inventory[3] == null)
{
inventory[3] = inventory[2].copy();
inventory[2] = null;
markDirty();
}
}
FluidContainerUtils.handleContainerItemEmpty(this, fluidTank, 2, 3);
}
else if(FluidContainerRegistry.isFilledContainer(inventory[2]))
{
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[2]);
if((fluidTank.getFluid() == null && itemFluid.amount <= MAX_FLUID) || fluidTank.getFluid().amount+itemFluid.amount <= MAX_FLUID)
{
if(fluidTank.getFluid() != null && !fluidTank.getFluid().isFluidEqual(itemFluid))
{
return;
}
ItemStack containerItem = inventory[2].getItem().getContainerItem(inventory[2]);
boolean filled = false;
if(containerItem != null)
{
if(inventory[3] == null || (ItemStack.areItemStacksEqual(inventory[3], containerItem) && inventory[3].stackSize+1 <= containerItem.getMaxStackSize()))
{
inventory[2] = null;
if(inventory[3] == null)
{
inventory[3] = containerItem;
}
else {
inventory[3].stackSize++;
}
filled = true;
}
}
else {
inventory[2].stackSize--;
if(inventory[2].stackSize == 0)
{
inventory[2] = null;
}
filled = true;
}
if(filled)
{
fluidTank.fill(itemFluid, true);
markDirty();
}
}
FluidContainerUtils.handleRegistryItemEmpty(this, fluidTank, 2, 3);
}
}
@@ -10,6 +10,7 @@ import mekanism.api.Coord4D;
import mekanism.api.ISalinationSolar;
import mekanism.api.MekanismConfig.general;
import mekanism.api.Range4D;
import mekanism.api.util.StackUtils;
import mekanism.client.SparkleAnimation.INodeChecker;
import mekanism.common.Mekanism;
import mekanism.common.base.IActiveState;
@@ -20,6 +21,8 @@ import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.FluidInput;
import mekanism.common.recipe.machines.ThermalEvaporationRecipe;
import mekanism.common.util.FluidContainerUtils;
import mekanism.common.util.FluidContainerUtils.FluidChecker;
import mekanism.common.util.MekanismUtils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
@@ -31,6 +34,7 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidContainerItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -249,7 +253,7 @@ public class TileEntityThermalEvaporationController extends TileEntityThermalEva
markDirty();
}
else if(ItemStack.areItemStacksEqual(tempStack, inventory[3]) && tempStack.getMaxStackSize() > inventory[3].stackSize)
else if(StackUtils.equalsWildcardWithNBT(tempStack, inventory[3]) && tempStack.getMaxStackSize() > inventory[3].stackSize)
{
outputTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
@@ -270,53 +274,27 @@ public class TileEntityThermalEvaporationController extends TileEntityThermalEva
if(structured)
{
if(FluidContainerRegistry.isFilledContainer(inventory[0]))
if(inventory[0] != null)
{
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);
if((inputTank.getFluid() == null && itemFluid.amount <= getMaxFluid()) || inputTank.getFluid().amount+itemFluid.amount <= getMaxFluid())
if(inventory[0].getItem() instanceof IFluidContainerItem)
{
if(!hasRecipe(itemFluid.getFluid()) || (inputTank.getFluid() != null && !inputTank.getFluid().isFluidEqual(itemFluid)))
{
return;
}
ItemStack containerItem = inventory[0].getItem().getContainerItem(inventory[0]);
boolean filled = false;
if(containerItem != null)
{
if(inventory[1] == null || (ItemStack.areItemStacksEqual(inventory[1], containerItem) && inventory[1].stackSize+1 <= containerItem.getMaxStackSize()))
FluidContainerUtils.handleContainerItemEmpty(this, inputTank, 0, 1, new FluidChecker() {
@Override
public boolean isValid(Fluid f)
{
inventory[0] = null;
if(inventory[1] == null)
{
inventory[1] = containerItem;
}
else {
inventory[1].stackSize++;
}
filled = true;
return hasRecipe(f);
}
}
else {
inventory[0].stackSize--;
if(inventory[0].stackSize == 0)
});
}
else if(FluidContainerRegistry.isFilledContainer(inventory[0]))
{
FluidContainerUtils.handleRegistryItemEmpty(this, inputTank, 0, 1, new FluidChecker() {
@Override
public boolean isValid(Fluid f)
{
inventory[0] = null;
return hasRecipe(f);
}
filled = true;
}
if(filled)
{
inputTank.fill(itemFluid, true);
}
});
}
}
}
@@ -1,7 +1,11 @@
package mekanism.common.util;
import mekanism.api.util.StackUtils;
import mekanism.common.tile.TileEntityContainerBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidContainerItem;
@@ -10,15 +14,15 @@ public final class FluidContainerUtils
{
public static FluidStack extractFluid(FluidTank tileTank, ItemStack container)
{
return extractFluid(tileTank, container, tileTank.getFluid() != null ? tileTank.getFluid().getFluid() : null);
return extractFluid(tileTank, container, FluidChecker.check(tileTank.getFluid()));
}
public static FluidStack extractFluid(FluidTank tileTank, ItemStack container, Fluid fluid)
public static FluidStack extractFluid(FluidTank tileTank, ItemStack container, FluidChecker checker)
{
return extractFluid(tileTank.getCapacity()-tileTank.getFluidAmount(), container, fluid);
return extractFluid(tileTank.getCapacity()-tileTank.getFluidAmount(), container, checker);
}
public static FluidStack extractFluid(int needed, ItemStack container, Fluid fluid)
public static FluidStack extractFluid(int needed, ItemStack container, FluidChecker checker)
{
IFluidContainerItem item = (IFluidContainerItem)container.getItem();
@@ -27,7 +31,7 @@ public final class FluidContainerUtils
return null;
}
if(fluid != null && item.getFluid(container).getFluid() != fluid)
if(checker != null && !checker.isValid(item.getFluid(container).getFluid()))
{
return null;
}
@@ -52,6 +56,205 @@ public final class FluidContainerUtils
return item.fill(container, fluid, true);
}
public static void handleContainerItemFill(TileEntityContainerBlock tileEntity, FluidTank tank, int inSlot, int outSlot)
{
tank.setFluid(handleContainerItemFill(tileEntity, tileEntity.inventory, tank.getFluid(), inSlot, outSlot));
}
public static FluidStack handleContainerItemFill(TileEntity tileEntity, ItemStack[] inventory, FluidStack stack, int inSlot, int outSlot)
{
if(stack != null)
{
int prev = stack.amount;
stack.amount -= insertFluid(stack, inventory[inSlot]);
if(prev == stack.amount || stack.amount == 0)
{
if(inventory[outSlot] == null)
{
inventory[outSlot] = inventory[inSlot].copy();
inventory[inSlot] = null;
}
}
if(stack.amount == 0)
{
stack = null;
}
tileEntity.markDirty();
}
return stack;
}
public static void handleContainerItemEmpty(TileEntityContainerBlock tileEntity, FluidTank tank, int inSlot, int outSlot)
{
handleContainerItemEmpty(tileEntity, tank, inSlot, outSlot, null);
}
public static void handleContainerItemEmpty(TileEntityContainerBlock tileEntity, FluidTank tank, int inSlot, int outSlot, FluidChecker checker)
{
tank.setFluid(handleContainerItemEmpty(tileEntity, tileEntity.inventory, tank.getFluid(), tank.getCapacity()-tank.getFluidAmount(), inSlot, outSlot, checker));
}
public static FluidStack handleContainerItemEmpty(TileEntity tileEntity, ItemStack[] inventory, FluidStack stored, int needed, int inSlot, int outSlot, final FluidChecker checker)
{
final Fluid storedFinal = stored != null ? stored.getFluid() : null;
FluidStack ret = extractFluid(needed, inventory[inSlot], new FluidChecker() {
@Override
public boolean isValid(Fluid f)
{
return (checker == null || checker.isValid(f)) && (storedFinal == null || storedFinal == f);
}
});
if(ret != null)
{
if(stored == null)
{
stored = ret;
}
else {
stored.amount += ret.amount;
}
needed -= ret.amount;
tileEntity.markDirty();
}
if(((IFluidContainerItem)inventory[inSlot].getItem()).getFluid(inventory[inSlot]) == null || needed == 0)
{
if(inventory[outSlot] == null)
{
inventory[outSlot] = inventory[inSlot].copy();
inventory[inSlot] = null;
tileEntity.markDirty();
}
}
return stored;
}
public static void handleRegistryItemFill(TileEntityContainerBlock tileEntity, FluidTank tank, int inSlot, int outSlot)
{
tank.setFluid(handleRegistryItemFill(tileEntity, tileEntity.inventory, tank.getFluid(), inSlot, outSlot));
}
public static FluidStack handleRegistryItemFill(TileEntity tileEntity, ItemStack[] inventory, FluidStack stack, int inSlot, int outSlot)
{
if(stack != null)
{
ItemStack filled = FluidContainerRegistry.fillFluidContainer(stack, inventory[inSlot]);
if(filled != null)
{
if(inventory[outSlot] == null || (StackUtils.equalsWildcardWithNBT(inventory[outSlot], filled) && inventory[outSlot].stackSize+1 <= filled.getMaxStackSize()))
{
inventory[inSlot].stackSize--;
if(inventory[inSlot].stackSize <= 0)
{
inventory[inSlot] = null;
}
if(inventory[outSlot] == null)
{
inventory[outSlot] = filled;
}
else {
inventory[outSlot].stackSize++;
}
stack.amount -= FluidContainerRegistry.getFluidForFilledItem(filled).amount;
if(stack.amount == 0)
{
return null;
}
tileEntity.markDirty();
}
}
}
return stack;
}
public static void handleRegistryItemEmpty(TileEntityContainerBlock tileEntity, FluidTank tank, int inSlot, int outSlot)
{
handleRegistryItemEmpty(tileEntity, tank, inSlot, outSlot, null);
}
public static void handleRegistryItemEmpty(TileEntityContainerBlock tileEntity, FluidTank tank, int inSlot, int outSlot, FluidChecker checker)
{
tank.setFluid(handleRegistryItemEmpty(tileEntity, tileEntity.inventory, tank.getFluid(), tank.getCapacity()-tank.getFluidAmount(), inSlot, outSlot, checker));
}
public static FluidStack handleRegistryItemEmpty(TileEntity tileEntity, ItemStack[] inventory, FluidStack stored, int needed, int inSlot, int outSlot, final FluidChecker checker)
{
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[inSlot]);
if(itemFluid != null && itemFluid.amount <= needed)
{
if((stored != null && !stored.isFluidEqual(itemFluid)) || (checker != null && !checker.isValid(itemFluid.getFluid())))
{
return stored;
}
ItemStack containerItem = inventory[inSlot].getItem().getContainerItem(inventory[inSlot]);
boolean filled = false;
if(containerItem != null)
{
if(inventory[outSlot] == null || (StackUtils.equalsWildcardWithNBT(inventory[outSlot], containerItem) && inventory[outSlot].stackSize+1 <= containerItem.getMaxStackSize()))
{
inventory[inSlot] = null;
if(inventory[outSlot] == null)
{
inventory[outSlot] = containerItem;
}
else {
inventory[outSlot].stackSize++;
}
filled = true;
}
}
else {
inventory[inSlot].stackSize--;
if(inventory[inSlot].stackSize == 0)
{
inventory[inSlot] = null;
}
filled = true;
}
if(filled)
{
if(stored == null)
{
stored = itemFluid.copy();
}
else {
stored.amount += itemFluid.amount;
}
tileEntity.markDirty();
}
}
return stored;
}
public static enum ContainerEditMode
{
BOTH("fluidedit.both"),
@@ -70,4 +273,36 @@ public final class FluidContainerUtils
display = s;
}
}
public static class FluidChecker
{
public boolean isValid(Fluid f)
{
return true;
}
public static FluidChecker check(FluidStack fluid)
{
final Fluid type = fluid != null ? fluid.getFluid() : null;
return new FluidChecker() {
@Override
public boolean isValid(Fluid f)
{
return type == null || type == f;
}
};
}
public static FluidChecker check(final Fluid type)
{
return new FluidChecker() {
@Override
public boolean isValid(Fluid f)
{
return type == null || type == f;
}
};
}
}
}
@@ -8,6 +8,7 @@ import java.util.Map;
import mekanism.api.energy.IEnergizedItem;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasItem;
import mekanism.api.util.StackUtils;
import mekanism.common.Upgrade;
import mekanism.common.base.IEnergyCube;
import mekanism.common.base.IFactory;
@@ -253,7 +254,7 @@ public class RecipeUtils
if(iterRecipe instanceof ShapedMekanismRecipe || iterRecipe instanceof ShapelessMekanismRecipe)
{
if(ItemStack.areItemStacksEqual(stack, iterRecipe.getRecipeOutput()))
if(StackUtils.equalsWildcard(stack, iterRecipe.getRecipeOutput()))
{
iter.remove();
}
@@ -10,6 +10,7 @@ import mekanism.api.MekanismConfig.generators;
import mekanism.common.base.ISustainedData;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.FluidContainerUtils;
import mekanism.common.util.FluidContainerUtils.FluidChecker;
import mekanism.common.util.HeatUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.PipeUtils;
@@ -68,7 +69,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu
if(inventory[0].getItem() instanceof IFluidContainerItem)
{
lavaTank.fill(FluidContainerUtils.extractFluid(lavaTank, inventory[0], FluidRegistry.LAVA), true);
lavaTank.fill(FluidContainerUtils.extractFluid(lavaTank, inventory[0], FluidChecker.check(FluidRegistry.LAVA)), true);
}
else if(fluid != null)
{