Skip to content

Commit

Permalink
Switch to byte array tags
Browse files Browse the repository at this point in the history
  • Loading branch information
voidsong-dragonfly committed Apr 3, 2021
1 parent 5049381 commit 125249a
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/main/java/zmaster587/libVulpes/util/EmbeddedInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.*;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
Expand All @@ -16,6 +13,7 @@
import zmaster587.libVulpes.interfaces.IInventoryUpdateCallback;

import javax.annotation.Nonnull;
import java.util.ArrayList;

public class EmbeddedInventory extends ItemStackHandler implements ISidedInventory {

Expand Down Expand Up @@ -56,19 +54,17 @@ public void writeToNBT(NBTTagCompound nbt) {

nbt.setTag("outputItems", list);

NBTTagList list2 = new NBTTagList();
ArrayList list2 = new ArrayList<Byte>();
for(int i = 0; i < this.slotInsert.size(); i++) {
NBTTagInt tag = new NBTTagInt((slotInsert.get(i) == true) ? 1 : 0);
list2.appendTag(tag);
list2.set(i, (slotInsert.get(i) == true) ? 1 : 0);
}
nbt.setTag("slotInsert", list2);
nbt.setTag("slotInsert", new NBTTagByteArray(list2));

NBTTagList list3 = new NBTTagList();
ArrayList list3 = new ArrayList<Byte>();
for(int i = 0; i < this.slotExtract.size(); i++) {
NBTTagInt tag = new NBTTagInt((slotExtract.get(i) == true) ? 1 : 0);
list3.appendTag(tag);
list3.set(i, (slotExtract.get(i) == true) ? 1 : 0);
}
nbt.setTag("slotExtract", list3);
nbt.setTag("slotExtract", new NBTTagByteArray(list3));

}

Expand All @@ -94,15 +90,15 @@ public void readFromNBT(NBTTagCompound nbt) {
}


NBTTagList list2 = nbt.getTagList("slotInsert", NBT.TAG_INT);
this.slotInsert = NonNullList.withSize(list2.tagCount(), false);
for (int i = 0; i < list2.tagCount(); i++) {
this.slotInsert.set(i, (list2.getIntAt(i) == 1) ? true : false);
byte[] list2 = nbt.getByteArray("slotInsert");
this.slotInsert = NonNullList.withSize(list2.length, false);
for (int i = 0; i < list2.length; i++) {
this.slotInsert.set(i, (list2[i] == 1) ? true : false);
}
NBTTagList list3 = nbt.getTagList("slotExtract", NBT.TAG_INT);
this.slotExtract = NonNullList.withSize(list3.tagCount(), false);
for (int i = 0; i < list3.tagCount(); i++) {
this.slotExtract.set(i, (list3.getIntAt(i) == 1) ? true : false);
byte[] list3 = nbt.getByteArray("slotExtract");
this.slotExtract = NonNullList.withSize(list3.length, false);
for (int i = 0; i < list3.length; i++) {
this.slotExtract.set(i, (list3[i] == 1) ? true : false);
}

//Backcompat, to allow older worlds to load
Expand Down

0 comments on commit 125249a

Please sign in to comment.