mirror of
https://github.com/GTNewHorizons/Baubles-Expanded.git
synced 2026-11-27 15:23:12 +00:00
57 lines
2.1 KiB
Java
57 lines
2.1 KiB
Java
package baubles.common.event;
|
|
|
|
import baubles.api.IBauble;
|
|
import baubles.common.container.InventoryBaubles;
|
|
import baubles.common.lib.PlayerHandler;
|
|
import baubles.common.network.PacketHandler;
|
|
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.entity.player.EntityPlayerMP;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
public class EventHandlerNetwork {
|
|
|
|
@SubscribeEvent
|
|
public void playerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event) {
|
|
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
|
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) {
|
|
if (o == event.player) continue;
|
|
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);
|
|
if (stack != null && stack.getItem() instanceof IBauble itemBauble) {
|
|
itemBauble.onPlayerLoad(stack, event.player);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
@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++) {
|
|
baubles.syncSlotToClients(i);
|
|
}
|
|
}
|
|
|
|
|
|
}
|