mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-23 21:39:40 +00:00
Added in algorithm to merge both fluid and item data of Dynamic Tank multi blocks
This commit is contained in:
1 parent
540eed908e
commit
d24eaddee4
2 files changed
+108
-3
No files matched your search
@@ -146,4 +146,83 @@ public final class StackUtils
|
||||
{
|
||||
return stack != null ? stack.stackSize : 0;
|
||||
}
|
||||
|
||||
public static List<ItemStack> getMergeRejects(ItemStack[] orig, ItemStack[] toAdd)
|
||||
{
|
||||
List<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
|
||||
for(int i = 0; i < toAdd.length; i++)
|
||||
{
|
||||
if(toAdd[i] != null)
|
||||
{
|
||||
ItemStack reject = getMergeReject(orig[i], toAdd[i]);
|
||||
|
||||
if(reject != null)
|
||||
{
|
||||
ret.add(reject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void merge(ItemStack[] orig, ItemStack[] toAdd)
|
||||
{
|
||||
for(int i = 0; i < toAdd.length; i++)
|
||||
{
|
||||
if(toAdd[i] != null)
|
||||
{
|
||||
orig[i] = merge(orig[i], toAdd[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack merge(ItemStack orig, ItemStack toAdd)
|
||||
{
|
||||
if(orig == null)
|
||||
{
|
||||
return toAdd;
|
||||
}
|
||||
|
||||
if(toAdd == null)
|
||||
{
|
||||
return orig;
|
||||
}
|
||||
|
||||
if(!orig.isItemEqual(toAdd) || !ItemStack.areItemStackTagsEqual(orig, toAdd))
|
||||
{
|
||||
return orig;
|
||||
}
|
||||
|
||||
return StackUtils.size(orig, Math.min(orig.getMaxStackSize(), orig.stackSize+toAdd.stackSize));
|
||||
}
|
||||
|
||||
public static ItemStack getMergeReject(ItemStack orig, ItemStack toAdd)
|
||||
{
|
||||
if(orig == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(toAdd == null)
|
||||
{
|
||||
return orig;
|
||||
}
|
||||
|
||||
if(!orig.isItemEqual(toAdd) || !ItemStack.areItemStackTagsEqual(orig, toAdd))
|
||||
{
|
||||
return orig;
|
||||
}
|
||||
|
||||
int newSize = orig.stackSize+toAdd.stackSize;
|
||||
|
||||
if(newSize > orig.getMaxStackSize())
|
||||
{
|
||||
return StackUtils.size(orig, newSize-orig.getMaxStackSize());
|
||||
}
|
||||
else {
|
||||
return StackUtils.size(orig, newSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,13 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.util.StackUtils;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.MekanismBlocks;
|
||||
import mekanism.common.multiblock.MultiblockManager;
|
||||
import mekanism.common.tank.SynchronizedTankData.ValveData;
|
||||
import mekanism.common.tile.TileEntityDynamicTank;
|
||||
import mekanism.common.tile.TileEntityDynamicValve;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
@@ -396,6 +397,7 @@ public class TankUpdateProtocol
|
||||
}
|
||||
|
||||
DynamicTankCache cache = new DynamicTankCache();
|
||||
List<ItemStack> rejectedItems = new ArrayList<ItemStack>();
|
||||
|
||||
if(!idsFound.isEmpty())
|
||||
{
|
||||
@@ -403,9 +405,33 @@ public class TankUpdateProtocol
|
||||
{
|
||||
if(Mekanism.tankManager.inventories.get(id) != null)
|
||||
{
|
||||
cache = (DynamicTankCache)Mekanism.tankManager.pullInventory(pointer.getWorldObj(), id);
|
||||
if(cache == null)
|
||||
{
|
||||
cache = (DynamicTankCache)Mekanism.tankManager.pullInventory(pointer.getWorldObj(), id);
|
||||
}
|
||||
else {
|
||||
DynamicTankCache merge = (DynamicTankCache)Mekanism.tankManager.pullInventory(pointer.getWorldObj(), id);
|
||||
|
||||
if(cache.fluid == null)
|
||||
{
|
||||
cache.fluid = merge.fluid;
|
||||
}
|
||||
else if(merge.fluid != null && cache.fluid.isFluidEqual(merge.fluid))
|
||||
{
|
||||
cache.fluid.amount += merge.fluid.amount;
|
||||
}
|
||||
|
||||
List<ItemStack> rejects = StackUtils.getMergeRejects(cache.inventory, merge.inventory);
|
||||
|
||||
if(!rejects.isEmpty())
|
||||
{
|
||||
rejectedItems.addAll(rejects);
|
||||
}
|
||||
|
||||
StackUtils.merge(cache.inventory, merge.inventory);
|
||||
}
|
||||
|
||||
idToUse = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user