Skip to content

Commit cf67b85

Browse files
committed
Merge remote-tracking branch 'origin/levelmaintainer-memorycard' into dev
2 parents 38a1889 + b28110e commit cf67b85

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

src/main/java/com/glodblock/github/common/tile/TileLevelMaintainer.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import appeng.tile.grid.AENetworkTile;
6060
import appeng.tile.inventory.IAEAppEngInventory;
6161
import appeng.tile.inventory.InvOperation;
62+
import appeng.util.SettingsFrom;
6263
import appeng.util.item.AEItemStack;
6364
import io.netty.buffer.ByteBuf;
6465

@@ -101,10 +102,7 @@ public ImmutableSet<ICraftingLink> getRequestedJobs() {
101102
@Override
102103
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
103104
int idx = this.getRequestIndexByLink(link);
104-
if (idx == -1) {
105-
AELog.warn("Invalid crafting link: " + link);
106-
return items;
107-
}
105+
108106
try {
109107
if (getProxy().isActive()) {
110108
final IEnergyGrid energy = getProxy().getEnergy();
@@ -116,7 +114,9 @@ public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, A
116114
.injectItems(ItemFluidDrop.getAeFluidStack(items), mode, source);
117115
if (notInjectedItems != null) {
118116
items.setStackSize(notInjectedItems.getStackSize());
119-
this.updateState(idx, LevelState.Export);
117+
if (idx != -1) {
118+
this.updateState(idx, LevelState.Export);
119+
}
120120

121121
return items;
122122
} else {
@@ -430,7 +430,7 @@ public void writeToNBTEvent(NBTTagCompound data) {
430430
NBTTagList tagList = new NBTTagList();
431431
for (int i = 0; i < REQ_COUNT; i++) {
432432
if (this.requests[i] != null) {
433-
tagList.appendTag(this.requests[i].writeToNBT());
433+
tagList.appendTag(this.requests[i].writeToNBT(true));
434434
} else {
435435
tagList.appendTag(new NBTTagCompound());
436436
}
@@ -544,6 +544,42 @@ public void writeToStream(final ByteBuf data) {
544544
data.writeBoolean(isActive());
545545
}
546546

547+
@Override
548+
public void uploadSettings(SettingsFrom from, NBTTagCompound compound) {
549+
super.uploadSettings(from, compound);
550+
NBTTagList tagList = compound.getTagList(NBT_REQUESTS, Constants.NBT.TAG_COMPOUND);
551+
for (int i = 0; i < tagList.tagCount(); i++) {
552+
NBTTagCompound tag = tagList.getCompoundTagAt(i);
553+
if (tag == null || !tag.hasKey(NBT_STACK)) {
554+
this.requests[i] = null;
555+
} else {
556+
try {
557+
this.requests[i] = new RequestInfo(tag, this);
558+
this.requests[i].state = LevelState.None;
559+
} catch (Exception ignored) {
560+
this.requests[i] = null;
561+
}
562+
}
563+
}
564+
this.saveChanges();
565+
}
566+
567+
@Override
568+
public NBTTagCompound downloadSettings(SettingsFrom from) {
569+
NBTTagCompound compound = super.downloadSettings(from);
570+
compound = compound == null ? new NBTTagCompound() : compound;
571+
NBTTagList tagList = new NBTTagList();
572+
for (int i = 0; i < REQ_COUNT; i++) {
573+
if (this.requests[i] != null) {
574+
tagList.appendTag(this.requests[i].writeToNBT(false));
575+
} else {
576+
tagList.appendTag(new NBTTagCompound());
577+
}
578+
}
579+
compound.setTag(NBT_REQUESTS, tagList);
580+
return compound;
581+
}
582+
547583
@MENetworkEventSubscribe
548584
public void stateChange(final MENetworkPowerStatusChange p) {
549585
updatePowerState();
@@ -643,7 +679,7 @@ public void loadFromNBT(NBTTagCompound tag) {
643679
}
644680
}
645681

646-
public NBTTagCompound writeToNBT() {
682+
public NBTTagCompound writeToNBT(boolean includeLink) {
647683
NBTTagCompound tag = new NBTTagCompound();
648684
NBTTagCompound stackTag = new NBTTagCompound();
649685
itemStack.writeToNBT(stackTag);
@@ -652,7 +688,7 @@ public NBTTagCompound writeToNBT() {
652688
tag.setLong(NBT_BATCH, batchSize);
653689
tag.setBoolean(NBT_ENABLE, enable);
654690
tag.setInteger(NBT_STATE, state.ordinal());
655-
if (this.link != null) {
691+
if (this.link != null && includeLink) {
656692
NBTTagCompound linkTag = new NBTTagCompound();
657693
this.link.writeToNBT(linkTag);
658694
tag.setTag(NBT_LINK, linkTag);

0 commit comments

Comments
 (0)