mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 04:57:27 +00:00
Sync Magic
This commit is contained in:
1 parent
b060daab44
commit
080fa62771
3 files changed
+106
-7
No files matched your search
@@ -81,6 +81,20 @@ public class SyncController {
|
||||
customEffectsNBT()
|
||||
), player);
|
||||
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.MAGIC,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
magicsNBT()
|
||||
), player);
|
||||
|
||||
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
||||
EnumSyncType.MAGIC_CYCLE,
|
||||
EnumSyncAction.RELOAD,
|
||||
-1,
|
||||
magicCyclesNBT()
|
||||
), player);
|
||||
|
||||
DBCAddon.instance.syncPlayer(player);
|
||||
syncPlayerData(player, false);
|
||||
}
|
||||
@@ -176,6 +190,30 @@ public class SyncController {
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound magicsNBT(){
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (Magic magic : MagicController.getInstance().magics.values()) {
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
magic.writeNBT(magicCompound);
|
||||
list.appendTag(magicCompound);
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static NBTTagCompound magicCyclesNBT(){
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
NBTTagCompound cycleCompound = new NBTTagCompound();
|
||||
cycle.writeNBT(cycleCompound);
|
||||
list.appendTag(cycleCompound);
|
||||
}
|
||||
compound.setTag("Data", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static void syncPlayerData(EntityPlayerMP player, boolean update){
|
||||
PlayerData data = PlayerData.get(player);
|
||||
if(data != null){
|
||||
@@ -353,6 +391,36 @@ public class SyncController {
|
||||
ClientCacheHandler.playerData.setSyncNBTFull(fullCompound);
|
||||
break;
|
||||
}
|
||||
case MAGIC: {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
MagicController mc = MagicController.getInstance();
|
||||
mc.magicSync.clear();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
Magic magic = new Magic();
|
||||
magic.readNBT(list.getCompoundTagAt(i));
|
||||
mc.magicSync.put(magic.id, magic);
|
||||
}
|
||||
|
||||
mc.magics.clear();
|
||||
mc.magics.putAll(mc.magicSync);
|
||||
mc.magicSync.clear();
|
||||
break;
|
||||
}
|
||||
case MAGIC_CYCLE: {
|
||||
NBTTagList list = fullCompound.getTagList("Data", 10);
|
||||
MagicController mc = MagicController.getInstance();
|
||||
mc.cyclesSync.clear();
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
cycle.readNBT(list.getCompoundTagAt(i));
|
||||
mc.cyclesSync.put(cycle.id, cycle);
|
||||
}
|
||||
|
||||
mc.cycles.clear();
|
||||
mc.cycles.putAll(mc.cyclesSync);
|
||||
mc.cyclesSync.clear();
|
||||
break;
|
||||
}
|
||||
case WORKBENCH_RECIPES: {
|
||||
NBTTagList list = fullCompound.getTagList("recipes", 10);
|
||||
if(list == null)
|
||||
@@ -483,6 +551,18 @@ public class SyncController {
|
||||
DialogController.Instance.categories.put(category.id, category);
|
||||
break;
|
||||
}
|
||||
case MAGIC_CYCLE: {
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
cycle.readNBT(compound);
|
||||
MagicController.getInstance().cycles.put(cycle.id, cycle);
|
||||
break;
|
||||
}
|
||||
case MAGIC: {
|
||||
Magic magic = new Magic();
|
||||
magic.readNBT(compound);
|
||||
MagicController.getInstance().magics.put(magic.id, magic);
|
||||
break;
|
||||
}
|
||||
case PLAYERDATA: {
|
||||
ClientCacheHandler.playerData.setSyncNBT(compound);
|
||||
break;
|
||||
@@ -563,6 +643,13 @@ public class SyncController {
|
||||
}
|
||||
break;
|
||||
case MAGIC:
|
||||
for(MagicCycle cycle : MagicController.getInstance().cycles.values()){
|
||||
cycle.associations.remove(id);
|
||||
}
|
||||
MagicController.getInstance().cycles.remove(id);
|
||||
break;
|
||||
case MAGIC_CYCLE:
|
||||
MagicController.getInstance().cycles.remove(id);
|
||||
break;
|
||||
case CUSTOM_EFFECTS:
|
||||
CustomEffectController.Instance.getCustomEffects().remove(id);
|
||||
|
||||
@@ -8,6 +8,7 @@ public enum EnumSyncType {
|
||||
QUEST_CATEGORY,
|
||||
PLAYERDATA,
|
||||
MAGIC,
|
||||
MAGIC_CYCLE,
|
||||
WORKBENCH_RECIPES,
|
||||
CARPENTRY_RECIPES,
|
||||
ANVIL_RECIPES,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.network.enums.EnumSyncType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -217,12 +219,18 @@ public class MagicController {
|
||||
mag.name += "_";
|
||||
}
|
||||
magics.put(mag.id, mag);
|
||||
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
mag.writeNBT(magicCompound);
|
||||
SyncController.syncUpdate(EnumSyncType.MAGIC, -1, magicCompound);
|
||||
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
public void removeMagic(int magicID) {
|
||||
if (magics.containsKey(magicID)) {
|
||||
magics.remove(magicID);
|
||||
SyncController.syncRemove(EnumSyncType.MAGIC, magicID);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
@@ -281,17 +289,18 @@ public class MagicController {
|
||||
cycle.name += "_";
|
||||
}
|
||||
cycles.put(cycle.id, cycle);
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
// Alternatively, if you prefer an addCycle method:
|
||||
public void addCycle(MagicCycle cycle) {
|
||||
saveCycle(cycle);
|
||||
NBTTagCompound cycleCompound = new NBTTagCompound();
|
||||
cycle.writeNBT(cycleCompound);
|
||||
SyncController.syncUpdate(EnumSyncType.MAGIC_CYCLE, -1, cycleCompound);
|
||||
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
public void removeCycle(int categoryId) {
|
||||
if (cycles.containsKey(categoryId)) {
|
||||
cycles.remove(categoryId);
|
||||
SyncController.syncRemove(EnumSyncType.MAGIC_CYCLE, categoryId);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
@@ -313,13 +322,15 @@ public class MagicController {
|
||||
assoc.index = index;
|
||||
assoc.priority = priority;
|
||||
cat.associations.put(magicId, assoc);
|
||||
saveMagicData();
|
||||
|
||||
saveCycle(cat);
|
||||
}
|
||||
|
||||
public void removeMagicFromCycle(int magicId, int cycleId) {
|
||||
MagicCycle cat = cycles.get(cycleId);
|
||||
if (cat == null) return;
|
||||
cat.associations.remove(magicId);
|
||||
saveMagicData();
|
||||
|
||||
saveCycle(cat);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user