Merge remote-tracking branch 'origin/levelmaintainer-memorycard' into dev

This commit is contained in:
Dream Master committed 2025-08-08 23:14:43 +07:00
commit cf67b855bc
1 file changed
+44 -8
@@ -59,6 +59,7 @@ import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkTile;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.SettingsFrom;
import appeng.util.item.AEItemStack;
import io.netty.buffer.ByteBuf;
@@ -101,10 +102,7 @@ public class TileLevelMaintainer extends AENetworkTile
@Override
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
int idx = this.getRequestIndexByLink(link);
if (idx == -1) {
AELog.warn("Invalid crafting link: " + link);
return items;
}
try {
if (getProxy().isActive()) {
final IEnergyGrid energy = getProxy().getEnergy();
@@ -116,7 +114,9 @@ public class TileLevelMaintainer extends AENetworkTile
.injectItems(ItemFluidDrop.getAeFluidStack(items), mode, source);
if (notInjectedItems != null) {
items.setStackSize(notInjectedItems.getStackSize());
this.updateState(idx, LevelState.Export);
if (idx != -1) {
this.updateState(idx, LevelState.Export);
}
return items;
} else {
@@ -430,7 +430,7 @@ public class TileLevelMaintainer extends AENetworkTile
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < REQ_COUNT; i++) {
if (this.requests[i] != null) {
tagList.appendTag(this.requests[i].writeToNBT());
tagList.appendTag(this.requests[i].writeToNBT(true));
} else {
tagList.appendTag(new NBTTagCompound());
}
@@ -544,6 +544,42 @@ public class TileLevelMaintainer extends AENetworkTile
data.writeBoolean(isActive());
}
@Override
public void uploadSettings(SettingsFrom from, NBTTagCompound compound) {
super.uploadSettings(from, compound);
NBTTagList tagList = compound.getTagList(NBT_REQUESTS, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound tag = tagList.getCompoundTagAt(i);
if (tag == null || !tag.hasKey(NBT_STACK)) {
this.requests[i] = null;
} else {
try {
this.requests[i] = new RequestInfo(tag, this);
this.requests[i].state = LevelState.None;
} catch (Exception ignored) {
this.requests[i] = null;
}
}
}
this.saveChanges();
}
@Override
public NBTTagCompound downloadSettings(SettingsFrom from) {
NBTTagCompound compound = super.downloadSettings(from);
compound = compound == null ? new NBTTagCompound() : compound;
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < REQ_COUNT; i++) {
if (this.requests[i] != null) {
tagList.appendTag(this.requests[i].writeToNBT(false));
} else {
tagList.appendTag(new NBTTagCompound());
}
}
compound.setTag(NBT_REQUESTS, tagList);
return compound;
}
@MENetworkEventSubscribe
public void stateChange(final MENetworkPowerStatusChange p) {
updatePowerState();
@@ -643,7 +679,7 @@ public class TileLevelMaintainer extends AENetworkTile
}
}
public NBTTagCompound writeToNBT() {
public NBTTagCompound writeToNBT(boolean includeLink) {
NBTTagCompound tag = new NBTTagCompound();
NBTTagCompound stackTag = new NBTTagCompound();
itemStack.writeToNBT(stackTag);
@@ -652,7 +688,7 @@ public class TileLevelMaintainer extends AENetworkTile
tag.setLong(NBT_BATCH, batchSize);
tag.setBoolean(NBT_ENABLE, enable);
tag.setInteger(NBT_STATE, state.ordinal());
if (this.link != null) {
if (this.link != null && includeLink) {
NBTTagCompound linkTag = new NBTTagCompound();
this.link.writeToNBT(linkTag);
tag.setTag(NBT_LINK, linkTag);