More Linked Manage Controls

This commit is contained in:
Kam committed 2025-02-15 22:59:51 -05:00
1 parent 4dc8d8a971
commit de2e3ce4fb
8 files changed
+383 -73

No files matched your search

@@ -43,10 +43,7 @@ import kamkeel.npcs.network.packets.request.jobs.JobGetPacket;
import kamkeel.npcs.network.packets.request.jobs.JobSavePacket;
import kamkeel.npcs.network.packets.request.jobs.JobSpawnerAddPacket;
import kamkeel.npcs.network.packets.request.jobs.JobSpawnerRemovePacket;
import kamkeel.npcs.network.packets.request.linked.LinkedAddPacket;
import kamkeel.npcs.network.packets.request.linked.LinkedGetAllPacket;
import kamkeel.npcs.network.packets.request.linked.LinkedRemovePacket;
import kamkeel.npcs.network.packets.request.linked.LinkedSetPacket;
import kamkeel.npcs.network.packets.request.linked.*;
import kamkeel.npcs.network.packets.request.mainmenu.*;
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnGetAllPacket;
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnGetPacket;
@@ -150,6 +147,7 @@ public class PacketHandler {
// Linked Packets
REQUEST_PACKET.registerPacket(new LinkedGetAllPacket());
REQUEST_PACKET.registerPacket(new LinkedGetPacket());
REQUEST_PACKET.registerPacket(new LinkedRemovePacket());
REQUEST_PACKET.registerPacket(new LinkedSetPacket());
REQUEST_PACKET.registerPacket(new LinkedAddPacket());
@@ -1,4 +1,7 @@
package kamkeel.npcs.network.enums;
import noppes.npcs.controllers.data.EffectScript;
public enum EnumRequestPacket {
NPCDelete,
RemoteMainMenu,
@@ -122,6 +125,7 @@ public enum EnumRequestPacket {
LinkedAdd,
LinkedGetAll,
LinkedSet,
LinkedGet,
BankGet,
BanksGet,
@@ -178,5 +182,5 @@ public enum EnumRequestPacket {
EffectRemove,
EffectSave,
ColorSet, ColorBrush,
ColorSet, ColorBrush
}
@@ -3,27 +3,33 @@ package kamkeel.npcs.network.packets.request.linked;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.*;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import kamkeel.npcs.network.packets.data.ScrollSelectedPacket;
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
import kamkeel.npcs.network.packets.data.large.ScrollListPacket;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.LinkedNpcController;
import noppes.npcs.controllers.data.LinkedItem;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public final class LinkedGetAllPacket extends AbstractPacket {
public static String packetName = "Request|LinkedGetAll";
private Action action;
public LinkedGetAllPacket() {}
public LinkedGetAllPacket(Action action) {
this.action = action;
}
@Override
public Enum getType() {
return EnumRequestPacket.LinkedGetAll;
@@ -37,6 +43,7 @@ public final class LinkedGetAllPacket extends AbstractPacket {
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.action.ordinal());
}
@Override
@@ -45,13 +52,36 @@ public final class LinkedGetAllPacket extends AbstractPacket {
return;
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
return;
List<String> list = new ArrayList<>();
for (LinkedNpcController.LinkedData d : LinkedNpcController.Instance.list) {
list.add(d.name);
}
ScrollListPacket.sendList((EntityPlayerMP) player, list);
if (npc != null) {
ScrollSelectedPacket.setSelectedList((EntityPlayerMP) player, npc.linkedName);
Action action = Action.values()[in.readInt()];
if(action == Action.NPC){
HashMap<String, Integer> list = new HashMap<>();
for (LinkedNpcController.LinkedData d : LinkedNpcController.Instance.list) {
list.put(d.name, 0);
}
ScrollDataPacket.sendScrollData((EntityPlayerMP) player, list);
if (npc != null) {
ScrollSelectedPacket.setSelectedList((EntityPlayerMP) player, npc.linkedName);
}
} else if (action == Action.ITEM){
HashMap<String, Integer> list = new HashMap<>();
for (LinkedItem linkedItem : LinkedItemController.Instance().linkedItems.values()) {
list.put(linkedItem.name, linkedItem.id);
}
ScrollDataPacket.sendScrollData((EntityPlayerMP) player, list);
}
}
public static void GetNPCs(){
PacketClient.sendClient(new LinkedGetAllPacket(Action.NPC));
}
public static void GetItems(){
PacketClient.sendClient(new LinkedGetAllPacket(Action.ITEM));
}
private enum Action {
NPC,
ITEM
}
}
@@ -0,0 +1,93 @@
package kamkeel.npcs.network.packets.request.linked;
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.data.LinkedItem;
import java.io.IOException;
public final class LinkedGetPacket extends AbstractPacket {
public static String packetName = "Request|LinkedGet";
private Action action;
private int id;
private String name;
public LinkedGetPacket() {}
public LinkedGetPacket(Action action, int id) {
this.action = action;
this.id = id;
}
public LinkedGetPacket(Action action, String name) {
this.action = action;
this.name = name;
}
@Override
public Enum getType() {
return EnumRequestPacket.LinkedGet;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.action.ordinal());
if(action == Action.NPC){
ByteBufUtils.writeString(out, this.name);
} else {
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()];
if(action == Action.NPC){
String name = ByteBufUtils.readString(in);
LinkedNpcController.LinkedData data = LinkedNpcController.Instance.getData(name);
NBTTagCompound compound = data.getNBT();
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
} else if (action == Action.ITEM) {
int id = in.readInt();
LinkedItem data = LinkedItemController.Instance().get(id);
NBTTagCompound compound = data.writeToNBT();
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
}
}
public static void GetNPC(String name) {
PacketClient.sendClient(new LinkedGetPacket(Action.NPC, name));
}
public static void GetItem(int id) {
PacketClient.sendClient(new LinkedGetPacket(Action.ITEM, id));
}
private enum Action {
NPC,
ITEM
}
}