diff options
author | miozune <miozune@gmail.com> | 2023-09-15 20:24:28 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-15 13:24:28 +0200 |
commit | dcb998cecc6bf3b97a5274958034587f32c43079 (patch) | |
tree | c2c41268049876554d79a22d045ae63f627d499c /src/main/java/gregtech/crossmod/holoinventory | |
parent | b31052879e7601dbfea4c7fb53b94119c7bbf5c6 (diff) | |
download | GT5-Unofficial-dcb998cecc6bf3b97a5274958034587f32c43079.tar.gz GT5-Unofficial-dcb998cecc6bf3b97a5274958034587f32c43079.tar.bz2 GT5-Unofficial-dcb998cecc6bf3b97a5274958034587f32c43079.zip |
Add HoloInventory compat (#2292)
Diffstat (limited to 'src/main/java/gregtech/crossmod/holoinventory')
-rw-r--r-- | src/main/java/gregtech/crossmod/holoinventory/GT_InventoryDecoder.java | 38 | ||||
-rw-r--r-- | src/main/java/gregtech/crossmod/holoinventory/HoloInventory.java | 10 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/gregtech/crossmod/holoinventory/GT_InventoryDecoder.java b/src/main/java/gregtech/crossmod/holoinventory/GT_InventoryDecoder.java new file mode 100644 index 0000000000..0cc8d1bf44 --- /dev/null +++ b/src/main/java/gregtech/crossmod/holoinventory/GT_InventoryDecoder.java @@ -0,0 +1,38 @@ +package gregtech.crossmod.holoinventory; + +import static net.dries007.holoInventory.util.NBTKeys.*; + +import java.util.List; + +import net.dries007.holoInventory.compat.InventoryDecoder; +import net.dries007.holoInventory.compat.InventoryDecoderRegistry; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +import gregtech.api.metatileentity.BaseTileEntity; + +public class GT_InventoryDecoder extends InventoryDecoder { + + public GT_InventoryDecoder() { + super(BaseTileEntity.class); + } + + @Override + public NBTTagList toNBT(IInventory inv) { + List<ItemStack> items = ((BaseTileEntity) inv).getItemsForHoloGlasses(); + if (items == null) { + return InventoryDecoderRegistry.DEFAULT.toNBT(inv); + } + NBTTagList tagList = new NBTTagList(); + for (ItemStack stack : items) { + if (stack != null) { + NBTTagCompound tag = stack.writeToNBT(new NBTTagCompound()); + tag.setInteger(NBT_KEY_COUNT, stack.stackSize); + tagList.appendTag(tag); + } + } + return tagList; + } +} diff --git a/src/main/java/gregtech/crossmod/holoinventory/HoloInventory.java b/src/main/java/gregtech/crossmod/holoinventory/HoloInventory.java new file mode 100644 index 0000000000..d7dcdcf4b5 --- /dev/null +++ b/src/main/java/gregtech/crossmod/holoinventory/HoloInventory.java @@ -0,0 +1,10 @@ +package gregtech.crossmod.holoinventory; + +import net.dries007.holoInventory.compat.InventoryDecoderRegistry; + +public class HoloInventory { + + public static void init() { + InventoryDecoderRegistry.register(new GT_InventoryDecoder()); + } +} |