mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 08:27:45 +00:00
Magic Get Packet
This commit is contained in:
1 parent
debbd25f18
commit
82bad818f9
4 files changed
+157
-62
No files matched your search
@@ -341,6 +341,7 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new MagicGetAllPacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicGetPacket());
|
||||
|
||||
// Other Packets
|
||||
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
|
||||
|
||||
@@ -201,5 +201,5 @@ public enum EnumRequestPacket {
|
||||
MagicCycleSave,
|
||||
MagicGetAll,
|
||||
MagicRemove,
|
||||
MagicSave
|
||||
MagicGet, MagicSave
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package kamkeel.npcs.network.packets.request.magic;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.*;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
import noppes.npcs.controllers.LinkedNpcController;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class MagicGetPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|MagicGet";
|
||||
|
||||
private Action action;
|
||||
private int id;
|
||||
|
||||
public MagicGetPacket() {}
|
||||
|
||||
public MagicGetPacket(Action action, int id) {
|
||||
this.action = action;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.MagicGet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(this.action.ordinal());
|
||||
out.writeInt(this.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
|
||||
return;
|
||||
|
||||
Action action = Action.values()[in.readInt()];
|
||||
int id = in.readInt();
|
||||
if(action == Action.MAGIC){
|
||||
Magic magic = MagicController.getInstance().getMagic(id);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
magic.writeNBT(magicCompound);
|
||||
compound.setTag("Magic", magicCompound);
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
} else if (action == Action.CYCLE) {
|
||||
MagicCycle cycle = MagicController.getInstance().getCycle(id);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
cycle.writeNBT(magicCompound);
|
||||
compound.setTag("MagicCycle", magicCompound);
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetMagic(int id) {
|
||||
PacketClient.sendClient(new MagicGetPacket(Action.MAGIC, id));
|
||||
}
|
||||
|
||||
public static void GetCycle(int id) {
|
||||
PacketClient.sendClient(new MagicGetPacket(Action.CYCLE, id));
|
||||
}
|
||||
|
||||
private enum Action {
|
||||
MAGIC,
|
||||
CYCLE
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,7 @@ import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicCycleRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicCycleSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.*;
|
||||
import noppes.npcs.client.gui.magic.SubGuiMagicCycleEdit;
|
||||
import noppes.npcs.client.gui.magic.SubGuiMagicEdit;
|
||||
import noppes.npcs.client.gui.magic.SubGuiMagicInteractionsEdit;
|
||||
@@ -25,7 +21,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons;
|
||||
|
||||
public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListener, ICustomScrollListener, IScrollData {
|
||||
public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListener, ICustomScrollListener, IScrollData, IGuiData {
|
||||
|
||||
private GuiCustomScroll leftScroll; // left scroll for cycles (viewByCycle)
|
||||
private GuiCustomScroll rightScroll; // right scroll for magics
|
||||
@@ -104,7 +100,9 @@ public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListen
|
||||
getButton(33).setEnabled(false);
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + 358, guiTop + 38, 58, 20, "gui.add"));
|
||||
getButton(0).setEnabled(false);
|
||||
addButton(new GuiNpcButton(1, guiLeft + 358, guiTop + 61, 58, 20, "gui.remove"));
|
||||
getButton(1).setEnabled(false);
|
||||
|
||||
addButton(new GuiNpcButton(2, guiLeft + 358, guiTop + 94, 58, 20, "gui.edit"));
|
||||
} else {
|
||||
@@ -258,14 +256,18 @@ public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListen
|
||||
switch (button.id) {
|
||||
case 50:
|
||||
viewByCycle = !viewByCycle;
|
||||
selectedMagic = null;
|
||||
selectedCycle = null;
|
||||
initGui();
|
||||
return;
|
||||
// Left side: Cycle management
|
||||
case 4: // Add Cycle
|
||||
{
|
||||
NBTTagCompound cycleCompound = new NBTTagCompound();
|
||||
cycleCompound.setString("Title", "New Cycle");
|
||||
PacketClient.sendClient(new MagicCycleSavePacket(cycleCompound));
|
||||
MagicCycle magicCycle = new MagicCycle();
|
||||
magicCycle.name = "New";
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
magicCycle.writeNBT(compound);
|
||||
PacketClient.sendClient(new MagicCycleSavePacket(compound));
|
||||
}
|
||||
break;
|
||||
case 5: // Remove Cycle
|
||||
@@ -279,42 +281,30 @@ public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListen
|
||||
}
|
||||
break;
|
||||
// Right side: Magic management (in viewByCycle)
|
||||
case 0: // Add Magic to selected cycle
|
||||
case 0: // Add Magic
|
||||
if (selectedCycle != null) {
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
magicCompound.setString("Name", "New Magic");
|
||||
magicCompound.setInteger("CycleID", selectedCycle.id);
|
||||
magicCompound.setInteger("Index", 0);
|
||||
magicCompound.setInteger("Priority", 0);
|
||||
PacketClient.sendClient(new MagicSavePacket(magicCompound));
|
||||
Magic magic = new Magic();
|
||||
magic.name = "New";
|
||||
magic.displayName = "New";
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
magic.writeNBT(compound);
|
||||
PacketClient.sendClient(new MagicSavePacket(compound));
|
||||
}
|
||||
break;
|
||||
case 1: // Edit Magic
|
||||
if (selectedMagic != null) {
|
||||
setSubGui(new SubGuiMagicEdit(selectedMagic));
|
||||
}
|
||||
break;
|
||||
case 2: // Remove Magic
|
||||
if (selectedMagic != null) {
|
||||
PacketClient.sendClient(new MagicRemovePacket(selectedMagic.id));
|
||||
}
|
||||
break;
|
||||
case 3: // Edit Interactions
|
||||
if (selectedMagic != null) {
|
||||
setSubGui(new SubGuiMagicInteractionsEdit(selectedMagic));
|
||||
}
|
||||
break;
|
||||
// Default mode buttons (global view)
|
||||
// Default mode buttons (global view)
|
||||
case 21:
|
||||
if (selectedMagic != null) {
|
||||
setSubGui(new SubGuiMagicEdit(selectedMagic));
|
||||
}
|
||||
break;
|
||||
case 2: // Remove Magic
|
||||
case 22:
|
||||
if (selectedMagic != null) {
|
||||
PacketClient.sendClient(new MagicRemovePacket(selectedMagic.id));
|
||||
}
|
||||
break;
|
||||
case 3: // Edit Interactions
|
||||
case 23:
|
||||
if (selectedMagic != null) {
|
||||
setSubGui(new SubGuiMagicInteractionsEdit(selectedMagic));
|
||||
@@ -327,41 +317,24 @@ public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListen
|
||||
public void customScrollClicked(int id, int index, int clickType, GuiCustomScroll scroll) {
|
||||
if (!viewByCycle) {
|
||||
if (scroll.id == 0) { // Left scroll: cycles
|
||||
selectedCycle = null;
|
||||
String cycleName = scroll.getSelected();
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
if (cycle.name.equals(cycleName)) {
|
||||
selectedCycle = cycle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Update right scroll with magics in selected cycle
|
||||
if (selectedCycle != null) {
|
||||
List<String> magicNames = new ArrayList<>();
|
||||
for (Integer magicId : selectedCycle.associations.keySet()) {
|
||||
Magic m = MagicController.getInstance().magics.get(magicId);
|
||||
if (m != null) {
|
||||
magicNames.add(m.name);
|
||||
}
|
||||
}
|
||||
rightScroll.setList(magicNames);
|
||||
if(cycleData.containsKey(cycleName)){
|
||||
MagicGetPacket.GetCycle(cycleData.get(cycleName));
|
||||
}
|
||||
} else if (scroll.id == 1) { // Right scroll: magics
|
||||
selectedMagic = null;
|
||||
String magicName = scroll.getSelected();
|
||||
for (Magic m : MagicController.getInstance().magics.values()) {
|
||||
if (m.name.equals(magicName)) {
|
||||
selectedMagic = m;
|
||||
break;
|
||||
}
|
||||
if(magicData.containsKey(magicName)){
|
||||
MagicGetPacket.GetMagic(magicData.get(magicName));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (scroll.id == 1) {
|
||||
selectedMagic = null;
|
||||
String magicName = scroll.getSelected();
|
||||
for (Magic m : MagicController.getInstance().magics.values()) {
|
||||
if (m.name.equals(magicName)) {
|
||||
selectedMagic = m;
|
||||
break;
|
||||
}
|
||||
if(magicData.containsKey(magicName)){
|
||||
MagicGetPacket.GetMagic(magicData.get(magicName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -392,11 +365,40 @@ public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListen
|
||||
initGui();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param selected
|
||||
*/
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
public void setSelected(String selected) {}
|
||||
|
||||
public void updateMagicList(){
|
||||
List<String> magicNames = new ArrayList<>();
|
||||
if(selectedCycle == null)
|
||||
return;
|
||||
|
||||
for (int magicId : selectedCycle.associations.keySet()) {
|
||||
for(String magicName : magicData.keySet()){
|
||||
if(magicData.containsKey(magicName) && magicData.get(magicName) == magicId){
|
||||
magicNames.add(magicName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(rightScroll != null)
|
||||
rightScroll.setList(magicNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if(compound.hasKey("Magic")){
|
||||
selectedMagic = new Magic();
|
||||
selectedMagic.readNBT(compound.getCompoundTag("Magic"));
|
||||
} else if (compound.hasKey("MagicCycle")) {
|
||||
selectedCycle = new MagicCycle();
|
||||
selectedCycle.readNBT(compound.getCompoundTag("MagicCycle"));
|
||||
|
||||
updateMagicList();
|
||||
selectedMagic = null;
|
||||
if(rightScroll != null)
|
||||
rightScroll.selected = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user