mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 04:57:27 +00:00
Magic Packet Fixes
This commit is contained in:
1 parent
c2fa74c541
commit
4e6d6b7082
13 files changed
+177
-54
No files matched your search
@@ -195,5 +195,11 @@ public enum EnumRequestPacket {
|
||||
ProfileCreate,
|
||||
ProfileRemove,
|
||||
ProfileRename,
|
||||
MagicCycleRemove, MagicCycleSave, MagicGetAll, MagicRemove, MagicSave, ProfileChange
|
||||
ProfileChange,
|
||||
|
||||
MagicCycleRemove,
|
||||
MagicCycleSave,
|
||||
MagicGetAll,
|
||||
MagicRemove,
|
||||
MagicSave
|
||||
}
|
||||
+7
-2
@@ -7,6 +7,7 @@ import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -29,6 +30,11 @@ public class MagicCycleRemovePacket extends AbstractPacket {
|
||||
return EnumRequestPacket.MagicCycleRemove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.GLOBAL_MAGIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
@@ -46,7 +52,6 @@ public class MagicCycleRemovePacket extends AbstractPacket {
|
||||
return;
|
||||
|
||||
int id = in.readInt();
|
||||
MagicController.getInstance().cycles.remove(id);
|
||||
MagicController.getInstance().saveMagicData();
|
||||
MagicController.getInstance().removeCycle(id);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -37,6 +38,11 @@ public class MagicCycleSavePacket extends AbstractPacket {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.GLOBAL_MAGIC;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
@@ -50,7 +56,6 @@ public class MagicCycleSavePacket extends AbstractPacket {
|
||||
NBTTagCompound comp = ByteBufUtils.readNBT(in);
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
cycle.readNBT(comp);
|
||||
MagicController.getInstance().cycles.put(cycle.id, cycle);
|
||||
MagicController.getInstance().saveMagicData();
|
||||
MagicController.getInstance().saveCycle(cycle);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class MagicGetAllPacket extends AbstractPacket {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
StringBuilder cycleNames = new StringBuilder();
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
cycleNames.append(cycle.title).append(",");
|
||||
cycleNames.append(cycle.name).append(",");
|
||||
}
|
||||
compound.setString("CycleNames", cycleNames.toString());
|
||||
// Build comma-separated list of magic names.
|
||||
|
||||
@@ -7,6 +7,7 @@ import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -34,6 +35,11 @@ public class MagicRemovePacket extends AbstractPacket {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.GLOBAL_MAGIC;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
@@ -46,7 +52,6 @@ public class MagicRemovePacket extends AbstractPacket {
|
||||
return;
|
||||
|
||||
int id = in.readInt();
|
||||
MagicController.getInstance().magics.remove(id);
|
||||
MagicController.getInstance().saveMagicData();
|
||||
MagicController.getInstance().removeMagic(id);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -37,6 +38,11 @@ public class MagicSavePacket extends AbstractPacket {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.GLOBAL_MAGIC;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.gui.util.GuiDiagram;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.constants.EnumDiagramLayout;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -32,7 +33,7 @@ public class GuiMagicMap extends GuiDiagram {
|
||||
for (Magic magic : MagicController.getInstance().magics.values()) {
|
||||
magics.add(magic);
|
||||
}
|
||||
setLayout(DiagramLayout.CIRCULAR_MANUAL);
|
||||
setLayout(EnumDiagramLayout.CIRCULAR_MANUAL);
|
||||
this.setCurvedArrows(true);
|
||||
this.setCurveAngle(-20);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import noppes.npcs.controllers.data.MagicCycle;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons;
|
||||
|
||||
@@ -330,7 +329,7 @@ public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListen
|
||||
if (scroll.id == 0) { // Left scroll: cycles
|
||||
String cycleName = scroll.getSelected();
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
if (cycle.title.equals(cycleName)) {
|
||||
if (cycle.name.equals(cycleName)) {
|
||||
selectedCycle = cycle;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class SubGuiMagicCycleEdit extends SubGuiInterface implements ITextfieldL
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
addLabel(new GuiNpcLabel(0, "Cycle: " + cycle.title, guiLeft + 4, guiTop + 4));
|
||||
addLabel(new GuiNpcLabel(0, "Cycle: " + cycle.name, guiLeft + 4, guiTop + 4));
|
||||
|
||||
// Build list of associations in the cycle (format: "MagicID: X | Index: Y | Priority: Z")
|
||||
assocList.clear();
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import noppes.npcs.constants.EnumDiagramLayout;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@@ -54,17 +55,12 @@ public abstract class GuiDiagram extends Gui {
|
||||
protected boolean useColorScaling = true; // Scale connection color based on a percentage
|
||||
|
||||
// --- Layout Options ---
|
||||
public enum DiagramLayout {
|
||||
CIRCULAR, SQUARE, TREE, GENERATED,
|
||||
CIRCULAR_MANUAL, SQUARE_MANUAL, TREE_MANUAL,
|
||||
CHART
|
||||
}
|
||||
protected DiagramLayout layout = DiagramLayout.CIRCULAR; // Default layout
|
||||
protected EnumDiagramLayout layout = EnumDiagramLayout.CIRCULAR; // Default layout
|
||||
|
||||
/**
|
||||
* Sets the layout type and invalidates caches.
|
||||
*/
|
||||
public void setLayout(DiagramLayout layout) {
|
||||
public void setLayout(EnumDiagramLayout layout) {
|
||||
this.layout = layout;
|
||||
invalidateCache();
|
||||
}
|
||||
@@ -160,7 +156,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
*/
|
||||
protected Map<Integer, Point> calculatePositions() {
|
||||
if (cachedPositions != null) return cachedPositions;
|
||||
if (layout == DiagramLayout.CHART) {
|
||||
if (layout == EnumDiagramLayout.CHART) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
switch (layout) {
|
||||
@@ -964,7 +960,7 @@ public abstract class GuiDiagram extends Gui {
|
||||
boolean allowInput = (parent == null || !parent.hasSubGui());
|
||||
if (allowInput && isWithin(mouseX, mouseY) && !subGui)
|
||||
handleMouseScroll(Mouse.getDWheel());
|
||||
if (layout == DiagramLayout.CHART) {
|
||||
if (layout == EnumDiagramLayout.CHART) {
|
||||
drawChartDiagram(mouseX, mouseY, subGui);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
public enum EnumDiagramLayout {
|
||||
CIRCULAR("diagram.circular"),
|
||||
SQUARE("diagram.square"),
|
||||
TREE("diagram.tree"),
|
||||
GENERATED("diagram.generated"),
|
||||
CIRCULAR_MANUAL("diagram.circular_manual"),
|
||||
SQUARE_MANUAL("diagram.square_manual"),
|
||||
TREE_MANUAL("diagram.tree_manual"),
|
||||
CHART("diagram.chart");
|
||||
|
||||
private String lang;
|
||||
EnumDiagramLayout(String langName){
|
||||
this.lang = langName;
|
||||
}
|
||||
|
||||
public String getLang(){
|
||||
return lang;
|
||||
}
|
||||
}
|
||||
@@ -142,9 +142,8 @@ public class MagicController {
|
||||
public void loadMagic(DataInputStream stream) throws IOException {
|
||||
NBTTagCompound compound = CompressedStreamTools.read(stream);
|
||||
lastUsedMagicID = compound.getInteger("lastID");
|
||||
lastUsedCycleID = compound.getInteger("lastCatID");
|
||||
lastUsedCycleID = compound.getInteger("lastCycleID");
|
||||
|
||||
// Load magics
|
||||
magics.clear();
|
||||
NBTTagList magicList = compound.getTagList("Magics", 10);
|
||||
for (int i = 0; i < magicList.tagCount(); i++) {
|
||||
@@ -154,14 +153,13 @@ public class MagicController {
|
||||
magics.put(mag.id, mag);
|
||||
}
|
||||
|
||||
// Load categories
|
||||
cycles.clear();
|
||||
NBTTagList catList = compound.getTagList("Cycles", 10);
|
||||
for (int i = 0; i < catList.tagCount(); i++) {
|
||||
NBTTagCompound catCompound = catList.getCompoundTagAt(i);
|
||||
MagicCycle cat = new MagicCycle();
|
||||
cat.readNBT(catCompound);
|
||||
cycles.put(cat.id, cat);
|
||||
NBTTagList cycleList = compound.getTagList("Cycles", 10);
|
||||
for (int i = 0; i < cycleList.tagCount(); i++) {
|
||||
NBTTagCompound catCompound = cycleList.getCompoundTagAt(i);
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
cycle.readNBT(catCompound);
|
||||
cycles.put(cycle.id, cycle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,9 +191,12 @@ public class MagicController {
|
||||
File fileOld = new File(saveDir, "magic.dat_old");
|
||||
File fileCurrent = new File(saveDir, "magic.dat");
|
||||
CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(fileNew));
|
||||
if (fileOld.exists()) fileOld.delete();
|
||||
if (fileOld.exists())
|
||||
fileOld.delete();
|
||||
fileCurrent.renameTo(fileOld);
|
||||
if (fileCurrent.exists()) fileCurrent.delete();
|
||||
|
||||
if (fileCurrent.exists())
|
||||
fileCurrent.delete();
|
||||
fileNew.renameTo(fileCurrent);
|
||||
if (fileNew.exists()) fileNew.delete();
|
||||
} catch (Exception e) {
|
||||
@@ -203,6 +204,7 @@ public class MagicController {
|
||||
}
|
||||
}
|
||||
|
||||
// Enforce unique names and IDs for Magics
|
||||
public void saveMagic(Magic mag) {
|
||||
if (mag.id < 0) {
|
||||
mag.id = getUnusedId();
|
||||
@@ -218,6 +220,13 @@ public class MagicController {
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
public void removeMagic(int magicID) {
|
||||
if (magics.containsKey(magicID)) {
|
||||
magics.remove(magicID);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
|
||||
public int getUnusedId() {
|
||||
if (lastUsedMagicID == 0) {
|
||||
for (int id : magics.keySet())
|
||||
@@ -231,35 +240,56 @@ public class MagicController {
|
||||
public boolean hasName(String newName) {
|
||||
if (newName.trim().isEmpty()) return true;
|
||||
for (Magic mag : magics.values())
|
||||
if (mag.name.equals(newName))
|
||||
if (mag.name.equalsIgnoreCase(newName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// === Category management methods ===
|
||||
// === Cycle Management Methods ===
|
||||
|
||||
public void addCycle(MagicCycle category) {
|
||||
if (category.id < 0) {
|
||||
lastUsedCycleID++;
|
||||
category.id = lastUsedCycleID;
|
||||
} else {
|
||||
while (containsCategoryName(category.title))
|
||||
category.title += "_";
|
||||
// Returns a new unique cycle ID
|
||||
public int getUnusedCycleId() {
|
||||
if (lastUsedCycleID == 0) {
|
||||
for (int id : cycles.keySet())
|
||||
if (id > lastUsedCycleID)
|
||||
lastUsedCycleID = id;
|
||||
}
|
||||
cycles.put(category.id, category);
|
||||
saveMagicData();
|
||||
lastUsedCycleID++;
|
||||
return lastUsedCycleID;
|
||||
}
|
||||
|
||||
// Checks if a cycle title already exists (case-insensitive)
|
||||
public boolean containsCategoryName(String title) {
|
||||
title = title.toLowerCase();
|
||||
for (MagicCycle cat : cycles.values()) {
|
||||
if (cat.title.toLowerCase().equals(title))
|
||||
if (cat.name.toLowerCase().equals(title))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeCategory(int categoryId) {
|
||||
// Saves a cycle ensuring a unique title and ID
|
||||
public void saveCycle(MagicCycle cycle) {
|
||||
if (cycle.id < 0) {
|
||||
cycle.id = getUnusedCycleId();
|
||||
while (containsCategoryName(cycle.name))
|
||||
cycle.name += "_";
|
||||
} else {
|
||||
MagicCycle existing = cycles.get(cycle.id);
|
||||
if (existing != null && !existing.name.equals(cycle.name))
|
||||
while (containsCategoryName(cycle.name))
|
||||
cycle.name += "_";
|
||||
}
|
||||
cycles.put(cycle.id, cycle);
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
// Alternatively, if you prefer an addCycle method:
|
||||
public void addCycle(MagicCycle cycle) {
|
||||
saveCycle(cycle);
|
||||
}
|
||||
|
||||
public void removeCycle(int categoryId) {
|
||||
if (cycles.containsKey(categoryId)) {
|
||||
cycles.remove(categoryId);
|
||||
saveMagicData();
|
||||
@@ -269,9 +299,15 @@ public class MagicController {
|
||||
/**
|
||||
* Associates a magic with a category along with its per-category ordering data.
|
||||
*/
|
||||
public void addMagicToCycle(int magicId, int categoryId, int index, int priority) {
|
||||
MagicCycle cat = cycles.get(categoryId);
|
||||
if (cat == null) return;
|
||||
public void addMagicToCycle(int magicId, int cycleId, int index, int priority) {
|
||||
MagicCycle cat = cycles.get(cycleId);
|
||||
if (cat == null)
|
||||
return;
|
||||
|
||||
Magic magic = magics.get(magicId);
|
||||
if(magic == null)
|
||||
return;
|
||||
|
||||
MagicAssociation assoc = new MagicAssociation();
|
||||
assoc.magicId = magicId;
|
||||
assoc.index = index;
|
||||
@@ -280,8 +316,8 @@ public class MagicController {
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
public void removeMagicFromCycle(int magicId, int categoryId) {
|
||||
MagicCycle cat = cycles.get(categoryId);
|
||||
public void removeMagicFromCycle(int magicId, int cycleId) {
|
||||
MagicCycle cat = cycles.get(cycleId);
|
||||
if (cat == null) return;
|
||||
cat.associations.remove(magicId);
|
||||
saveMagicData();
|
||||
|
||||
@@ -2,6 +2,8 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.constants.EnumDiagramLayout;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@@ -10,14 +12,17 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class MagicCycle {
|
||||
public int id = -1;
|
||||
public String title = "";
|
||||
public String name = "";
|
||||
public String displayName = "";
|
||||
public EnumDiagramLayout layout = EnumDiagramLayout.CIRCULAR;
|
||||
public HashMap<Integer, MagicAssociation> associations = new HashMap<>();
|
||||
|
||||
public MagicCycle() {}
|
||||
|
||||
public void readNBT(NBTTagCompound compound) {
|
||||
id = compound.getInteger("CategoryID");
|
||||
title = compound.getString("Title");
|
||||
name = compound.getString("Name");
|
||||
displayName = compound.getString("DisplayName");
|
||||
layout = EnumDiagramLayout.values()[compound.getInteger("Layout")];
|
||||
associations.clear();
|
||||
NBTTagList list = compound.getTagList("Associations", 10); // compound tags
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
@@ -32,7 +37,9 @@ public class MagicCycle {
|
||||
|
||||
public void writeNBT(NBTTagCompound compound) {
|
||||
compound.setInteger("CategoryID", id);
|
||||
compound.setString("Title", title);
|
||||
compound.setString("Title", name);
|
||||
compound.setString("DisplayName", displayName);
|
||||
compound.setInteger("Layout", layout.ordinal());
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (MagicAssociation assoc : associations.values()) {
|
||||
NBTTagCompound assocTag = new NBTTagCompound();
|
||||
@@ -43,4 +50,40 @@ public class MagicCycle {
|
||||
}
|
||||
compound.setTag("Associations", list);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public EnumDiagramLayout getLayout() {
|
||||
return layout;
|
||||
}
|
||||
|
||||
public void setLayout(EnumDiagramLayout layout) {
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
public HashMap<Integer, MagicAssociation> getAssociations() {
|
||||
return associations;
|
||||
}
|
||||
|
||||
public void setAssociations(HashMap<Integer, MagicAssociation> associations) {
|
||||
this.associations = associations;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user