mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-11 15:57:55 +00:00
Merge pull request #6 from GlodBlock/bugfix
fix drops leak to item cell when discretizer go offline
This commit is contained in:
5 files changed
+131
-20
No files matched your search
@@ -22,6 +22,5 @@ dependencies {
|
||||
compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.29:dev") {transitive = false}
|
||||
compileOnly("com.github.GTNewHorizons:GTplusplus:1.7.49:dev") {transitive = false}
|
||||
|
||||
|
||||
runtime("com.github.GTNewHorizons:Baubles:1.0.1.14:dev")
|
||||
}
|
||||
@@ -129,25 +129,6 @@ public class TileFluidDiscretizer extends AENetworkTile implements IPriorityHost
|
||||
updateState();
|
||||
}
|
||||
|
||||
/*@MENetworkEventSubscribe
|
||||
public void onBootUp(MENetworkBootingStatusChange event) {
|
||||
try {
|
||||
IMEInventory<IAEItemStack> inventory = this.getProxy().getStorage().getItemInventory();
|
||||
IItemList<IAEItemStack> items = inventory.getAvailableItems(AEApi.instance().storage().createItemList());
|
||||
IItemList<IAEItemStack> drops = AEApi.instance().storage().createItemList();
|
||||
for (IAEItemStack item : items) {
|
||||
if (item != null && item.getItem() instanceof ItemFluidDrop) {
|
||||
drops.add(item);
|
||||
}
|
||||
}
|
||||
for (IAEItemStack drop : drops) {
|
||||
inventory.extractItems(drop, Actionable.MODULATE, ownActionSource);
|
||||
inventory.injectItems(drop, Actionable.MODULATE, ownActionSource);
|
||||
}
|
||||
} catch (GridAccessException ignored) {
|
||||
}
|
||||
}*/
|
||||
|
||||
private class FluidDiscretizingInventory implements IMEInventory<IAEItemStack>, IMEMonitorHandlerReceiver<IAEFluidStack> {
|
||||
|
||||
private final MEInventoryHandler<IAEItemStack> invHandler = new MEInventoryHandler<>(this, getChannel());
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package com.glodblock.github.coremod.hooker;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.IMachineSet;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.crafting.MECraftingInventory;
|
||||
import appeng.me.MachineSet;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.parts.misc.PartInterface;
|
||||
import appeng.tile.misc.TileInterface;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
@@ -16,6 +22,7 @@ import com.glodblock.github.common.tile.TileFluidInterface;
|
||||
import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor;
|
||||
import com.glodblock.github.inventory.FluidConvertingInventoryCrafting;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import com.glodblock.github.util.Ae2Reflect;
|
||||
import com.glodblock.github.util.SetBackedMachineSet;
|
||||
import com.glodblock.github.util.Util;
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -104,4 +111,51 @@ public class CoreModHooks {
|
||||
else return aeStack.getStackSize();
|
||||
}
|
||||
|
||||
public static void storeFluidItem(CraftingCPUCluster instance) {
|
||||
final IGrid g = Ae2Reflect.getGrid(instance);
|
||||
|
||||
if( g == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final IStorageGrid sg = g.getCache( IStorageGrid.class );
|
||||
final IMEInventory<IAEItemStack> ii = sg.getItemInventory();
|
||||
final IMEInventory<IAEFluidStack> jj = sg.getFluidInventory();
|
||||
final MECraftingInventory inventory = Ae2Reflect.getCPUInventory(instance);
|
||||
|
||||
for( IAEItemStack is : inventory.getItemList() )
|
||||
{
|
||||
is = inventory.extractItems( is.copy(), Actionable.MODULATE, Ae2Reflect.getCPUSource(instance) );
|
||||
|
||||
if( is != null )
|
||||
{
|
||||
Ae2Reflect.postCPUChange(instance, is, Ae2Reflect.getCPUSource(instance));
|
||||
if (is.getItem() instanceof ItemFluidDrop) {
|
||||
IAEFluidStack fluidDrop = ItemFluidDrop.getAeFluidStack(is);
|
||||
fluidDrop = jj.injectItems(fluidDrop, Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
|
||||
if (fluidDrop == null) {
|
||||
is = null;
|
||||
} else {
|
||||
is.setStackSize(fluidDrop.getStackSize());
|
||||
}
|
||||
} else {
|
||||
is = ii.injectItems(is, Actionable.MODULATE, Ae2Reflect.getCPUSource(instance));
|
||||
}
|
||||
}
|
||||
|
||||
if( is != null )
|
||||
{
|
||||
inventory.injectItems( is, Actionable.MODULATE, Ae2Reflect.getCPUSource(instance) );
|
||||
}
|
||||
}
|
||||
|
||||
if( inventory.getItemList().isEmpty() )
|
||||
{
|
||||
Ae2Reflect.setCPUInventory(instance, new MECraftingInventory());
|
||||
}
|
||||
|
||||
Ae2Reflect.markCPUDirty(instance);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,6 +29,8 @@ public class CraftingCpuTransformer extends FCClassTransformer.ClassMapper {
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
if (name.equals("executeCrafting")) {
|
||||
return new TransformExecuteCrafting(api, super.visitMethod(access, name, desc, signature, exceptions));
|
||||
} else if (name.equals("cancel")) {
|
||||
return new TransformStoreItems(api, super.visitMethod(access, name, desc, signature, exceptions));
|
||||
}
|
||||
return super.visitMethod(access, name, desc, signature, exceptions);
|
||||
}
|
||||
@@ -104,4 +106,27 @@ public class CraftingCpuTransformer extends FCClassTransformer.ClassMapper {
|
||||
|
||||
}
|
||||
|
||||
private static class TransformStoreItems extends MethodVisitor {
|
||||
|
||||
TransformStoreItems(int api, MethodVisitor mv) {
|
||||
super(api, mv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
|
||||
if (opcode == Opcodes.INVOKESPECIAL
|
||||
&& owner.equals("appeng/me/cluster/implementations/CraftingCPUCluster") && name.equals("storeItems")) {
|
||||
super.visitMethodInsn(Opcodes.INVOKESTATIC,
|
||||
"com/glodblock/github/coremod/hooker/CoreModHooks",
|
||||
"storeFluidItem",
|
||||
"(Lappeng/me/cluster/implementations/CraftingCPUCluster;)V",
|
||||
false
|
||||
);
|
||||
} else {
|
||||
super.visitMethodInsn(opcode, owner, name, desc, itf);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
package com.glodblock.github.util;
|
||||
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.crafting.ICraftingCPU;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.container.implementations.ContainerUpgradeable;
|
||||
import appeng.container.implementations.CraftingCPURecord;
|
||||
import appeng.crafting.MECraftingInventory;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.me.storage.MEPassThrough;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
@@ -23,7 +29,12 @@ public class Ae2Reflect {
|
||||
private static final Field fCPU_myName;
|
||||
private static final Field fCPU_processors;
|
||||
private static final Field fCPU_size;
|
||||
private static final Field fCPU_inventory;
|
||||
private static final Field fCPU_machineSrc;
|
||||
private static final Method mItemSlot_setExtractable;
|
||||
private static final Method mCPU_getGrid;
|
||||
private static final Method mCPU_postChange;
|
||||
private static final Method mCPU_markDirty;
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -34,7 +45,12 @@ public class Ae2Reflect {
|
||||
fCPU_myName = Ae2Reflect.reflectField(CraftingCPURecord.class, "myName");
|
||||
fCPU_processors = Ae2Reflect.reflectField(CraftingCPURecord.class, "processors");
|
||||
fCPU_size = Ae2Reflect.reflectField(CraftingCPURecord.class, "size");
|
||||
fCPU_inventory = Ae2Reflect.reflectField(CraftingCPUCluster.class, "inventory");
|
||||
fCPU_machineSrc = Ae2Reflect.reflectField(CraftingCPUCluster.class, "machineSrc");
|
||||
mItemSlot_setExtractable = reflectMethod(ItemSlot.class, "setExtractable", boolean.class);
|
||||
mCPU_getGrid = reflectMethod(CraftingCPUCluster.class, "getGrid");
|
||||
mCPU_postChange = reflectMethod(CraftingCPUCluster.class, "postChange", IAEItemStack.class, BaseActionSource.class);
|
||||
mCPU_markDirty = reflectMethod(CraftingCPUCluster.class, "markDirty");
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to initialize AE2 reflection hacks!", e);
|
||||
}
|
||||
@@ -114,4 +130,40 @@ public class Ae2Reflect {
|
||||
return Ae2Reflect.readField(container, fInventory_containerUpgrade);
|
||||
}
|
||||
|
||||
public static IGrid getGrid(CraftingCPUCluster cpu) {
|
||||
try {
|
||||
return (IGrid) mCPU_getGrid.invoke(cpu);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + mCPU_getGrid, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static MECraftingInventory getCPUInventory(CraftingCPUCluster cpu) {
|
||||
return Ae2Reflect.readField(cpu, fCPU_inventory);
|
||||
}
|
||||
|
||||
public static void setCPUInventory(CraftingCPUCluster cpu, MECraftingInventory value) {
|
||||
Ae2Reflect.writeField(cpu, fCPU_inventory, value);
|
||||
}
|
||||
|
||||
public static MachineSource getCPUSource(CraftingCPUCluster cpu) {
|
||||
return Ae2Reflect.readField(cpu, fCPU_machineSrc);
|
||||
}
|
||||
|
||||
public static void postCPUChange(CraftingCPUCluster cpu, IAEItemStack stack, MachineSource src) {
|
||||
try {
|
||||
mCPU_postChange.invoke(cpu, stack, src);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + mCPU_postChange, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void markCPUDirty(CraftingCPUCluster cpu) {
|
||||
try {
|
||||
mCPU_markDirty.invoke(cpu);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to invoke method: " + mCPU_markDirty, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user