2025-01-29 18:25:34 -05:00
|
|
|
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;
|
2025-02-10 21:41:54 -05:00
|
|
|
import kamkeel.npcs.network.packets.data.large.SyncEffectPacket;
|
2025-01-30 13:54:49 -05:00
|
|
|
import kamkeel.npcs.network.packets.data.large.SyncPacket;
|
2025-01-29 18:25:34 -05:00
|
|
|
import kamkeel.npcs.network.enums.EnumSyncAction;
|
|
|
|
|
import kamkeel.npcs.network.enums.EnumSyncType;
|
2025-02-10 21:41:54 -05:00
|
|
|
import net.minecraft.client.Minecraft;
|
2025-01-29 18:25:34 -05:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
|
import noppes.npcs.client.ClientCacheHandler;
|
2025-02-10 16:38:50 -05:00
|
|
|
import noppes.npcs.controllers.*;
|
2025-01-29 18:25:34 -05:00
|
|
|
import noppes.npcs.controllers.data.*;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2025-02-10 21:41:54 -05:00
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2025-01-29 18:25:34 -05:00
|
|
|
|
2025-01-30 09:26:04 -05:00
|
|
|
public class SyncController {
|
2025-01-29 18:25:34 -05:00
|
|
|
|
|
|
|
|
public static void syncPlayer(EntityPlayerMP player){
|
|
|
|
|
// 1) Factions
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
2025-01-29 18:25:34 -05:00
|
|
|
EnumSyncType.FACTION,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
factionsNBT()
|
|
|
|
|
), player);
|
|
|
|
|
|
|
|
|
|
// 2) Dialog Categories
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
2025-01-29 18:25:34 -05:00
|
|
|
EnumSyncType.DIALOG_CATEGORY,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
dialogCategoriesNBT()
|
|
|
|
|
), player);
|
|
|
|
|
|
|
|
|
|
// 3) Quest Categories
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
2025-01-29 18:25:34 -05:00
|
|
|
EnumSyncType.QUEST_CATEGORY,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
questCategoriesNBT()
|
|
|
|
|
), player);
|
|
|
|
|
|
2025-01-30 09:22:43 -05:00
|
|
|
// 4) Workbench Recipes
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
2025-01-30 09:22:43 -05:00
|
|
|
EnumSyncType.WORKBENCH_RECIPES,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
workbenchNBT()
|
|
|
|
|
), player);
|
|
|
|
|
|
|
|
|
|
// 5) Carpentry Recipes
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
2025-01-30 09:22:43 -05:00
|
|
|
EnumSyncType.CARPENTRY_RECIPES,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
carpentryNBT()
|
|
|
|
|
), player);
|
|
|
|
|
|
2025-02-10 02:44:28 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
|
|
|
|
EnumSyncType.ANVIL_RECIPES,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
anvilNBT()
|
|
|
|
|
), player);
|
|
|
|
|
|
2025-02-10 16:38:50 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
|
|
|
|
EnumSyncType.CUSTOM_EFFECTS,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
customEffectsNBT()
|
|
|
|
|
), player);
|
|
|
|
|
|
2025-01-29 18:25:34 -05:00
|
|
|
DBCAddon.instance.syncPlayer(player);
|
|
|
|
|
syncPlayerData(player, false);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-30 09:22:43 -05:00
|
|
|
public static NBTTagCompound workbenchNBT(){
|
|
|
|
|
RecipeController controller = RecipeController.Instance;
|
|
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
for(RecipeCarpentry recipe : controller.globalRecipes.values()){
|
|
|
|
|
list.appendTag(recipe.writeNBT());
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("recipes", list);
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static NBTTagCompound carpentryNBT(){
|
|
|
|
|
RecipeController controller = RecipeController.Instance;
|
|
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
for(RecipeCarpentry recipe : controller.carpentryRecipes.values()){
|
|
|
|
|
list.appendTag(recipe.writeNBT());
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("recipes", list);
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-10 02:44:28 -05:00
|
|
|
public static NBTTagCompound anvilNBT(){
|
|
|
|
|
RecipeController controller = RecipeController.Instance;
|
|
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
for(RecipeAnvil recipe : controller.anvilRecipes.values()){
|
|
|
|
|
list.appendTag(recipe.writeNBT());
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("recipes", list);
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 18:25:34 -05:00
|
|
|
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()){
|
2025-01-29 19:43:45 -05:00
|
|
|
NBTTagCompound questCompound = new NBTTagCompound();
|
2025-01-29 18:25:34 -05:00
|
|
|
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()));
|
2025-01-29 19:43:45 -05:00
|
|
|
categoryList.appendTag(questCompound);
|
2025-01-29 18:25:34 -05:00
|
|
|
}
|
|
|
|
|
compound.setTag("DialogCategories", categoryList);
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 19:43:45 -05:00
|
|
|
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()));
|
|
|
|
|
categoryList.appendTag(questCompound);
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("QuestCategories", categoryList);
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-10 16:38:50 -05:00
|
|
|
public static NBTTagCompound customEffectsNBT(){
|
|
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
2025-02-12 03:15:28 -05:00
|
|
|
for (CustomEffect effect : CustomEffectController.getInstance().getCustomEffects().values()) {
|
2025-02-10 16:38:50 -05:00
|
|
|
list.appendTag(effect.writeToNBT(false));
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("Data", list);
|
|
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 18:25:34 -05:00
|
|
|
public static void syncPlayerData(EntityPlayerMP player, boolean update){
|
|
|
|
|
PlayerData data = PlayerData.get(player);
|
|
|
|
|
if(data != null){
|
|
|
|
|
if(update){
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
2025-01-29 18:25:34 -05:00
|
|
|
EnumSyncType.PLAYERDATA,
|
|
|
|
|
EnumSyncAction.UPDATE,
|
|
|
|
|
-1,
|
|
|
|
|
data.getSyncNBT())
|
|
|
|
|
, player);
|
|
|
|
|
} else {
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
2025-01-29 18:25:34 -05:00
|
|
|
EnumSyncType.PLAYERDATA,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
data.getSyncNBTFull()), player);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void syncRemove(EnumSyncType enumSyncType, int id){
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToAll(new SyncPacket(
|
2025-01-29 18:25:34 -05:00
|
|
|
enumSyncType,
|
|
|
|
|
EnumSyncAction.REMOVE,
|
|
|
|
|
id,
|
|
|
|
|
new NBTTagCompound()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void syncAllDialogs() {
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToAll(new SyncPacket(
|
2025-01-29 18:25:34 -05:00
|
|
|
EnumSyncType.DIALOG_CATEGORY,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
dialogCategoriesNBT()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void syncAllQuests() {
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToAll(new SyncPacket(
|
2025-01-29 18:25:34 -05:00
|
|
|
EnumSyncType.QUEST_CATEGORY,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
questCategoriesNBT()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-30 09:22:43 -05:00
|
|
|
public static void syncAllWorkbenchRecipes() {
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToAll(new SyncPacket(
|
2025-01-30 09:22:43 -05:00
|
|
|
EnumSyncType.WORKBENCH_RECIPES,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
workbenchNBT()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void syncAllCarpentryRecipes() {
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToAll(new SyncPacket(
|
2025-01-30 09:22:43 -05:00
|
|
|
EnumSyncType.CARPENTRY_RECIPES,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
carpentryNBT()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-10 02:44:28 -05:00
|
|
|
public static void syncAllAnvilRecipes() {
|
|
|
|
|
PacketHandler.Instance.sendToAll(new SyncPacket(
|
|
|
|
|
EnumSyncType.ANVIL_RECIPES,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
anvilNBT()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-10 16:38:50 -05:00
|
|
|
public static void syncAllCustomEffects() {
|
|
|
|
|
PacketHandler.Instance.sendToAll(new SyncPacket(
|
|
|
|
|
EnumSyncType.CUSTOM_EFFECTS,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
|
|
|
|
customEffectsNBT()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 18:25:34 -05:00
|
|
|
@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;
|
|
|
|
|
}
|
2025-01-30 09:22:43 -05:00
|
|
|
case WORKBENCH_RECIPES: {
|
|
|
|
|
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
|
|
|
|
if(list == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < list.tagCount(); i++)
|
|
|
|
|
{
|
|
|
|
|
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
|
|
|
|
|
RecipeController.syncRecipes.put(recipe.id,recipe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes);
|
|
|
|
|
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CARPENTRY_RECIPES: {
|
|
|
|
|
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
|
|
|
|
if(list == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < list.tagCount(); i++)
|
|
|
|
|
{
|
|
|
|
|
RecipeCarpentry recipe = RecipeCarpentry.read(list.getCompoundTagAt(i));
|
|
|
|
|
RecipeController.syncRecipes.put(recipe.id,recipe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes;
|
|
|
|
|
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-02-10 02:44:28 -05:00
|
|
|
case ANVIL_RECIPES: {
|
|
|
|
|
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
|
|
|
|
if(list == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < list.tagCount(); i++)
|
|
|
|
|
{
|
|
|
|
|
RecipeAnvil recipe = RecipeAnvil.read(list.getCompoundTagAt(i));
|
|
|
|
|
RecipeController.syncAnvilRecipes.put(recipe.id, recipe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RecipeController.Instance.anvilRecipes = RecipeController.syncAnvilRecipes;
|
|
|
|
|
RecipeController.syncAnvilRecipes = new HashMap<Integer, RecipeAnvil>();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-02-10 16:38:50 -05:00
|
|
|
case CUSTOM_EFFECTS: {
|
|
|
|
|
NBTTagList list = fullCompound.getTagList("Data", 10);
|
2025-02-12 03:15:28 -05:00
|
|
|
CustomEffectController ce = CustomEffectController.getInstance();
|
|
|
|
|
ce.customEffectsSync.clear();
|
2025-02-10 16:38:50 -05:00
|
|
|
for (int i = 0; i < list.tagCount(); i++) {
|
|
|
|
|
CustomEffect effect = new CustomEffect();
|
|
|
|
|
effect.readFromNBT(list.getCompoundTagAt(i));
|
2025-02-10 17:24:26 -05:00
|
|
|
ClientCacheHandler.getImageData(effect.icon);
|
2025-02-12 03:15:28 -05:00
|
|
|
ce.customEffectsSync.put(effect.id, effect);
|
2025-02-10 16:38:50 -05:00
|
|
|
}
|
|
|
|
|
|
2025-02-12 03:15:28 -05:00
|
|
|
ce.getCustomEffects().clear();
|
|
|
|
|
ce.getCustomEffects().putAll(ce.customEffectsSync);
|
|
|
|
|
ce.customEffectsSync.clear();
|
2025-02-10 16:38:50 -05:00
|
|
|
break;
|
|
|
|
|
}
|
2025-01-29 18:25:34 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
2025-02-10 16:38:50 -05:00
|
|
|
case CUSTOM_EFFECTS: {
|
|
|
|
|
CustomEffect effect = new CustomEffect();
|
|
|
|
|
effect.readFromNBT(compound);
|
|
|
|
|
ClientCacheHandler.getImageData(effect.icon);
|
|
|
|
|
|
2025-02-12 03:15:28 -05:00
|
|
|
CustomEffectController.Instance.getCustomEffects().put(effect.id, effect);
|
2025-02-10 16:38:50 -05:00
|
|
|
break;
|
|
|
|
|
}
|
2025-01-29 18:25:34 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void syncUpdate(EnumSyncType type, int cat, NBTTagCompound compound) {
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToAll(new SyncPacket(
|
2025-01-29 18:25:34 -05:00
|
|
|
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;
|
2025-02-10 16:38:50 -05:00
|
|
|
case CUSTOM_EFFECTS:
|
2025-02-12 03:15:28 -05:00
|
|
|
CustomEffectController.Instance.getCustomEffects().remove(id);
|
2025-02-10 16:38:50 -05:00
|
|
|
break;
|
2025-01-29 18:25:34 -05:00
|
|
|
}
|
|
|
|
|
}
|
2025-02-10 21:41:54 -05:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-29 18:25:34 -05:00
|
|
|
}
|