Fix generated method reporting 0 stack limit when initialising (#333)
This commit is contained in:
parent
da0a382beb
commit
e877d3a391
|
@ -33,7 +33,7 @@ public abstract class InventoryMixin implements Container, IInventoryBridge, Pla
|
|||
// @formatter:on
|
||||
|
||||
public List<HumanEntity> transaction = new ArrayList<>();
|
||||
private int maxStack = MAX_STACK;
|
||||
private int maxStack = -1;
|
||||
|
||||
public int canHold(ItemStack stack) {
|
||||
int remains = stack.getCount();
|
||||
|
@ -98,8 +98,10 @@ public abstract class InventoryMixin implements Container, IInventoryBridge, Pla
|
|||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
if (maxStack == 0) maxStack = MAX_STACK;
|
||||
return maxStack;
|
||||
if (maxStack != -1) {
|
||||
return maxStack;
|
||||
}
|
||||
return Container.super.getMaxStackSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -122,9 +122,9 @@ public class InventoryImplementer implements Implementer {
|
|||
node.interfaces.add(BRIDGE_TYPE);
|
||||
return false;
|
||||
} else {
|
||||
ArclightImplementer.LOGGER.debug(MARKER, "Implementing inventory for class {}", node.name);
|
||||
ArclightImplementer.LOGGER.debug(MARKER, "Implementing inventory for class {} in {}", node.name, map.get(node.name));
|
||||
FieldNode transaction = new FieldNode(Opcodes.ACC_PRIVATE, "$transaction", Type.getType(List.class).getDescriptor(), null, null);
|
||||
FieldNode maxStack = new FieldNode(Opcodes.ACC_PRIVATE, "$maxStack", "I", null, null);
|
||||
FieldNode maxStack = new FieldNode(Opcodes.ACC_PRIVATE, "$maxStack", Type.getType(Integer.class).getDescriptor(), null, null);
|
||||
node.fields.add(transaction);
|
||||
node.fields.add(maxStack);
|
||||
node.interfaces.add(BRIDGE_TYPE);
|
||||
|
@ -165,12 +165,12 @@ public class InventoryImplementer implements Implementer {
|
|||
LabelNode labelNode = new LabelNode();
|
||||
list.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
list.add(new FieldInsnNode(Opcodes.GETFIELD, node.name, maxStack.name, maxStack.desc));
|
||||
list.add(new InsnNode(Opcodes.ICONST_M1));
|
||||
list.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, labelNode));
|
||||
list.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
list.add(new FieldInsnNode(Opcodes.GETFIELD, node.name, maxStack.name, maxStack.desc));
|
||||
list.add(new InsnNode(Opcodes.DUP));
|
||||
list.add(new JumpInsnNode(Opcodes.IFNULL, labelNode));
|
||||
list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Integer.class), "intValue", "()I", false));
|
||||
list.add(new InsnNode(Opcodes.IRETURN));
|
||||
list.add(labelNode);
|
||||
list.add(new InsnNode(Opcodes.POP));
|
||||
if (stackLimitMethod != null && !Modifier.isAbstract(stackLimitMethod.access)) {
|
||||
stackLimitMethod.instructions.insert(list);
|
||||
} else {
|
||||
|
@ -194,6 +194,7 @@ public class InventoryImplementer implements Implementer {
|
|||
InsnList insnList = new InsnList();
|
||||
insnList.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
insnList.add(new VarInsnNode(Opcodes.ILOAD, 1));
|
||||
insnList.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf", Type.getMethodDescriptor(Type.getType(Integer.class), Type.INT_TYPE)));
|
||||
insnList.add(new FieldInsnNode(Opcodes.PUTFIELD, node.name, maxStack.name, maxStack.desc));
|
||||
insnList.add(new InsnNode(Opcodes.RETURN));
|
||||
methodNode.instructions = insnList;
|
||||
|
@ -212,9 +213,6 @@ public class InventoryImplementer implements Implementer {
|
|||
insnList.add(new InsnNode(Opcodes.DUP));
|
||||
insnList.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Type.getInternalName(ArrayList.class), "<init>", "()V", false));
|
||||
insnList.add(new FieldInsnNode(Opcodes.PUTFIELD, node.name, transaction.name, transaction.desc));
|
||||
insnList.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||
insnList.add(new InsnNode(Opcodes.ICONST_M1));
|
||||
insnList.add(new FieldInsnNode(Opcodes.PUTFIELD, node.name, maxStack.name, maxStack.desc));
|
||||
methodNode.instructions.insert(initNode, insnList);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user