ICustomGui:

-Added IDs to custom GUI slots.
This commit is contained in:
Luis C.M committed 2023-03-18 03:04:46 -05:00
1 parent 2c012f2693
commit 586c451f06
7 files changed
+52 -19

No files matched your search

@@ -1,10 +1,13 @@
package noppes.npcs.scripted.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.event.ICustomGuiEvent;
import noppes.npcs.api.gui.ICustomGui;
import noppes.npcs.api.gui.IItemSlot;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.client.gui.custom.components.CustomGuiSlot;
import noppes.npcs.constants.EnumScriptType;
public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent {
@@ -114,11 +117,13 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent {
public static class SlotEvent extends CustomGuiEvent implements ICustomGuiEvent.SlotEvent {
public final int slotId;
public final IItemStack stack;
public final IItemSlot slot;
public SlotEvent(IPlayer player, ICustomGui gui, int slotId, IItemStack stack) {
super(player, gui);
this.slotId = slotId;
this.stack = stack;
this.slot = (IItemSlot) gui.getComponent(((CustomGuiSlot)(((EntityPlayerMP)player.getMCEntity()).openContainer.getSlot(slotId))).guiSlotId);
}
public String getHookName() {
@@ -139,17 +144,19 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent {
public final int slotId;
public final IItemStack stack;
public final int dragType;
public final IItemSlot slot;
/**
*
*/
public final int clickType;
public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, IItemStack stack, int dragType, int clickType) {
public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, int guiSlotId, IItemStack stack, int dragType, int clickType) {
super(player,gui);
this.slotId = slotId;
this.stack = stack;
this.dragType = dragType;
this.clickType = clickType;
this.slot = (IItemSlot) gui.getComponent(guiSlotId);
}
public String getHookName() {
@@ -143,13 +143,25 @@ public class ScriptGui implements ICustomGui {
}
public IItemSlot addItemSlot(int x, int y) {
ScriptGuiItemSlot slot = new ScriptGuiItemSlot(x, y);
ScriptGuiItemSlot slot = new ScriptGuiItemSlot(this.getMaxId() + 1, x, y);
this.slots.add(slot);
return (IItemSlot)this.slots.get(this.slots.size() - 1);
}
public IItemSlot addItemSlot(int x, int y, IItemStack stack) {
ScriptGuiItemSlot slot = new ScriptGuiItemSlot(x, y, stack);
ScriptGuiItemSlot slot = new ScriptGuiItemSlot(this.getMaxId() + 1, x, y, stack);
this.slots.add(slot);
return (IItemSlot)this.slots.get(this.slots.size() - 1);
}
public IItemSlot addItemSlot(int id, int x, int y) {
ScriptGuiItemSlot slot = new ScriptGuiItemSlot(id, x, y);
this.slots.add(slot);
return (IItemSlot)this.slots.get(this.slots.size() - 1);
}
public IItemSlot addItemSlot(int id, int x, int y, IItemStack stack) {
ScriptGuiItemSlot slot = new ScriptGuiItemSlot(id, x, y, stack);
this.slots.add(slot);
return (IItemSlot)this.slots.get(this.slots.size() - 1);
}
@@ -230,6 +242,16 @@ public class ScriptGui implements ICustomGui {
return this.playerInvY;
}
private int getMaxId() {
int max = 0;
for (ICustomGuiComponent component : this.getComponents()) {
if (component.getID() >= max) {
max = component.getID();
}
}
return max;
}
public ICustomGui fromNBT(NBTTagCompound tag) {
this.id = tag.getInteger("id");
this.width = tag.getIntArray("size")[0];
@@ -13,12 +13,13 @@ public class ScriptGuiItemSlot extends ScriptGuiComponent implements IItemSlot {
public ScriptGuiItemSlot() {
}
public ScriptGuiItemSlot(int x, int y) {
public ScriptGuiItemSlot(int id, int x, int y) {
this.setID(id);
this.setPos(x, y);
}
public ScriptGuiItemSlot(int x, int y, IItemStack stack) {
this(x, y);
public ScriptGuiItemSlot(int id, int x, int y, IItemStack stack) {
this(id, x, y);
this.setStack(stack);
}