forked from AE2-UEL/AE2FluidCraft-Rework
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete crafting jobs on networks without discretizer
- Loading branch information
Showing
4 changed files
with
162 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/com/glodblock/github/coremod/transform/CraftingGridCacheTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.glodblock.github.coremod.transform; | ||
|
||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.Opcodes; | ||
|
||
import com.glodblock.github.coremod.FCClassTransformer; | ||
|
||
public class CraftingGridCacheTransformer extends FCClassTransformer.ClassMapper { | ||
|
||
public static final CraftingGridCacheTransformer INSTANCE = new CraftingGridCacheTransformer(); | ||
|
||
private CraftingGridCacheTransformer() { | ||
// NO-OP | ||
} | ||
|
||
@Override | ||
protected ClassVisitor getClassMapper(ClassVisitor downstream) { | ||
return new CraftingGridCacheTransformer.TransformCraftingGridCache(Opcodes.ASM5, downstream); | ||
} | ||
|
||
private static class TransformCraftingGridCache extends ClassVisitor { | ||
|
||
TransformCraftingGridCache(int api, ClassVisitor cv) { | ||
super(api, cv); | ||
} | ||
|
||
@Override | ||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { | ||
if (name.equals("getCellArray")) { | ||
return new CraftingGridCacheTransformer.ReplaceGetCellArray( | ||
api, | ||
super.visitMethod(access, name, desc, signature, exceptions)); | ||
} | ||
return super.visitMethod(access, name, desc, signature, exceptions); | ||
} | ||
} | ||
|
||
private static class ReplaceGetCellArray extends MethodVisitor { | ||
|
||
private final MethodVisitor target; | ||
|
||
ReplaceGetCellArray(int api, MethodVisitor mv) { | ||
// Original method is replaced | ||
super(api, null); | ||
target = mv; | ||
} | ||
|
||
@Override | ||
public void visitCode() { | ||
target.visitCode(); | ||
// Equivalent to | ||
// return CoreModHooks::craftingGridCacheGetCellArray(this, channel); | ||
target.visitVarInsn(Opcodes.ALOAD, 0); | ||
target.visitVarInsn(Opcodes.ALOAD, 1); | ||
target.visitMethodInsn( | ||
Opcodes.INVOKESTATIC, | ||
"com/glodblock/github/coremod/hooker/CoreModHooks", | ||
"craftingGridCacheGetCellArray", | ||
"(Lappeng/me/cache/CraftingGridCache;Lappeng/api/storage/StorageChannel;)Ljava/util/List;", | ||
false); | ||
target.visitInsn(Opcodes.ARETURN); | ||
target.visitMaxs(2, 3); | ||
target.visitEnd(); | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/glodblock/github/inventory/CraftingGridCacheFluidInventoryProxyCell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.glodblock.github.inventory; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.glodblock.github.common.item.ItemFluidDrop; | ||
|
||
import appeng.api.config.AccessRestriction; | ||
import appeng.api.config.Actionable; | ||
import appeng.api.networking.security.BaseActionSource; | ||
import appeng.api.storage.IMEInventoryHandler; | ||
import appeng.api.storage.StorageChannel; | ||
import appeng.api.storage.data.IAEFluidStack; | ||
import appeng.api.storage.data.IAEItemStack; | ||
import appeng.api.storage.data.IItemList; | ||
import appeng.me.cache.CraftingGridCache; | ||
|
||
public class CraftingGridCacheFluidInventoryProxyCell implements IMEInventoryHandler<IAEFluidStack> { | ||
|
||
private final CraftingGridCache inner; | ||
|
||
public CraftingGridCacheFluidInventoryProxyCell(final CraftingGridCache craftingGridCache) { | ||
inner = craftingGridCache; | ||
} | ||
|
||
@Override | ||
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, BaseActionSource src) { | ||
return ItemFluidDrop | ||
.getAeFluidStack((IAEItemStack) inner.injectItems(ItemFluidDrop.newAeStack(input), type, src)); | ||
} | ||
|
||
@Override | ||
public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, BaseActionSource src) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out, int iteration) { | ||
return out; | ||
} | ||
|
||
@Override | ||
public IAEFluidStack getAvailableItem(@NotNull IAEFluidStack request, int iteration) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public StorageChannel getChannel() { | ||
return StorageChannel.FLUIDS; | ||
} | ||
|
||
@Override | ||
public AccessRestriction getAccess() { | ||
return inner.getAccess(); | ||
} | ||
|
||
@Override | ||
public boolean isPrioritized(IAEFluidStack input) { | ||
return inner.isPrioritized(input); | ||
} | ||
|
||
@Override | ||
public boolean canAccept(IAEFluidStack input) { | ||
return inner.canAccept(ItemFluidDrop.newAeStack(input)); | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return inner.getPriority(); | ||
} | ||
|
||
@Override | ||
public int getSlot() { | ||
return inner.getSlot(); | ||
} | ||
|
||
@Override | ||
public boolean validForPass(int i) { | ||
return inner.validForPass(i); | ||
} | ||
} |