mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 08:45:11 +00:00
ICustomGui:
-Added IDs to custom GUI slots.
This commit is contained in:
1 parent
2c012f2693
commit
586c451f06
7 files changed
+52
-19
No files matched your search
@@ -560,8 +560,8 @@ public class EventHooks {
|
||||
CustomGuiController.onSlotChange(event);
|
||||
}
|
||||
|
||||
public static boolean onCustomGuiSlotClicked(IPlayer player, ICustomGui gui, int slotId, int dragType, int clickType) {
|
||||
CustomGuiEvent.SlotClickEvent event = new CustomGuiEvent.SlotClickEvent(player, gui, slotId, player.getOpenContainer().getSlot(slotId), dragType, clickType);
|
||||
public static boolean onCustomGuiSlotClicked(IPlayer player, ICustomGui gui, int slotId, int guiSlotId, int dragType, int clickType) {
|
||||
CustomGuiEvent.SlotClickEvent event = new CustomGuiEvent.SlotClickEvent(player, gui, slotId, guiSlotId, player.getOpenContainer().getSlot(slotId), dragType, clickType);
|
||||
return CustomGuiController.onSlotClick(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,14 @@ import noppes.npcs.client.gui.custom.GuiCustom;
|
||||
|
||||
public class CustomGuiSlot extends Slot {
|
||||
public boolean clientSide;
|
||||
public int slotNumber;
|
||||
public final int slotNumber;
|
||||
public final int guiSlotId;
|
||||
|
||||
public CustomGuiSlot(IInventory inventoryIn, int index, int xPosition, int yPosition, boolean clientSide) {
|
||||
public CustomGuiSlot(IInventory inventoryIn, int index, int guiSlotId, int xPosition, int yPosition, boolean clientSide) {
|
||||
super(inventoryIn, index, xPosition, yPosition);
|
||||
this.clientSide = clientSide;
|
||||
this.slotNumber = index;
|
||||
this.guiSlotId = guiSlotId;
|
||||
}
|
||||
|
||||
public void onSlotChanged() {
|
||||
|
||||
@@ -44,9 +44,9 @@ public class ContainerCustomGui extends Container {
|
||||
while(var3.hasNext()) {
|
||||
IItemSlot slot = (IItemSlot)var3.next();
|
||||
if (slot.hasStack()) {
|
||||
this.addSlot(slot.getPosX(), slot.getPosY(), slot.getStack().getMCItemStack(), player.worldObj.isRemote);
|
||||
this.addSlot(slot.getPosX(), slot.getPosY(), slot.getID(), slot.getStack().getMCItemStack(), player.worldObj.isRemote);
|
||||
} else {
|
||||
this.addSlot(slot.getPosX(), slot.getPosY(), player.worldObj.isRemote);
|
||||
this.addSlot(slot.getPosX(), slot.getPosY(), slot.getID(), player.worldObj.isRemote);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,13 +75,13 @@ public class ContainerCustomGui extends Container {
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
void addSlot(int x, int y, boolean clientSide) {
|
||||
this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, x, y, clientSide));
|
||||
void addSlot(int x, int y, int guiSlotId, boolean clientSide) {
|
||||
this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, guiSlotId, x, y, clientSide));
|
||||
}
|
||||
|
||||
void addSlot(int x, int y, ItemStack itemStack, boolean clientSide) {
|
||||
void addSlot(int x, int y, int guiSlotId, ItemStack itemStack, boolean clientSide) {
|
||||
this.guiInventory.setInventorySlotContents(this.slotCount, itemStack);
|
||||
this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, x, y, clientSide));
|
||||
this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, guiSlotId, x, y, clientSide));
|
||||
}
|
||||
|
||||
void addPlayerInventory(EntityPlayer player, int x, int y) {
|
||||
@@ -108,8 +108,9 @@ public class ContainerCustomGui extends Container {
|
||||
public ItemStack slotClick(int slotId, int dragType, int clickTypeIn, EntityPlayer player) {
|
||||
if(slotId < 0)
|
||||
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
if(!player.worldObj.isRemote) {
|
||||
if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, dragType, clickTypeIn)) {
|
||||
if(!player.worldObj.isRemote && this.getSlot(slotId) instanceof CustomGuiSlot) {
|
||||
CustomGuiSlot guiSlot = (CustomGuiSlot) this.getSlot(slotId);
|
||||
if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, guiSlot.guiSlotId, dragType, clickTypeIn)) {
|
||||
ItemStack item = super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
EntityPlayerMP p = (EntityPlayerMP) player;
|
||||
p.sendContainerToPlayer(this);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user