Skip to content

Commit

Permalink
Merge pull request #23 from GTNewHorizons/fix
Browse files Browse the repository at this point in the history
fix wrong bytes display when ingrentent isn't enough and a possible d…
  • Loading branch information
Dream-Master authored Oct 7, 2022
2 parents 587fd70 + 47dce05 commit d8140da
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 32 deletions.
16 changes: 8 additions & 8 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

dependencies {
compile('com.github.GTNewHorizons:NotEnoughItems:2.2.17-GTNH:dev')
compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-108-GTNH:dev')
compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-109-GTNH:dev')
compile('curse.maven:cofh-core-69162:2388751')
compile('com.github.GTNewHorizons:ExtraCells2:2.5.20:dev') {transitive = false}
compile("com.github.GTNewHorizons:WirelessCraftingTerminal:1.8.8.5:dev")

compileOnly("com.github.GTNewHorizons:ForestryMC:4.4.7:dev")
compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.27:dev")
compileOnly("com.github.GTNewHorizons:EnderCore:0.2.6:dev")
compileOnly('com.github.GTNewHorizons:ForestryMC:4.4.7:dev')
compileOnly('com.github.GTNewHorizons:EnderIO:2.3.1.27:dev')
compileOnly('com.github.GTNewHorizons:EnderCore:0.2.6:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.40.41:dev')
compileOnly('com.github.GTNewHorizons:StructureLib:1.0.15:dev')
compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev')
compileOnly('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev')
compileOnly('com.github.GTNewHorizons:AppleCore:3.1.9:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.27:dev') {transitive = false}
compileOnly("com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev") {transitive = false}
compileOnly('com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:OpenComputers:1.7.5.23-GTNH:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.3.19-GTNH:dev') {transitive = false}
compileOnly("com.github.GTNewHorizons:EnderIO:2.3.1.29:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:GTplusplus:1.7.49:dev") {transitive = false}
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")
runtime('com.github.GTNewHorizons:Baubles:1.0.1.14:dev')
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ private void encodeFluidPattern() {
ItemStack patternStack = new ItemStack(ItemAndBlockHolder.PATTERN);
FluidPatternDetails pattern = new FluidPatternDetails(patternStack);
pattern.setCombine(this.combine ? 1:0);
pattern.setPriority(this.prioritize? 1:0);
pattern.setInputs(collectInventory(craftingSlots));
pattern.setOutputs(collectInventory(outputSlots));
patternSlotOUT.putStack(pattern.writeToStack());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,22 @@ public ItemFluidEncodedPattern register() {
GameRegistry.registerItem(this, NameConst.ITEM_FLUID_ENCODED_PATTERN, FluidCraft.MODID);
return this;
}

@Override
public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List<String> lines, final boolean displayMoreInfo )
{
NBTTagCompound data = stack.getTagCompound();
final boolean combine = data.getBoolean("combine");
final boolean prio = data.getBoolean("prioritize");
super.addCheckedInformation(stack,player,lines,displayMoreInfo);
super.addCheckedInformation(stack, player, lines, displayMoreInfo);
// lines.add(String.format("%s: %s",combine ? StatCollector.translateToLocal(NameConst.TT_KEY+"combine"):StatCollector.translateToLocal(NameConst.TT_KEY+"not_combine"),combine ? GuiText.Yes.getLocal() : GuiText.No.getLocal()));
// lines.add(String.format("%s: %s",prio ? StatCollector.translateToLocal(NameConst.TT_KEY+"prio"):StatCollector.translateToLocal(NameConst.TT_KEY+"not_prio"),prio ? GuiText.Yes.getLocal() : GuiText.No.getLocal()));
}

public ItemStack stack() {
return new ItemStack(this, 1);
}

public ItemStack stack(int size) {
return new ItemStack(this, size);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall)
inventory.setInventorySlotContents(0, null);
return TickRateModulation.SLEEP;
}
IAEFluidStack aeFluid = AEFluidStack.create(fluid);
IAEFluidStack aeFluid = AEFluidStack.create(fluid.copy());
IEnergyGrid energyGrid = node.getGrid().getCache(IEnergyGrid.class);
IMEMonitor<IAEFluidStack> fluidGrid = node.getGrid().<IStorageGrid>getCache(IStorageGrid.class).getFluidInventory();
IAEFluidStack remaining = Platform.poweredInsert(energyGrid, fluidGrid, aeFluid, ownActionSource);
if (remaining != null) {
if (remaining.getStackSize() == aeFluid.getStackSize()) {
inventory.setInventorySlotContents(0, ItemFluidPacket.newStack(remaining.getFluidStack()));
return TickRateModulation.SLOWER;
}
inventory.setInventorySlotContents(0, ItemFluidPacket.newStack(remaining.getFluidStack()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public static long getCraftingByteCost(IAEItemStack stack) {
? (long) Math.ceil(stack.getStackSize() / 1000D) : stack.getStackSize();
}

public static long getFluidDropsByteCost(long totalBytes, long originByte, IAEItemStack stack) {
if (stack != null && stack.getItem() instanceof ItemFluidDrop) {
return (long) Math.ceil(originByte / 1000D) + totalBytes;
}
return originByte + totalBytes;
}

public static IAEItemStack[] flattenFluidPackets(IAEItemStack[] stacks) {
for (int i = 0; i < stacks.length; i++) {
if (stacks[i].getItem() instanceof ItemFluidPacket) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
private static class TransformRequest extends MethodVisitor {

private boolean writingBytes = false;
private int cnt = 0;

TransformRequest(int api, MethodVisitor mv) {
super(api, mv);
Expand All @@ -62,6 +63,7 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
if (writingBytes && opcode == Opcodes.INVOKEINTERFACE
&& owner.equals("appeng/api/storage/data/IAEItemStack") && name.equals("getStackSize")) {
writingBytes = false;
cnt ++;
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"getCraftingByteCost",
Expand All @@ -72,6 +74,27 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
}
}

@Override
public void visitInsn(int opcode) {
if (writingBytes && cnt == 5 && opcode == Opcodes.LADD) {
super.visitVarInsn(Opcodes.ALOAD, 0);
super.visitFieldInsn(Opcodes.GETFIELD,
"appeng/crafting/CraftingTreeNode",
"what",
"Lappeng/api/storage/data/IAEItemStack;"
);
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"com/glodblock/github/coremod/hooker/CoreModHooks",
"getFluidDropsByteCost",
"(JJLappeng/api/storage/data/IAEItemStack;)J",
false);
writingBytes = false;
cnt ++;
return;
}
super.visitInsn(opcode);
}

}

}
32 changes: 11 additions & 21 deletions src/main/java/com/glodblock/github/util/FluidPatternDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.helpers.PatternHelper;
import appeng.util.item.AEItemStack;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
Expand All @@ -12,8 +13,6 @@

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class FluidPatternDetails implements ICraftingPatternDetails, Comparable<FluidPatternDetails>{
Expand Down Expand Up @@ -43,8 +42,14 @@ public int getPriority() {
public void setPriority(int priority) {
this.priority = priority;
}
public void setCombine(int combine){ this.combine = combine;}
public int getCombine(){return combine;}

public void setCombine(int combine) {
this.combine = combine;
}

public int getCombine() {
return combine;
}

@Override
public boolean isCraftable() {
Expand Down Expand Up @@ -99,20 +104,7 @@ public boolean setOutputs(IAEItemStack[] outputs) {
}

private static IAEItemStack[] condenseStacks(IAEItemStack[] stacks) {
// AE item stacks are equivalent iff they are of the same item type (not accounting for stack size)
// thus, it's not the semantically-correct definition of "equal" but it's useful for matching item types
Map<IAEItemStack, IAEItemStack> accMap = new HashMap<>();
for (IAEItemStack stack : stacks) {
if (stack != null) {
IAEItemStack acc = accMap.get(stack);
if (acc == null) {
accMap.put(stack, stack.copy());
} else {
acc.add(stack);
}
}
}
return accMap.values().toArray(new IAEItemStack[0]);
return PatternHelper.convertToCondensedList(stacks);
}

@Override
Expand Down Expand Up @@ -157,8 +149,7 @@ public ItemStack writeToStack() {
//Shits
tag.setTag("in", writeStackArray(checkInitialized(inputs)));
tag.setTag("out", writeStackArray(checkInitialized(outputs)));
tag.setInteger("prioritize",this.getPriority());
tag.setInteger("combine",this.getCombine());
tag.setInteger("combine", this.getCombine());
patternStack.setTagCompound(tag);
patternStackAe = Objects.requireNonNull(AEItemStack.create(patternStack));
return patternStack;
Expand All @@ -170,7 +161,6 @@ public static NBTTagList writeStackArray(IAEItemStack[] stacks) {
// see note at top of class
NBTTagCompound stackTag = new NBTTagCompound();
if (stack != null) stack.writeToNBT(stackTag);

listTag.appendTag(stackTag);
}
return listTag;
Expand Down

0 comments on commit d8140da

Please sign in to comment.