59
59
import appeng .tile .grid .AENetworkTile ;
60
60
import appeng .tile .inventory .IAEAppEngInventory ;
61
61
import appeng .tile .inventory .InvOperation ;
62
+ import appeng .util .SettingsFrom ;
62
63
import appeng .util .item .AEItemStack ;
63
64
import io .netty .buffer .ByteBuf ;
64
65
@@ -101,10 +102,7 @@ public ImmutableSet<ICraftingLink> getRequestedJobs() {
101
102
@ Override
102
103
public IAEItemStack injectCraftedItems (ICraftingLink link , IAEItemStack items , Actionable mode ) {
103
104
int idx = this .getRequestIndexByLink (link );
104
- if (idx == -1 ) {
105
- AELog .warn ("Invalid crafting link: " + link );
106
- return items ;
107
- }
105
+
108
106
try {
109
107
if (getProxy ().isActive ()) {
110
108
final IEnergyGrid energy = getProxy ().getEnergy ();
@@ -116,7 +114,9 @@ public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, A
116
114
.injectItems (ItemFluidDrop .getAeFluidStack (items ), mode , source );
117
115
if (notInjectedItems != null ) {
118
116
items .setStackSize (notInjectedItems .getStackSize ());
119
- this .updateState (idx , LevelState .Export );
117
+ if (idx != -1 ) {
118
+ this .updateState (idx , LevelState .Export );
119
+ }
120
120
121
121
return items ;
122
122
} else {
@@ -430,7 +430,7 @@ public void writeToNBTEvent(NBTTagCompound data) {
430
430
NBTTagList tagList = new NBTTagList ();
431
431
for (int i = 0 ; i < REQ_COUNT ; i ++) {
432
432
if (this .requests [i ] != null ) {
433
- tagList .appendTag (this .requests [i ].writeToNBT ());
433
+ tagList .appendTag (this .requests [i ].writeToNBT (true ));
434
434
} else {
435
435
tagList .appendTag (new NBTTagCompound ());
436
436
}
@@ -544,6 +544,42 @@ public void writeToStream(final ByteBuf data) {
544
544
data .writeBoolean (isActive ());
545
545
}
546
546
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
+
547
583
@ MENetworkEventSubscribe
548
584
public void stateChange (final MENetworkPowerStatusChange p ) {
549
585
updatePowerState ();
@@ -643,7 +679,7 @@ public void loadFromNBT(NBTTagCompound tag) {
643
679
}
644
680
}
645
681
646
- public NBTTagCompound writeToNBT () {
682
+ public NBTTagCompound writeToNBT (boolean includeLink ) {
647
683
NBTTagCompound tag = new NBTTagCompound ();
648
684
NBTTagCompound stackTag = new NBTTagCompound ();
649
685
itemStack .writeToNBT (stackTag );
@@ -652,7 +688,7 @@ public NBTTagCompound writeToNBT() {
652
688
tag .setLong (NBT_BATCH , batchSize );
653
689
tag .setBoolean (NBT_ENABLE , enable );
654
690
tag .setInteger (NBT_STATE , state .ordinal ());
655
- if (this .link != null ) {
691
+ if (this .link != null && includeLink ) {
656
692
NBTTagCompound linkTag = new NBTTagCompound ();
657
693
this .link .writeToNBT (linkTag );
658
694
tag .setTag (NBT_LINK , linkTag );
0 commit comments