mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-27 01:32:55 +00:00
Syncing and Large Packet Completion
This commit is contained in:
1 parent
dcf3a0d8b0
commit
de56032118
39 files changed
+648
-862
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncMaster;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
@@ -89,7 +90,7 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
)
|
||||
public void reload(ICommandSender sender, String args[]){
|
||||
new DialogController().load();
|
||||
SyncController.syncAllDialogs();
|
||||
SyncMaster.syncAllDialogs();
|
||||
sendResult(sender, "Dialogs Reloaded");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package kamkeel.npcs.command;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncMaster;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -382,7 +383,7 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
)
|
||||
public void reload(ICommandSender sender, String args[]){
|
||||
new QuestController().load();
|
||||
SyncController.syncAllQuests();
|
||||
SyncMaster.syncAllQuests();
|
||||
sendResult(sender, "Quests Reloaded");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,383 @@
|
||||
package kamkeel.npcs.controllers;
|
||||
|
||||
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.client.large.sync.LargeSyncPacket;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.FactionController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SyncMaster {
|
||||
|
||||
public static void syncPlayer(EntityPlayerMP player){
|
||||
// 1) Factions
|
||||
PacketHandler.Instance.sendToPlayer(new LargeSyncPacket(
|
||||
EnumSyncType.FACTION,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
factionsNBT()
|
||||
), player);
|
||||
|
||||
// 2) Dialog Categories
|
||||
PacketHandler.Instance.sendToPlayer(new LargeSyncPacket(
|
||||
EnumSyncType.DIALOG_CATEGORY,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
dialogCategoriesNBT()
|
||||
), player);
|
||||
|
||||
// 3) Quest Categories
|
||||
PacketHandler.Instance.sendToPlayer(new LargeSyncPacket(
|
||||
EnumSyncType.QUEST_CATEGORY,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
questCategoriesNBT()
|
||||
), player);
|
||||
|
||||
DBCAddon.instance.syncPlayer(player);
|
||||
syncPlayerData(player, false);
|
||||
}
|
||||
|
||||
public static NBTTagCompound factionsNBT(){
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for(Faction faction : FactionController.getInstance().factions.values()){
|
||||
NBTTagCompound factioNBT = new NBTTagCompound();
|
||||
faction.writeNBT(factioNBT);
|
||||
list.appendTag(factioNBT);
|
||||
}
|
||||
compound.setTag("Factions", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound dialogCategoriesNBT(){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList categoryList = new NBTTagList();
|
||||
for(DialogCategory category : DialogController.Instance.categories.values()){
|
||||
NBTTagCompound questCompound = new NBTTagCompound();;
|
||||
NBTTagList dialogList = new NBTTagList();
|
||||
for(int dialogID : category.dialogs.keySet()){
|
||||
Dialog quest = category.dialogs.get(dialogID);
|
||||
dialogList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
questCompound.setTag("Data", dialogList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
}
|
||||
compound.setTag("DialogCategories", categoryList);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static void syncPlayerData(EntityPlayerMP player, boolean update){
|
||||
PlayerData data = PlayerData.get(player);
|
||||
if(data != null){
|
||||
if(update){
|
||||
PacketHandler.Instance.sendToPlayer(new LargeSyncPacket(
|
||||
EnumSyncType.PLAYERDATA,
|
||||
EnumSyncAction.UPDATE,
|
||||
-1,
|
||||
data.getSyncNBT())
|
||||
, player);
|
||||
} else {
|
||||
PacketHandler.Instance.sendToPlayer(new LargeSyncPacket(
|
||||
EnumSyncType.PLAYERDATA,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
data.getSyncNBTFull()), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncRemove(EnumSyncType enumSyncType, int id){
|
||||
PacketHandler.Instance.sendToAll(new LargeSyncPacket(
|
||||
enumSyncType,
|
||||
EnumSyncAction.REMOVE,
|
||||
id,
|
||||
new NBTTagCompound()
|
||||
));
|
||||
}
|
||||
|
||||
public static void syncAllDialogs() {
|
||||
PacketHandler.Instance.sendToAll(new LargeSyncPacket(
|
||||
EnumSyncType.DIALOG_CATEGORY,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
dialogCategoriesNBT()
|
||||
));
|
||||
}
|
||||
|
||||
public static void syncAllQuests() {
|
||||
PacketHandler.Instance.sendToAll(new LargeSyncPacket(
|
||||
EnumSyncType.QUEST_CATEGORY,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
questCategoriesNBT()
|
||||
));
|
||||
}
|
||||
|
||||
public static NBTTagCompound questCategoriesNBT(){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagList categoryList = new NBTTagList();
|
||||
for(QuestCategory category : QuestController.Instance.categories.values()){
|
||||
NBTTagCompound questCompound = new NBTTagCompound();;
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for(int questID : category.quests.keySet()){
|
||||
Quest quest = category.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
|
||||
}
|
||||
compound.setTag("QuestCategories", categoryList);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientSync(EnumSyncType enumSyncType, NBTTagCompound fullCompound) {
|
||||
switch (enumSyncType){
|
||||
case FACTION: {
|
||||
NBTTagList list = fullCompound.getTagList("Factions", 10);
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(list.getCompoundTagAt(i));
|
||||
FactionController.getInstance().factionsSync.put(faction.id, faction);
|
||||
}
|
||||
FactionController.getInstance().factions = FactionController.getInstance().factionsSync;
|
||||
FactionController.getInstance().factionsSync = new HashMap<Integer, Faction>();
|
||||
break;
|
||||
}
|
||||
case DIALOG_CATEGORY: {
|
||||
if(!fullCompound.hasNoTags()){
|
||||
NBTTagList categories = fullCompound.getTagList("DialogCategories", 10);
|
||||
for(int j = 0; j < fullCompound.getTagList("DialogCategories", 10).tagCount(); j++) {
|
||||
NBTTagCompound categoryCompound = categories.getCompoundTagAt(j);
|
||||
if(categoryCompound.hasNoTags())
|
||||
continue;
|
||||
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
NBTTagList dialogList = categoryCompound.getTagList("Data", 10);
|
||||
if(DialogController.Instance.categoriesSync.containsKey(category.id)){
|
||||
category = DialogController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for(int i = 0; i < dialogList.tagCount(); i++)
|
||||
{
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.readNBT(dialogList.getCompoundTagAt(i));
|
||||
dialog.category = category;
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
DialogController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<Integer, Dialog> dialogs = new HashMap<Integer, Dialog>();
|
||||
for(DialogCategory category : DialogController.Instance.categoriesSync.values()){
|
||||
for(Dialog dialog : category.dialogs.values()){
|
||||
dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
}
|
||||
|
||||
DialogController.Instance.categories = DialogController.Instance.categoriesSync;
|
||||
DialogController.Instance.dialogs = dialogs;
|
||||
DialogController.Instance.categoriesSync = new HashMap<Integer, DialogCategory>();
|
||||
break;
|
||||
}
|
||||
case QUEST_CATEGORY: {
|
||||
if(!fullCompound.hasNoTags()){
|
||||
NBTTagList categories = fullCompound.getTagList("QuestCategories", 10);
|
||||
for(int j = 0; j < fullCompound.getTagList("QuestCategories", 10).tagCount(); j++) {
|
||||
NBTTagCompound categoryCompound = categories.getCompoundTagAt(j);
|
||||
if(categoryCompound.hasNoTags())
|
||||
continue;
|
||||
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
NBTTagList questList = categoryCompound.getTagList("Data", 10);
|
||||
if(QuestController.Instance.categoriesSync.containsKey(category.id)){
|
||||
category = QuestController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for(int i = 0; i < questList.tagCount(); i++)
|
||||
{
|
||||
Quest quest = new Quest();
|
||||
quest.readNBT(questList.getCompoundTagAt(i));
|
||||
quest.category = category;
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
QuestController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<Integer,Quest> quests = new HashMap<Integer, Quest>();
|
||||
for(QuestCategory category : QuestController.Instance.categoriesSync.values()){
|
||||
for(Quest quest : category.quests.values()){
|
||||
quests.put(quest.id, quest);
|
||||
}
|
||||
}
|
||||
|
||||
QuestController.Instance.categories = QuestController.Instance.categoriesSync;
|
||||
QuestController.Instance.quests = quests;
|
||||
QuestController.Instance.categoriesSync = new HashMap<Integer, QuestCategory>();
|
||||
break;
|
||||
}
|
||||
case PLAYERDATA: {
|
||||
ClientCacheHandler.playerData.setSyncNBTFull(fullCompound);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Related Tasks
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientUpdate(EnumSyncType enumSyncType, int category_id, NBTTagCompound compound) {
|
||||
switch (enumSyncType){
|
||||
case FACTION: {
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(compound);
|
||||
FactionController.getInstance().factions.put(faction.id, faction);
|
||||
break;
|
||||
}
|
||||
case DIALOG: {
|
||||
DialogCategory category = DialogController.Instance.categories.get(category_id);
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.category = category;
|
||||
dialog.readNBT(compound);
|
||||
DialogController.Instance.dialogs.put(dialog.id, dialog);
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
break;
|
||||
}
|
||||
case QUEST: {
|
||||
QuestCategory category = QuestController.Instance.categories.get(category_id);
|
||||
Quest quest = new Quest();
|
||||
quest.category = category;
|
||||
quest.readNBT(compound);
|
||||
QuestController.Instance.quests.put(quest.id, quest);
|
||||
category.quests.put(quest.id, quest);
|
||||
break;
|
||||
}
|
||||
case QUEST_CATEGORY: {
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if(QuestController.Instance.categoriesSync.containsKey(category.id)){
|
||||
category = QuestController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
Quest quest = new Quest();
|
||||
quest.readNBT(list.getCompoundTagAt(i));
|
||||
quest.category = category;
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
QuestController.Instance.categories.put(category.id, category);
|
||||
break;
|
||||
}
|
||||
case DIALOG_CATEGORY: {
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
if(DialogController.Instance.categoriesSync.containsKey(category.id)){
|
||||
category = DialogController.Instance.categoriesSync.get(category.id);
|
||||
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
|
||||
}
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.readNBT(list.getCompoundTagAt(i));
|
||||
dialog.category = category;
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
DialogController.Instance.categories.put(category.id, category);
|
||||
break;
|
||||
}
|
||||
case PLAYERDATA: {
|
||||
ClientCacheHandler.playerData.setSyncNBT(compound);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncUpdate(EnumSyncType type, int cat, NBTTagCompound compound) {
|
||||
PacketHandler.Instance.sendToAll(new LargeSyncPacket(
|
||||
type,
|
||||
EnumSyncAction.UPDATE,
|
||||
cat,
|
||||
compound
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public static NBTTagCompound updateQuestCat(QuestCategory questCategory) {
|
||||
NBTTagCompound questCompound = new NBTTagCompound();
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for(int questID : questCategory.quests.keySet()){
|
||||
Quest quest = questCategory.quests.get(questID);
|
||||
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
questCompound.setTag("Data", questList);
|
||||
questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
return questCompound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound updateDialogCat(DialogCategory dialogCategory) {
|
||||
NBTTagCompound dialogCompound = new NBTTagCompound();
|
||||
NBTTagList dialogList = new NBTTagList();
|
||||
for(int questID : dialogCategory.dialogs.keySet()){
|
||||
Dialog dialog = dialogCategory.dialogs.get(questID);
|
||||
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
dialogCompound.setTag("Data", dialogList);
|
||||
dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound()));
|
||||
return dialogCompound;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clientSyncRemove(EnumSyncType enumSyncType, int id) {
|
||||
switch (enumSyncType){
|
||||
case FACTION:
|
||||
FactionController.getInstance().factions.remove(id);
|
||||
break;
|
||||
case DIALOG:
|
||||
Dialog dialog = DialogController.Instance.dialogs.remove(id);
|
||||
if(dialog != null) {
|
||||
dialog.category.dialogs.remove(id);
|
||||
}
|
||||
break;
|
||||
case DIALOG_CATEGORY:
|
||||
DialogCategory dialogCategory = DialogController.Instance.categories.remove(id);
|
||||
if(dialogCategory != null) {
|
||||
DialogController.Instance.dialogs.keySet().removeAll(dialogCategory.dialogs.keySet());
|
||||
}
|
||||
break;
|
||||
case QUEST:
|
||||
Quest quest = QuestController.Instance.quests.remove(id);
|
||||
if(quest != null) {
|
||||
quest.category.quests.remove(id);
|
||||
}
|
||||
break;
|
||||
case QUEST_CATEGORY:
|
||||
QuestCategory questCategory = QuestController.Instance.categories.remove(id);
|
||||
if(questCategory != null) {
|
||||
QuestController.Instance.quests.keySet().removeAll(questCategory.quests.keySet());
|
||||
}
|
||||
break;
|
||||
case MAGIC:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractPacket {
|
||||
|
||||
@@ -16,11 +18,22 @@ public abstract class AbstractPacket {
|
||||
buf.writeInt(packetChannel.getChannelType().ordinal());
|
||||
buf.writeInt(getType().ordinal());
|
||||
sendData(buf);
|
||||
return new FMLProxyPacket(buf, getChannel().getChannelName());
|
||||
} catch (Exception ignored) {}
|
||||
return new FMLProxyPacket(buf, packetChannel.getChannelName());
|
||||
} catch (Exception e) {
|
||||
// For debugging, you might want to log it
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<FMLProxyPacket> generatePackets() {
|
||||
FMLProxyPacket single = generatePacket();
|
||||
if (single == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(single);
|
||||
}
|
||||
|
||||
public abstract Enum getType();
|
||||
public abstract PacketChannel getChannel();
|
||||
public abstract void sendData(ByteBuf out) throws IOException;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package kamkeel.npcs.network;
|
||||
|
||||
import kamkeel.npcs.network.packets.large.LargeScrollGroupPacket;
|
||||
import kamkeel.npcs.network.packets.large.LargeScrollDataPacket;
|
||||
import kamkeel.npcs.network.packets.client.large.LargeScrollGroupPacket;
|
||||
import kamkeel.npcs.network.packets.client.large.LargeScrollDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package kamkeel.npcs.network;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import org.lwjgl.Sys;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -13,28 +16,47 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public abstract class LargeAbstractPacket extends AbstractPacket {
|
||||
|
||||
private static final Map<UUID, PacketStorage> packetChunks = new ConcurrentHashMap<>();
|
||||
private static final int CHUNK_SIZE = 5000;
|
||||
private static final int CHUNK_SIZE = 10000;
|
||||
|
||||
/**
|
||||
* Create multiple FMLProxyPacket objects, each containing up to CHUNK_SIZE bytes.
|
||||
*/
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
byte[] data = getData();
|
||||
int totalSize = data.length;
|
||||
public List<FMLProxyPacket> generatePackets() {
|
||||
List<FMLProxyPacket> packets = new ArrayList<>();
|
||||
PacketChannel packetChannel = getChannel();
|
||||
|
||||
byte[] fullData;
|
||||
try {
|
||||
fullData = getData();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return packets;
|
||||
}
|
||||
|
||||
int totalSize = fullData.length;
|
||||
UUID packetId = UUID.randomUUID();
|
||||
|
||||
// Break the data into chunks of CHUNK_SIZE bytes each
|
||||
// Break data into CHUNK_SIZE chunks
|
||||
for (int offset = 0; offset < totalSize; offset += CHUNK_SIZE) {
|
||||
int chunkSize = Math.min(CHUNK_SIZE, totalSize - offset);
|
||||
ByteBuf chunkBuf = Unpooled.buffer();
|
||||
|
||||
// Write a header for each chunk
|
||||
out.writeLong(packetId.getMostSignificantBits());
|
||||
out.writeLong(packetId.getLeastSignificantBits());
|
||||
out.writeInt(totalSize);
|
||||
out.writeInt(offset);
|
||||
out.writeInt((totalSize + CHUNK_SIZE - 1) / CHUNK_SIZE); // totalChunks
|
||||
chunkBuf.writeInt(packetChannel.getChannelType().ordinal());
|
||||
chunkBuf.writeInt(getType().ordinal());
|
||||
|
||||
// Write the chunk bytes
|
||||
out.writeBytes(data, offset, chunkSize);
|
||||
chunkBuf.writeLong(packetId.getMostSignificantBits());
|
||||
chunkBuf.writeLong(packetId.getLeastSignificantBits());
|
||||
chunkBuf.writeInt(totalSize);
|
||||
chunkBuf.writeInt(offset);
|
||||
chunkBuf.writeInt((totalSize + CHUNK_SIZE - 1) / CHUNK_SIZE);
|
||||
|
||||
chunkBuf.writeBytes(fullData, offset, chunkSize);
|
||||
|
||||
FMLProxyPacket proxyPacket = new FMLProxyPacket(chunkBuf, packetChannel.getChannelName());
|
||||
packets.add(proxyPacket);
|
||||
}
|
||||
return packets;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,6 +109,12 @@ public abstract class LargeAbstractPacket extends AbstractPacket {
|
||||
|
||||
protected abstract void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException;
|
||||
|
||||
@Override
|
||||
public final FMLProxyPacket generatePacket() {return null;}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {}
|
||||
|
||||
/**
|
||||
* Simple storage class to keep track of partial data and how many bytes we've received so far.
|
||||
*/
|
||||
|
||||
@@ -7,9 +7,10 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.enums.EnumPacketType;
|
||||
import kamkeel.npcs.network.packets.large.LargeScrollDataPacket;
|
||||
import kamkeel.npcs.network.packets.large.LargeScrollGroupPacket;
|
||||
import kamkeel.npcs.network.packets.large.LargeScrollListPacket;
|
||||
import kamkeel.npcs.network.packets.client.large.LargeScrollDataPacket;
|
||||
import kamkeel.npcs.network.packets.client.large.LargeScrollGroupPacket;
|
||||
import kamkeel.npcs.network.packets.client.large.LargeScrollListPacket;
|
||||
import kamkeel.npcs.network.packets.client.large.sync.LargeSyncPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
@@ -17,19 +18,19 @@ import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class PacketHandler {
|
||||
public static PacketHandler Instance;
|
||||
|
||||
// Channels
|
||||
public Map<EnumPacketType, FMLEventChannel> channels = new Hashtable<>();
|
||||
|
||||
public final static PacketChannel INFO_PACKET = new PacketChannel("CNPC+|Info", EnumPacketType.INFO);
|
||||
public final static PacketChannel DATA_PACKET = new PacketChannel("CNPC+|Data", EnumPacketType.DATA);
|
||||
public final static PacketChannel CLIENT_PACKET = new PacketChannel("CNPC+|Client", EnumPacketType.CLIENT);
|
||||
public final static PacketChannel LARGE_PACKET = new PacketChannel("CNPC+|Large", EnumPacketType.LARGE);
|
||||
public static final PacketChannel INFO_PACKET = new PacketChannel("CNPC+|Info", EnumPacketType.INFO);
|
||||
public static final PacketChannel DATA_PACKET = new PacketChannel("CNPC+|Data", EnumPacketType.DATA);
|
||||
public static final PacketChannel CLIENT_PACKET = new PacketChannel("CNPC+|Client", EnumPacketType.CLIENT);
|
||||
public static final PacketChannel LARGE_PACKET = new PacketChannel("CNPC+|Large", EnumPacketType.LARGE);
|
||||
|
||||
private final static List<PacketChannel> packetChannels = new ArrayList<>();
|
||||
private static final List<PacketChannel> packetChannels = new ArrayList<>();
|
||||
|
||||
public PacketHandler() {
|
||||
// Register Channels
|
||||
@@ -43,22 +44,20 @@ public final class PacketHandler {
|
||||
LARGE_PACKET.registerPacket(new LargeScrollGroupPacket());
|
||||
LARGE_PACKET.registerPacket(new LargeScrollDataPacket());
|
||||
LARGE_PACKET.registerPacket(new LargeScrollListPacket());
|
||||
|
||||
// Log channel registration
|
||||
System.out.println("PacketHandler initialized and channels registered.");
|
||||
LARGE_PACKET.registerPacket(new LargeSyncPacket());
|
||||
}
|
||||
|
||||
public void registerChannels() {
|
||||
FMLEventChannel eventChannel;
|
||||
private void registerChannels() {
|
||||
for (PacketChannel channel : packetChannels) {
|
||||
eventChannel = NetworkRegistry.INSTANCE.newEventDrivenChannel(channel.getChannelName());
|
||||
FMLEventChannel eventChannel =
|
||||
NetworkRegistry.INSTANCE.newEventDrivenChannel(channel.getChannelName());
|
||||
eventChannel.register(this);
|
||||
channels.put(channel.getChannelType(), eventChannel);
|
||||
System.out.println("Registered channel: " + channel.getChannelName());
|
||||
}
|
||||
}
|
||||
|
||||
public PacketChannel getPacketChannel(EnumPacketType type){
|
||||
public PacketChannel getPacketChannel(EnumPacketType type) {
|
||||
return packetChannels.stream()
|
||||
.filter(channel -> channel.getChannelType() == type)
|
||||
.findFirst()
|
||||
@@ -86,20 +85,26 @@ public final class PacketHandler {
|
||||
private void handlePacket(FMLProxyPacket packet, EntityPlayer player) {
|
||||
ByteBuf buf = packet.payload();
|
||||
try {
|
||||
// First two ints are channelTypeOrdinal and packetTypeOrdinal
|
||||
int packetTypeOrdinal = buf.readInt();
|
||||
EnumPacketType packetType = EnumPacketType.values()[packetTypeOrdinal];
|
||||
|
||||
PacketChannel packetChannel = getPacketChannel(packetType);
|
||||
if (packetChannel == null) {
|
||||
LogWriter.error("Error: Packet channel is null for packet type: " + packetType);
|
||||
return;
|
||||
}
|
||||
|
||||
int packetId = buf.readInt();
|
||||
AbstractPacket abstractPacket = packetChannel.packets.get(packetId);
|
||||
if (abstractPacket == null) {
|
||||
LogWriter.error("Error: Abstract packet is null for packet ID: " + packetId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Let the packet parse the rest
|
||||
abstractPacket.receiveData(buf, player);
|
||||
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
LogWriter.error("Error: IndexOutOfBoundsException in handlePacket: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
@@ -107,20 +112,31 @@ public final class PacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPacket(AbstractPacket packet, Consumer<FMLProxyPacket> sendFunction) {
|
||||
FMLProxyPacket proxyPacket = packet.generatePacket();
|
||||
if (proxyPacket != null) {
|
||||
sendFunction.accept(proxyPacket);
|
||||
/**
|
||||
* Sends every FMLProxyPacket produced by packet.generatePackets()
|
||||
*/
|
||||
private void sendAllPackets(AbstractPacket packet, SendAction action) {
|
||||
// get all generated FMLProxyPacket objects (could be 1 for normal, or many for large)
|
||||
List<FMLProxyPacket> proxyPackets = packet.generatePackets();
|
||||
if (proxyPackets.isEmpty()) {
|
||||
LogWriter.error("Warning: No packets generated for " + packet.getClass().getName());
|
||||
}
|
||||
|
||||
for (FMLProxyPacket proxy : proxyPackets) {
|
||||
action.send(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Public API methods for sending
|
||||
|
||||
public void sendToPlayer(AbstractPacket packet, EntityPlayerMP player) {
|
||||
FMLEventChannel eventChannel = getEventChannel(packet);
|
||||
if (eventChannel == null) {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
sendPacket(packet, proxyPacket -> eventChannel.sendTo(proxyPacket, player));
|
||||
sendAllPackets(packet, p -> eventChannel.sendTo(p, player));
|
||||
}
|
||||
|
||||
public void sendToServer(AbstractPacket packet) {
|
||||
@@ -129,7 +145,7 @@ public final class PacketHandler {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
sendPacket(packet, eventChannel::sendToServer);
|
||||
sendAllPackets(packet, eventChannel::sendToServer);
|
||||
}
|
||||
|
||||
public void sendToAll(AbstractPacket packet) {
|
||||
@@ -138,7 +154,7 @@ public final class PacketHandler {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
sendPacket(packet, eventChannel::sendToAll);
|
||||
sendAllPackets(packet, eventChannel::sendToAll);
|
||||
}
|
||||
|
||||
public void sendToAllAround(AbstractPacket packet, NetworkRegistry.TargetPoint point) {
|
||||
@@ -147,7 +163,7 @@ public final class PacketHandler {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
sendPacket(packet, proxyPacket -> eventChannel.sendToAllAround(proxyPacket, point));
|
||||
sendAllPackets(packet, p -> eventChannel.sendToAllAround(p, point));
|
||||
}
|
||||
|
||||
public void sendToDimension(AbstractPacket packet, int dimensionId) {
|
||||
@@ -156,6 +172,11 @@ public final class PacketHandler {
|
||||
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
|
||||
return;
|
||||
}
|
||||
sendPacket(packet, proxyPacket -> eventChannel.sendToDimension(proxyPacket, dimensionId));
|
||||
sendAllPackets(packet, p -> eventChannel.sendToDimension(p, dimensionId));
|
||||
}
|
||||
|
||||
// Simple functional interface to unify the "send" action
|
||||
private interface SendAction {
|
||||
void send(FMLProxyPacket proxy);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package kamkeel.npcs.network.enums;
|
||||
|
||||
// Packets to the Client
|
||||
public enum EnumClientPacket {
|
||||
SYNC,
|
||||
CHAT,
|
||||
MESSAGE,
|
||||
PARTY_MESSAGE,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumSyncAction {
|
||||
RELOAD,
|
||||
UPDATE,
|
||||
REMOVE
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumSyncType {
|
||||
FACTION,
|
||||
DIALOG,
|
||||
DIALOG_CATEGORY,
|
||||
QUEST,
|
||||
QUEST_CATEGORY,
|
||||
PLAYERDATA,
|
||||
MAGIC
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumClientPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class DBCFormPacket extends AbstractPacket {
|
||||
public static final String packetName = "Client|DBCForm";
|
||||
|
||||
public DBCFormPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumClientPacket.DBC_FORM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.CLIENT_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
// TODO: Send Packet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
NoppesUtil.handleFormEnd();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumClientPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LargeNBTEndPacket extends AbstractPacket {
|
||||
public static final String packetName = "Client|LargeNBTEnd";
|
||||
|
||||
public LargeNBTEndPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumClientPacket.LARGE_NBT_END;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.CLIENT_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
// TODO: Send Packet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
// Finalize handling of large NBT data (if needed).
|
||||
NoppesUtil.handleLargeData(null);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumClientPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LargeNBTPartPacket extends AbstractPacket {
|
||||
public static final String packetName = "Client|LargeNBTPart";
|
||||
|
||||
public LargeNBTPartPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumClientPacket.LARGE_NBT_PART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.CLIENT_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
// TODO: Send Packet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
byte[] chunk = new byte[in.readShort()];
|
||||
in.readBytes(chunk);
|
||||
NoppesUtil.handleLargeData(chunk);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package kamkeel.npcs.network.packets.large;
|
||||
package kamkeel.npcs.network.packets.client.large;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package kamkeel.npcs.network.packets.large;
|
||||
package kamkeel.npcs.network.packets.client.large;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package kamkeel.npcs.network.packets.large;
|
||||
package kamkeel.npcs.network.packets.client.large;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@@ -0,0 +1,102 @@
|
||||
package kamkeel.npcs.network.packets.client.large.sync;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.npcs.controllers.SyncMaster;
|
||||
import kamkeel.npcs.network.LargeAbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumClientPacket;
|
||||
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 java.io.IOException;
|
||||
|
||||
/**
|
||||
* A large sync packet that sends chunked data to the client for a given SyncType
|
||||
* along with a SyncAction (RELOAD, UPDATE, REMOVE).
|
||||
*/
|
||||
public final class LargeSyncPacket extends LargeAbstractPacket {
|
||||
|
||||
private EnumSyncType enumSyncType;
|
||||
private EnumSyncAction enumSyncAction;
|
||||
private NBTTagCompound syncData;
|
||||
private int operationID;
|
||||
|
||||
public LargeSyncPacket() {}
|
||||
|
||||
/**
|
||||
* Constructs a new LargeSyncPacket.
|
||||
*/
|
||||
public LargeSyncPacket(EnumSyncType enumSyncType, EnumSyncAction enumSyncAction, int catId, NBTTagCompound syncData) {
|
||||
this.enumSyncType = enumSyncType;
|
||||
this.enumSyncAction = enumSyncAction;
|
||||
this.syncData = syncData;
|
||||
this.operationID = catId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumClientPacket.SYNC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.LARGE_PACKET; // Or whichever channel you want.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] getData() throws IOException {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
// 1) Write SyncType
|
||||
buffer.writeInt(enumSyncType.ordinal());
|
||||
// 2) Write SyncAction
|
||||
buffer.writeInt(enumSyncAction.ordinal());
|
||||
// 3) Optional Category ID
|
||||
buffer.writeInt(operationID);
|
||||
// 4) Write the NBTTagCompound
|
||||
ByteBufUtils.writeNBT(buffer, syncData);
|
||||
|
||||
// Copy the buffer’s readable bytes into a byte[]
|
||||
byte[] bytes = new byte[buffer.readableBytes()];
|
||||
buffer.readBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
||||
if(CustomNpcs.side() != Side.CLIENT)
|
||||
return;
|
||||
|
||||
// Reconstruct everything from the ByteBuf
|
||||
int syncTypeOrdinal = data.readInt();
|
||||
int syncActionOrdinal = data.readInt();
|
||||
int categoryID = data.readInt();
|
||||
|
||||
EnumSyncType type = EnumSyncType.values()[syncTypeOrdinal];
|
||||
EnumSyncAction action = EnumSyncAction.values()[syncActionOrdinal];
|
||||
NBTTagCompound tag = ByteBufUtils.readNBT(data);
|
||||
|
||||
// Now do your client-side logic (similar to your old clientSync() or clientSyncUpdate() approach)
|
||||
handleSyncPacketClient(type, action, categoryID, tag);
|
||||
}
|
||||
|
||||
private void handleSyncPacketClient(EnumSyncType enumSyncType, EnumSyncAction enumSyncAction, int id, NBTTagCompound data) {
|
||||
switch (enumSyncAction) {
|
||||
case RELOAD:
|
||||
SyncMaster.clientSync(enumSyncType, data);
|
||||
break;
|
||||
case UPDATE:
|
||||
SyncMaster.clientUpdate(enumSyncType, id, data);
|
||||
break;
|
||||
case REMOVE:
|
||||
SyncMaster.clientSyncRemove(enumSyncType, id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.client.sync;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumClientPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class SyncAddPacket extends AbstractPacket {
|
||||
public static final String packetName = "Client|SyncAdd";
|
||||
|
||||
public SyncAddPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumClientPacket.SYNC_ADD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.CLIENT_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
// TODO: Send Packet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
int synctype = in.readInt();
|
||||
NBTTagCompound compound = Server.readNBT(in);
|
||||
SyncController.clientSync(synctype, compound, false);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.client.sync;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumClientPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class SyncEndPacket extends AbstractPacket {
|
||||
public static final String packetName = "Client|SyncEnd";
|
||||
|
||||
public SyncEndPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumClientPacket.SYNC_END;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.CLIENT_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
// TODO: Send Packet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
int synctype = in.readInt();
|
||||
NBTTagCompound compound = Server.readNBT(in);
|
||||
SyncController.clientSync(synctype, compound, true);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.client.sync;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumClientPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class SyncPlayerPacket extends AbstractPacket {
|
||||
public static final String packetName = "Client|SyncPlayer";
|
||||
|
||||
public SyncPlayerPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumClientPacket.SYNC_PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.CLIENT_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
// TODO: Send Packet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
boolean sync = in.readBoolean();
|
||||
NoppesUtil.handlePlayerDataEnd(sync);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.client.sync;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumClientPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class SyncRemovePacket extends AbstractPacket {
|
||||
public static final String packetName = "Client|SyncRemove";
|
||||
|
||||
public SyncRemovePacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumClientPacket.SYNC_REMOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.CLIENT_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
// TODO: Send Packet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
int synctype = in.readInt();
|
||||
int id = in.readInt();
|
||||
SyncController.clientSyncRemove(synctype, id);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package kamkeel.npcs.network.packets.client.sync;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumClientPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class SyncUpdatePacket extends AbstractPacket {
|
||||
public static final String packetName = "Client|SyncUpdate";
|
||||
|
||||
public SyncUpdatePacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumClientPacket.SYNC_UPDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.CLIENT_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
// TODO: Send Packet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
int synctype = in.readInt();
|
||||
NBTTagCompound compound = Server.readNBT(in);
|
||||
SyncController.clientSyncUpdate(synctype, compound, in);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user