SyncController OVERHAUL PHASE #1:

- Refactored EnumSyncType into object based SyncType registry, so other mods can register their own types
This commit is contained in:
bigguy345 committed 2026-03-31 19:59:53 +02:00
1 parent b2c279feeb
commit 48281c8d34
13 files changed
+673 -558

No files matched your search

@@ -10,7 +10,7 @@ import kamkeel.npcs.entity.EntityEnergyDome;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumSoundOperation;
import kamkeel.npcs.network.enums.EnumSyncAction;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.enums.SyncType;
import kamkeel.npcs.network.packets.data.ClonerPacket;
import kamkeel.npcs.network.packets.data.MarkDataPacket;
import kamkeel.npcs.network.packets.data.SoundManagementPacket;
@@ -255,19 +255,19 @@ public class ServerEventsHandler {
if (block == Blocks.crafting_table && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.WORKBENCH_RECIPES,
SyncType.WORKBENCH_RECIPES,
EnumSyncAction.RELOAD,
-1,
SyncController.getCurrentRevision(EnumSyncType.WORKBENCH_RECIPES),
SyncController.getCurrentRevision(SyncType.WORKBENCH_RECIPES),
SyncController.workbenchNBT()
), (EntityPlayerMP) player);
}
if (block == CustomItems.carpentyBench && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
PacketHandler.Instance.sendToPlayer(new SyncPacket(
EnumSyncType.CARPENTRY_RECIPES,
SyncType.CARPENTRY_RECIPES,
EnumSyncAction.RELOAD,
-1,
SyncController.getCurrentRevision(EnumSyncType.CARPENTRY_RECIPES),
SyncController.getCurrentRevision(SyncType.CARPENTRY_RECIPES),
SyncController.carpentryNBT()
), (EntityPlayerMP) player);
}
@@ -1,6 +1,6 @@
package noppes.npcs.client;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.enums.SyncType;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.controllers.MusicController;
@@ -18,8 +18,8 @@ import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.util.CacheHashMap;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
@@ -32,14 +32,14 @@ public class ClientCacheHandler {
private static String activeServerKey = "";
private static String lastServerKey = "";
private static final Map<String, EnumMap<EnumSyncType, Integer>> clientRevisionCache = new HashMap<>();
private static final Map<String, Map<SyncType, Integer>> clientRevisionCache = new HashMap<>();
public static Party party;
public static boolean allowProfiles = true;
public static boolean allowParties = true;
public static void setActiveServer(String serverKey, EnumMap<EnumSyncType, Integer> serverRevisions) {
public static void setActiveServer(String serverKey, Map<SyncType, Integer> serverRevisions) {
String normalizedKey = serverKey == null ? "" : serverKey;
String previousKey = activeServerKey == null ? "" : activeServerKey;
lastServerKey = previousKey;
@@ -54,9 +54,9 @@ public class ClientCacheHandler {
return;
}
EnumMap<EnumSyncType, Integer> cached = clientRevisionCache.computeIfAbsent(
Map<SyncType, Integer> cached = clientRevisionCache.computeIfAbsent(
activeServerKey,
ignored -> new EnumMap<>(EnumSyncType.class)
ignored -> new LinkedHashMap<>()
);
if (serverRevisions != null && !serverRevisions.isEmpty()) {
cached.keySet().retainAll(serverRevisions.keySet());
@@ -67,19 +67,19 @@ public class ClientCacheHandler {
return lastServerKey == null ? "" : lastServerKey;
}
public static EnumMap<EnumSyncType, Integer> getCachedRevisionsForServer(String serverKey) {
public static Map<SyncType, Integer> getCachedRevisionsForServer(String serverKey) {
String key = serverKey == null ? "" : serverKey;
if (key.isEmpty()) {
return new EnumMap<>(EnumSyncType.class);
return new LinkedHashMap<>();
}
EnumMap<EnumSyncType, Integer> revisions = clientRevisionCache.get(key);
Map<SyncType, Integer> revisions = clientRevisionCache.get(key);
if (revisions == null) {
return new EnumMap<>(EnumSyncType.class);
return new LinkedHashMap<>();
}
return new EnumMap<>(revisions);
return new LinkedHashMap<>(revisions);
}
public static void updateClientRevision(EnumSyncType type, int revision) {
public static void updateClientRevision(SyncType type, int revision) {
if (revision < 0) {
return;
}
@@ -87,9 +87,9 @@ public class ClientCacheHandler {
if (key.isEmpty()) {
return;
}
EnumMap<EnumSyncType, Integer> revisions = clientRevisionCache.computeIfAbsent(
Map<SyncType, Integer> revisions = clientRevisionCache.computeIfAbsent(
key,
ignored -> new EnumMap<>(EnumSyncType.class)
ignored -> new LinkedHashMap<>()
);
revisions.put(type, revision);
}
@@ -126,14 +126,11 @@ public class ClientCacheHandler {
ClientCacheHandler.playerAnimations.clear();
ProfileClientConfig.reset();
// Clear Texture Caches
GuiSoundSelection.cachedDomains.clear();
GuiTextureSelection.cachedTextures.clear();
// Clear music/bard sounds
MusicController.Instance.stopAllSounds();
// Clear Quest Tracker
HudComponent component = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker);
if (component != null) {
component.loadData(new NBTTagCompound());
@@ -146,7 +143,6 @@ public class ClientCacheHandler {
ClientCacheHandler.customOverlays.clear();
ClientCacheHandler.skinOverlays.clear();
// Clear Texture Caches
GuiSoundSelection.cachedDomains.clear();
GuiTextureSelection.cachedTextures.clear();
}
@@ -1,7 +1,7 @@
package noppes.npcs.controllers;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.enums.SyncType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
@@ -128,7 +128,7 @@ public class CustomEffectController implements ICustomEffectHandler {
file.delete();
}
categoryManager.removeItem(id);
SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID());
SyncController.syncRemove(SyncType.CUSTOM_EFFECTS, foundEffect.getID());
saveEffectLoadMap();
}
}
@@ -700,7 +700,7 @@ public class CustomEffectController implements ICustomEffectHandler {
file2.delete();
file.renameTo(file2);
nbtTagCompound.removeTag("ScriptData");
SyncController.syncUpdate(EnumSyncType.CUSTOM_EFFECTS, -1, nbtTagCompound);
SyncController.syncUpdate(SyncType.CUSTOM_EFFECTS, -1, nbtTagCompound);
} catch (Exception e) {
LogWriter.except(e);
}
@@ -1,7 +1,7 @@
package noppes.npcs.controllers;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.enums.SyncType;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -239,7 +239,7 @@ public class DialogController implements IDialogHandler {
dir.mkdirs();
}
categories.put(category.id, category);
SyncController.syncUpdate(EnumSyncType.DIALOG_CATEGORY, -1, SyncController.updateDialogCat(category));
SyncController.syncUpdate(SyncType.DIALOG_CATEGORY, -1, SyncController.updateDialogCat(category));
}
public void removeCategory(int category) {
@@ -252,7 +252,7 @@ public class DialogController implements IDialogHandler {
for (int dia : cat.dialogs.keySet())
dialogs.remove(dia);
categories.remove(category);
SyncController.syncRemove(EnumSyncType.DIALOG_CATEGORY, category);
SyncController.syncRemove(SyncType.DIALOG_CATEGORY, category);
}
private boolean containsCategoryName(String name) {
@@ -302,7 +302,7 @@ public class DialogController implements IDialogHandler {
if (file2.exists())
file2.delete();
file.renameTo(file2);
SyncController.syncUpdate(EnumSyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound()));
SyncController.syncUpdate(SyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound()));
} catch (Exception e) {
LogWriter.except(e);
}
@@ -316,7 +316,7 @@ public class DialogController implements IDialogHandler {
return;
category.dialogs.remove(dialog.id);
dialogs.remove(dialog.id);
SyncController.syncRemove(EnumSyncType.DIALOG, dialog.id);
SyncController.syncRemove(SyncType.DIALOG, dialog.id);
}
private File getDir() {
@@ -1,7 +1,7 @@
package noppes.npcs.controllers;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.enums.SyncType;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -159,7 +159,7 @@ public class FactionController implements IFactionHandler {
NBTTagCompound facCompound = new NBTTagCompound();
faction.writeNBT(facCompound);
SyncController.syncUpdate(EnumSyncType.FACTION, -1, facCompound);
SyncController.syncUpdate(SyncType.FACTION, -1, facCompound);
saveFactions();
}
@@ -195,7 +195,7 @@ public class FactionController implements IFactionHandler {
} else {
this.saveFactions();
faction.id = -1;
SyncController.syncRemove(EnumSyncType.FACTION, id);
SyncController.syncRemove(SyncType.FACTION, id);
return faction;
}
} else {
@@ -1,7 +1,7 @@
package noppes.npcs.controllers;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.enums.SyncType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
@@ -275,7 +275,7 @@ public class MagicController implements IMagicHandler {
NBTTagCompound magicCompound = new NBTTagCompound();
mag.writeNBT(magicCompound);
SyncController.syncUpdate(EnumSyncType.MAGIC, -1, magicCompound);
SyncController.syncUpdate(SyncType.MAGIC, -1, magicCompound);
saveMagicData();
}
@@ -283,7 +283,7 @@ public class MagicController implements IMagicHandler {
public void removeMagic(int magicID) {
if (magics.containsKey(magicID)) {
magics.remove(magicID);
SyncController.syncRemove(EnumSyncType.MAGIC, magicID);
SyncController.syncRemove(SyncType.MAGIC, magicID);
saveMagicData();
}
}
@@ -345,7 +345,7 @@ public class MagicController implements IMagicHandler {
NBTTagCompound cycleCompound = new NBTTagCompound();
cycle.writeNBT(cycleCompound);
SyncController.syncUpdate(EnumSyncType.MAGIC_CYCLE, -1, cycleCompound);
SyncController.syncUpdate(SyncType.MAGIC_CYCLE, -1, cycleCompound);
saveMagicData();
}
@@ -353,7 +353,7 @@ public class MagicController implements IMagicHandler {
public void removeCycle(int categoryId) {
if (cycles.containsKey(categoryId)) {
cycles.remove(categoryId);
SyncController.syncRemove(EnumSyncType.MAGIC_CYCLE, categoryId);
SyncController.syncRemove(SyncType.MAGIC_CYCLE, categoryId);
saveMagicData();
}
}
@@ -1,7 +1,7 @@
package noppes.npcs.controllers;
import kamkeel.npcs.controllers.SyncController;
import kamkeel.npcs.network.enums.EnumSyncType;
import kamkeel.npcs.network.enums.SyncType;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -158,7 +158,7 @@ public class QuestController implements IQuestHandler {
for (int dia : cat.quests.keySet())
quests.remove(dia);
categories.remove(category);
SyncController.syncRemove(EnumSyncType.QUEST_CATEGORY, category);
SyncController.syncRemove(SyncType.QUEST_CATEGORY, category);
}
public void saveCategory(QuestCategory category) {
@@ -188,7 +188,7 @@ public class QuestController implements IQuestHandler {
dir.mkdirs();
}
categories.put(category.id, category);
SyncController.syncUpdate(EnumSyncType.QUEST_CATEGORY, -1, SyncController.updateQuestCat(category));
SyncController.syncUpdate(SyncType.QUEST_CATEGORY, -1, SyncController.updateQuestCat(category));
}
private boolean containsCategoryName(String name) {
@@ -245,7 +245,7 @@ public class QuestController implements IQuestHandler {
if (file2.exists())
file2.delete();
file.renameTo(file2);
SyncController.syncUpdate(EnumSyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound()));
SyncController.syncUpdate(SyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound()));
} catch (Exception e) {
e.printStackTrace();
}