mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 19:19:43 +00:00
Sync Effects Packet
This commit is contained in:
1 parent
7d37670494
commit
097f1f9d1d
7 files changed
+94
-3
No files matched your search
@@ -4,9 +4,11 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncEffectPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.SyncPacket;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -15,6 +17,8 @@ import noppes.npcs.controllers.*;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class SyncController {
|
||||
|
||||
@@ -558,4 +562,21 @@ public class SyncController {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncEffects(EntityPlayerMP playerMP){
|
||||
ConcurrentHashMap<EffectKey, PlayerEffect> playerEffects = CustomEffectController.getInstance().getPlayerEffects(playerMP);
|
||||
PlayerData playerData = PlayerData.get(playerMP);
|
||||
playerData.effectData.setEffects(playerEffects);
|
||||
|
||||
NBTTagCompound compound = playerData.getPlayerEffects();
|
||||
PacketHandler.Instance.sendToPlayer(new SyncEffectPacket(compound), playerMP);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientSyncEffects(NBTTagCompound compound) {
|
||||
PlayerData playerData = PlayerData.get(Minecraft.getMinecraft().thePlayer);
|
||||
if(playerData != null){
|
||||
playerData.setPlayerEffects(compound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -367,6 +367,7 @@ public class PacketHandler {
|
||||
DATA_PACKET.registerPacket(new ScrollDataPacket());
|
||||
DATA_PACKET.registerPacket(new ScrollListPacket());
|
||||
DATA_PACKET.registerPacket(new SyncPacket());
|
||||
DATA_PACKET.registerPacket(new SyncEffectPacket());
|
||||
DATA_PACKET.registerPacket(new GuiDataPacket());
|
||||
DATA_PACKET.registerPacket(new PartyDataPacket());
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package kamkeel.npcs.network.enums;
|
||||
public enum EnumDataPacket {
|
||||
// Synchronization
|
||||
SYNC,
|
||||
SYNC_EFFECTS,
|
||||
CONFIG_COMMAND,
|
||||
|
||||
// Messages
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package kamkeel.npcs.network.packets.data.large;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.LargeAbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumDataPacket;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class SyncEffectPacket extends LargeAbstractPacket {
|
||||
|
||||
private NBTTagCompound syncData;
|
||||
|
||||
public SyncEffectPacket() {}
|
||||
|
||||
public SyncEffectPacket(NBTTagCompound syncData) {
|
||||
this.syncData = syncData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumDataPacket.SYNC_EFFECTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.DATA_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] getData() throws IOException {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
ByteBufUtils.writeBigNBT(buffer, syncData);
|
||||
byte[] bytes = new byte[buffer.readableBytes()];
|
||||
buffer.readBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
||||
if (CustomNpcs.side() != Side.CLIENT)
|
||||
return;
|
||||
try {
|
||||
NBTTagCompound tag = ByteBufUtils.readBigNBT(data);
|
||||
SyncController.clientSyncEffects(tag);
|
||||
}
|
||||
catch (RuntimeException e){
|
||||
LogWriter.error(String.format("Attempted to Sync Effects but it was too big"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,9 @@ public class ScriptPlayerEventHandler {
|
||||
playerData.timers.update();
|
||||
}
|
||||
|
||||
if(player.ticksExisted % 10 == 0)
|
||||
SyncController.syncEffects((EntityPlayerMP) player);
|
||||
|
||||
// TODO: Fix Config
|
||||
// player.ticksExisted % ConfigDBCGameplay.CheckEffectsTick == 0
|
||||
if (player.ticksExisted % 10 == 0)
|
||||
|
||||
@@ -53,6 +53,7 @@ public class ServerTickHandler {
|
||||
}
|
||||
|
||||
SyncController.syncPlayer(player);
|
||||
SyncController.syncEffects(player);
|
||||
ProfileController.login(player);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
private HashMap<Integer, String> bootOrder;
|
||||
|
||||
private int lastUsedID = 0;
|
||||
public ConcurrentHashMap<UUID, Map<EffectKey, PlayerEffect>> playerEffects = new ConcurrentHashMap<>();
|
||||
public ConcurrentHashMap<UUID, ConcurrentHashMap<EffectKey, PlayerEffect>> playerEffects = new ConcurrentHashMap<>();
|
||||
|
||||
public CustomEffectController() {}
|
||||
|
||||
@@ -214,9 +214,9 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
return has(name, 0);
|
||||
}
|
||||
|
||||
public Map<EffectKey, PlayerEffect> getPlayerEffects(EntityPlayer player) {
|
||||
public ConcurrentHashMap<EffectKey, PlayerEffect> getPlayerEffects(EntityPlayer player) {
|
||||
UUID playerId = NoppesUtilServer.getUUID(player);
|
||||
Map<EffectKey, PlayerEffect> effects = playerEffects.get(playerId);
|
||||
ConcurrentHashMap<EffectKey, PlayerEffect> effects = playerEffects.get(playerId);
|
||||
if (effects == null) {
|
||||
effects = new ConcurrentHashMap<>();
|
||||
playerEffects.put(playerId, effects);
|
||||
|
||||
Reference in new issue
Block a user