mirror of
https://github.com/GTNewHorizons/Baubles-Expanded.git
synced 2026-11-27 15:23:12 +00:00
rewrite initial sync
This commit is contained in:
6 files changed
+101
-27
No files matched your search
@@ -1,19 +1,19 @@
|
||||
package baubles.common.event;
|
||||
|
||||
import baubles.api.BaublesApi;
|
||||
import baubles.api.IBauble;
|
||||
import baubles.common.Baubles;
|
||||
import baubles.common.container.InventoryBaubles;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import baubles.common.network.PacketHandler;
|
||||
import baubles.common.network.PacketSyncBauble;
|
||||
import baubles.common.network.PacketSyncAllBauble;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class EventHandlerNetwork {
|
||||
|
||||
@@ -23,9 +23,13 @@ public class EventHandlerNetwork {
|
||||
if (side == Side.SERVER) {
|
||||
// Apply all baubles
|
||||
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(event.player);
|
||||
PacketHandler.INSTANCE.sendToAll(new PacketSyncAllBauble(event.player));
|
||||
for (Object o : MinecraftServer.getServer().getConfigurationManager().playerEntityList) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) o;
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncAllBauble(player), (EntityPlayerMP) event.player);
|
||||
}
|
||||
for (int i = 0; i < baubles.getSizeInventory(); i++) {
|
||||
ItemStack stack = baubles.getStackInSlot(i);
|
||||
PacketHandler.INSTANCE.sendToAll(new PacketSyncBauble(event.player, i, true));
|
||||
if (stack != null && stack.getItem() instanceof IBauble itemBauble) {
|
||||
itemBauble.onPlayerLoad(stack, event.player);
|
||||
}
|
||||
@@ -34,6 +38,12 @@ public class EventHandlerNetwork {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConnectedToServer(FMLNetworkEvent.ClientConnectedToServerEvent event) {
|
||||
// clear old cache
|
||||
PlayerHandler.clearClientPlayerBaubles();
|
||||
}
|
||||
|
||||
public static void syncBaubles(EntityPlayer player) {
|
||||
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
|
||||
for (int i = 0; i < baubles.getSizeInventory(); i++) {
|
||||
|
||||
Reference in new issue
Block a user