mirror of
https://github.com/GTNewHorizons/Baubles-Expanded.git
synced 2026-11-27 15:23:12 +00:00
some fixes for syncing between client and server
When the inventory was being changed outside the gui the itemstacks were not being synced to client.
This commit is contained in:
1 parent
c1b33b7688
commit
4b782a9e99
7 files changed
+71
-2
No files matched your search
@@ -26,7 +26,7 @@ public class Baubles {
|
||||
|
||||
public static final String MODID = "Baubles";
|
||||
public static final String MODNAME = "Baubles";
|
||||
public static final String VERSION = "1.0.0.7";
|
||||
public static final String VERSION = "1.0.0.8";
|
||||
|
||||
@SidedProxy(clientSide = "baubles.client.ClientProxy", serverSide = "baubles.common.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@@ -3,6 +3,7 @@ package baubles.common.container;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -10,7 +11,9 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.api.IBauble;
|
||||
import baubles.common.Baubles;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import baubles.common.network.PacketSyncBauble;
|
||||
|
||||
public class InventoryBaubles implements IInventory {
|
||||
public ItemStack[] stackList;
|
||||
@@ -96,6 +99,7 @@ public class InventoryBaubles implements IInventory {
|
||||
}
|
||||
|
||||
if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this);
|
||||
syncSlotToClient(par1);
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = this.stackList[par1].splitStack(par2);
|
||||
@@ -108,6 +112,7 @@ public class InventoryBaubles implements IInventory {
|
||||
((IBauble)itemstack.getItem()).onUnequipped(itemstack, player.get());
|
||||
}
|
||||
if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this);
|
||||
syncSlotToClient(par1);
|
||||
return itemstack;
|
||||
}
|
||||
} else {
|
||||
@@ -126,6 +131,7 @@ public class InventoryBaubles implements IInventory {
|
||||
((IBauble)stack.getItem()).onEquipped(stack, player.get());
|
||||
}
|
||||
if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this);
|
||||
syncSlotToClient(par1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +226,15 @@ public class InventoryBaubles implements IInventory {
|
||||
if (this.stackList[i] != null) {
|
||||
player.dropPlayerItemWithRandomChoice(this.stackList[i], true);
|
||||
this.stackList[i] = null;
|
||||
syncSlotToClient(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void syncSlotToClient(int slot) {
|
||||
try {
|
||||
if (Baubles.proxy.getClientWorld()==null)
|
||||
Baubles.packetPipeline.sendTo(new PacketSyncBauble(player.get(),slot), (EntityPlayerMP) player.get());
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ public class EventHandlerNetwork {
|
||||
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
||||
if (side == Side.SERVER) {
|
||||
PlayerHandler.loadPlayerBaubles(event.player);
|
||||
for (int a=0;a<4;a++)
|
||||
PlayerHandler.getPlayerBaubles(event.player).syncSlotToClient(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||
|
||||
//packets
|
||||
registerPacket(PacketOpenBaublesInventory.class);
|
||||
registerPacket(PacketSyncBauble.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package baubles.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
|
||||
public class PacketSyncBauble extends AbstractPacket {
|
||||
|
||||
int slot;
|
||||
ItemStack bauble=null;
|
||||
|
||||
public PacketSyncBauble() {}
|
||||
|
||||
public PacketSyncBauble(EntityPlayer player, int slot) {
|
||||
this.slot = slot;
|
||||
this.bauble = PlayerHandler.getPlayerBaubles(player).getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
buffer.writeByte(slot);
|
||||
PacketBuffer pb = new PacketBuffer(buffer);
|
||||
try { pb.writeItemStackToBuffer(bauble); } catch (IOException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)
|
||||
{
|
||||
slot = buffer.readByte();
|
||||
PacketBuffer pb = new PacketBuffer(buffer);
|
||||
try { bauble = pb.readItemStackFromBuffer(); } catch (IOException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
PlayerHandler.getPlayerBaubles(player).stackList[slot]=bauble;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user