Make Altar packet write the ItemStack to NBT (#155)

This commit is contained in:
Mykhailo Balaker authored and GitHub committed 2026-10-25 00:39:49 -05:00
1 parent 10a36f6413
commit 56a268bcda
2 files changed
+9 -47

No files matched your search

@@ -11,6 +11,7 @@ import java.util.stream.IntStream;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@@ -34,6 +35,7 @@ import WayofTime.alchemicalWizardry.common.tileEntity.TESocket;
import WayofTime.alchemicalWizardry.common.tileEntity.TETeleposer;
import WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec;
import cpw.mods.fml.common.network.FMLOutboundHandler;
@@ -106,7 +108,7 @@ public enum NewPacketHandler {
World world = AlchemicalWizardry.proxy.getClientWorld();
TileEntity te = world.getTileEntity(msg.x, msg.y, msg.z);
if (te instanceof TEAltar altar) {
altar.handlePacketData(msg.items, msg.fluids, msg.capacity);
altar.handlePacketData(msg.itemStack, msg.fluids, msg.capacity);
}
}
}
@@ -317,7 +319,7 @@ public enum NewPacketHandler {
int y;
int z;
int[] items;
ItemStack itemStack;
int[] fluids;
int capacity;
}
@@ -482,11 +484,7 @@ public enum NewPacketHandler {
target.writeInt(m.y);
target.writeInt(m.z);
target.writeBoolean(m.items != null);
if (m.items != null) {
int[] items = m.items;
Arrays.stream(items).forEach(target::writeInt);
}
ByteBufUtils.writeItemStack(target, m.itemStack);
target.writeBoolean(m.fluids != null);
if (m.fluids != null) {
@@ -658,13 +656,8 @@ public enum NewPacketHandler {
m.x = dat.readInt();
m.y = dat.readInt();
m.z = dat.readInt();
boolean hasStacks = dat.readBoolean();
m.items = new int[TEAltar.sizeInv * 3];
if (hasStacks) {
m.items = new int[TEAltar.sizeInv * 3];
IntStream.range(0, m.items.length).forEach(i -> m.items[i] = dat.readInt());
}
m.itemStack = ByteBufUtils.readItemStack(dat);
boolean hasFluids = dat.readBoolean();
m.fluids = new int[6];
@@ -841,7 +834,7 @@ public enum NewPacketHandler {
msg.x = tileAltar.xCoord;
msg.y = tileAltar.yCoord;
msg.z = tileAltar.zCoord;
msg.items = tileAltar.buildIntDataList();
msg.itemStack = tileAltar.getStackInSlot(0);
msg.fluids = tileAltar.buildFluidList();
msg.capacity = tileAltar.getCapacity();
@@ -5,7 +5,6 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
@@ -718,19 +717,8 @@ public class TEAltar extends TEInventory implements IFluidTank, IFluidHandler, I
return NewPacketHandler.getPacket(this);
}
public void handlePacketData(int[] intData, int[] fluidData, int capacity) {
if (intData == null) {
return;
}
if (intData.length == 3) {
if (intData[2] != 0) {
ItemStack is = new ItemStack(Item.getItemById(intData[0]), intData[2], intData[1]);
inv[0] = is;
} else {
inv[0] = null;
}
}
public void handlePacketData(ItemStack itemStack, int[] fluidData, int capacity) {
inv[0] = itemStack == null ? null : itemStack.copy();
FluidStack flMain = new FluidStack(fluidData[0], fluidData[1]);
FluidStack flIn = new FluidStack(fluidData[2], fluidData[3]);
@@ -743,25 +731,6 @@ public class TEAltar extends TEInventory implements IFluidTank, IFluidHandler, I
this.capacity = capacity;
}
public int[] buildIntDataList() {
int[] sortList = new int[3]; // 1 * 3
int pos = 0;
for (ItemStack is : inv) {
if (is != null) {
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
} else {
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
}
}
return sortList;
}
@Override
public void startCycle() {
if (worldObj != null) {