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
}
}
@@ -24,7 +24,7 @@ public class GuiNPCAdvancedLinkedNpc extends GuiNPCInterface2 implements IScroll
public GuiNPCAdvancedLinkedNpc(EntityNPCInterface npc){
super(npc);
Instance = this;
PacketClient.sendClient(new LinkedGetAllPacket());
LinkedGetAllPacket.GetNPCs();
}
@Override
@@ -1,51 +1,87 @@
package noppes.npcs.client.gui.global;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.request.linked.LinkedAddPacket;
import kamkeel.npcs.network.packets.request.linked.LinkedGetAllPacket;
import kamkeel.npcs.network.packets.request.linked.LinkedGetPacket;
import kamkeel.npcs.network.packets.request.linked.LinkedRemovePacket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.CustomNpcResourceListener;
import noppes.npcs.client.gui.SubGuiEditText;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData, ISubGuiListener{
private GuiCustomScroll scroll;
private List<String> data = new ArrayList<String>();
public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData, ISubGuiListener, ICustomScrollListener, IGuiData {
private int tab = 0;
private boolean loadedNPC = false;
private GuiCustomScroll scroll;
public HashMap<String, Integer> data = new HashMap<>();
private String selected = null;
private String search = "";
public static GuiScreen Instance;
private float zoomed = 70, rotation;
public GuiNPCManageLinked(EntityNPCInterface npc){
super(npc);
Instance = this;
PacketClient.sendClient(new LinkedGetAllPacket());
// Spoof NPC
this.npc = new EntityCustomNpc(Minecraft.getMinecraft().theWorld);
this.npc.display.name = "Linked NPC";
this.npc.height = 1.62f;
this.npc.width = 0.43f;
LinkedGetAllPacket.GetNPCs();
}
@Override
public void initGui(){
super.initGui();
this.addButton(new GuiNpcButton(1,guiLeft + 358, guiTop + 38, 58, 20, "gui.add"));
this.addButton(new GuiNpcButton(2,guiLeft + 358, guiTop + 61, 58, 20, "gui.remove"));
int y = guiTop + 8;
this.addButton(new GuiNpcButton(10,guiLeft + 368, y, 45, 20, "npc"));
this.addButton(new GuiNpcButton(11,guiLeft + 368, y += 22, 45, 20, "items"));
getButton(10).enabled = tab == 1;
getButton(11).enabled = tab == 0;
this.addButton(new GuiNpcButton(1,guiLeft + 368, y += 40, 45, 20, "gui.add"));
this.addButton(new GuiNpcButton(2,guiLeft + 368, y += 22, 45, 20, "gui.remove"));
this.addButton(new GuiNpcButton(3,guiLeft + 368, y += 22, 45, 20, "gui.edit"));
this.addButton(new GuiNpcButton(4,guiLeft + 368, y += 22, 45, 20, "gui.copy"));
getButton(3).enabled = tab == 1;
getButton(4).enabled = tab == 1;
if(scroll == null){
scroll = new GuiCustomScroll(this,0,0);
scroll.setSize(143, 185);
}
scroll.guiLeft = guiLeft + 214;
scroll.guiLeft = guiLeft + 220;
scroll.guiTop = guiTop + 4;
scroll.setList(getSearchList());
this.addScroll(scroll);
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 220, guiTop + 4 + 3 + 185, 143, 20, search));
this.addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 220, guiTop + 4 + 3 + 185, 143, 20, search));
}
@Override
@@ -63,12 +99,87 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
}
}
@Override
public void drawScreen(int i, int j, float f) {
super.drawScreen(i, j, f);
if(tab == 0){
if (hasSubGui())
return;
if (isMouseOverRenderer(i, j)) {
zoomed += Mouse.getDWheel() * 0.035f;
if (zoomed > 100)
zoomed = 100;
if (zoomed < 10)
zoomed = 10;
if (Mouse.isButtonDown(0) || Mouse.isButtonDown(1)) {
rotation -= Mouse.getDX() * 0.75f;
}
}
GL11.glColor4f(1, 1, 1, 1);
EntityLivingBase entity = this.npc;
int l = guiLeft + 150;
int i1 = guiTop + 198;
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glPushMatrix();
GL11.glTranslatef(l, i1, 60F);
GL11.glScalef(-zoomed, zoomed, zoomed);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
float f2 = entity.renderYawOffset;
float f3 = entity.rotationYaw;
float f4 = entity.rotationPitch;
float f7 = entity.rotationYawHead;
float f5 = (float) (l) - i;
float f6 = (float) (i1 - 50) - j;
GL11.glRotatef(135F, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glRotatef(-135F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-(float) Math.atan(f6 / 800F) * 20F, 1.0F, 0.0F, 0.0F);
entity.prevRenderYawOffset = entity.renderYawOffset = rotation;
entity.prevRotationYaw = entity.rotationYaw = (float) Math.atan(f5 / 80F) * 40F + rotation;
entity.rotationPitch = -(float) Math.atan(f6 / 80F) * 20F;
entity.prevRotationYawHead = entity.rotationYawHead = entity.rotationYaw;
GL11.glTranslatef(0.0F, entity.yOffset, 1F);
RenderManager.instance.playerViewY = 180F;
// Render Entity
GL11.glPushMatrix();
try {
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0, 0.0, 0.0, 0.0F, 1.0F);
} catch (Exception ignored) {
}
GL11.glPopMatrix();
entity.prevRenderYawOffset = entity.renderYawOffset = f2;
entity.prevRotationYaw = entity.rotationYaw = f3;
entity.rotationPitch = f4;
entity.prevRotationYawHead = entity.rotationYawHead = f7;
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
GL11.glPopMatrix();
}
}
private List<String> getSearchList(){
if(search.isEmpty()){
return new ArrayList<String>(this.data);
return new ArrayList<String>(this.data.keySet());
}
List<String> list = new ArrayList<String>();
for(String name : this.data){
for(String name : this.data.keySet()){
if(name.toLowerCase().contains(search))
list.add(name);
}
@@ -78,14 +189,85 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
@Override
public void buttonEvent(GuiButton button){
if(button.id == 1){
save();
setSubGui(new SubGuiEditText("New"));
if(tab == 0){
save();
setSubGui(new SubGuiEditText("New"));
} else {
}
}
if(button.id == 2){
if(scroll.hasSelected())
PacketClient.sendClient(new LinkedRemovePacket(scroll.getSelected()));
}
if(tab == 0){
if(scroll.hasSelected())
PacketClient.sendClient(new LinkedRemovePacket(scroll.getSelected()));
} else {
}
}
if(button.id == 10){
tab = 0;
initGui();
}
if(button.id == 11){
tab = 1;
initGui();
}
}
@Override
public void drawBackground() {
super.drawBackground();
renderScreen();
}
private void renderScreen() {
drawGradientRect(guiLeft + 5, guiTop + 4, guiLeft + 218, guiTop + 24, 0xC0101010, 0xC0101010);
drawHorizontalLine(guiLeft + 5, guiLeft + 218, guiTop + 25, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor);
drawGradientRect(guiLeft + 5, guiTop + 27, guiLeft + 218, guiTop + ySize + 9, 0xA0101010, 0xA0101010);
if (tab == 0 && loadedNPC && this.npc != null) {
String drawString = npc.display.getName();
int textWidth = getStringWidthWithoutColor(drawString);
int centerX = guiLeft + 5 + ((218 - 10 - textWidth) / 2);
fontRendererObj.drawString(drawString, centerX, guiTop + 10, npc.getFaction().color, true);
int y = guiTop + 18;
String healthMenu = "Health:";
fontRendererObj.drawString(healthMenu, guiLeft + 8, y += 12, 0xFFFFFF, true);
healthMenu = "§c" + String.valueOf(this.npc.stats.maxHealth);
fontRendererObj.drawString(healthMenu, guiLeft + 50, y, 0xFFFFFF, true);
String damage = "Damage:";
fontRendererObj.drawString(damage, guiLeft + 8, y += 12, 0xFFFFFF, true);
damage = "§4" + String.valueOf(this.npc.stats.getAttackStrength());
fontRendererObj.drawString(damage, guiLeft + 50, y, 0xFFFFFF, true);
String moveSpeed = "Speed:";
fontRendererObj.drawString(moveSpeed, guiLeft + 8, y += 12, 0xFFFFFF, true);
moveSpeed = "§b" + String.valueOf(this.npc.ais.getWalkingSpeed());
fontRendererObj.drawString(moveSpeed, guiLeft + 50, y, 0xFFFFFF, true);
}
}
public int getStringWidthWithoutColor(String text) {
int width = 0;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c == '§') {
if (i < text.length() - 1) {
i += 1;
}
} else {
// If not a color code, calculate the width
width += fontRendererObj.getCharWidth(c);
}
}
return width;
}
@Override
@@ -97,19 +279,52 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data) {
this.data = new ArrayList<String>(list);
this.data = new HashMap<>(data);
this.scroll.setList(getSearchList());
initGui();
}
@Override
public void setSelected(String selected) {
}
@Override
public void setSelected(String selected) {
this.selected = selected;
scroll.setSelected(selected);
}
@Override
public void save() {
public void save() {}
}
public boolean isMouseOverRenderer(int x, int y) {
return x >= guiLeft + 10 && x <= guiLeft + 10 + 200 && y >= guiTop + 6 && y <= guiTop + 6 + 204;
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll.id == 0) {
loadedNPC = false;
selected = scroll.getSelected();
if (selected != null && !selected.isEmpty()){
if(tab == 0)
LinkedGetPacket.GetNPC(selected);
else
LinkedGetPacket.GetItem(data.get(selected));
}
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {}
public void setGuiData(NBTTagCompound compound) {
loadedNPC = false;
if(compound.hasKey("NPCData")){
// Linked NPC
this.npc.display.readToNBT(compound.getCompoundTag("NPCData"));
this.npc.stats.readToNBT(compound.getCompoundTag("NPCData"));
this.npc.ais.readToNBT(compound.getCompoundTag("NPCData"));
loadedNPC = true;
} else {
// Linked Item
}
}
}
@@ -19,8 +19,8 @@ public class LinkedItemController {
private static LinkedItemController Instance;
private int lastUsedID = 0;
private HashMap<Integer, LinkedItem> linkedItems = new HashMap<>();
private HashMap<Integer, LinkedItemScript> linkedItemsScripts = new HashMap<>();
public HashMap<Integer, LinkedItem> linkedItems = new HashMap<>();
public HashMap<Integer, LinkedItemScript> linkedItemsScripts = new HashMap<>();
private HashMap<Integer, String> bootOrder;
@@ -1,30 +0,0 @@
package noppes.npcs.controllers.data;
public class LinkedItemData {
// Utilitzed within a Scripted Item
//
public int version = 1;
public boolean durabilityShow = false;
public double durabilityValue = 1.0D;
public int durabilityColor = -1;
public int itemColor = 0x8B4513;
public int stackSize = 64;
public int maxItemUseDuration = 20;
public int itemUseAction = 0;
public boolean isNormalItem = false;
public boolean isTool = false;
public int digSpeed = 1;
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 4: Fits in Head -> Boots slot respectively
public int enchantability;
public String texture = "minecraft:textures/items/iron_pickaxe.png";
public float translateX, translateY, translateZ;
public float scaleX = 1.0F, scaleY = 1.0F, scaleZ = 1.0F;
public float rotationX, rotationY, rotationZ;
public float rotationXRate, rotationYRate, rotationZRate;
}