Fixed null pointer exceptions from new custom gui slot commit.

This commit is contained in:
Luis C.M committed 2023-03-18 03:47:24 -05:00
1 parent 586c451f06
commit e3405d22e9
4 files changed
+25 -10

No files matched your search

+3 -2
View File
@@ -26,6 +26,7 @@ import noppes.npcs.api.entity.IProjectile;
import noppes.npcs.api.gui.ICustomGui;
import noppes.npcs.api.item.IItemCustom;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.client.gui.custom.components.CustomGuiSlot;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.CustomGuiController;
import noppes.npcs.controllers.ScriptContainer;
@@ -560,8 +561,8 @@ public class EventHooks {
CustomGuiController.onSlotChange(event);
}
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);
public static boolean onCustomGuiSlotClicked(IPlayer player, ICustomGui gui, int slotId, CustomGuiSlot guiSlot, int dragType, int clickType) {
CustomGuiEvent.SlotClickEvent event = new CustomGuiEvent.SlotClickEvent(player, gui, slotId, guiSlot, player.getOpenContainer().getSlot(slotId), dragType, clickType);
return CustomGuiController.onSlotClick(event);
}
@@ -108,9 +108,12 @@ 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 && 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)) {
if(!player.worldObj.isRemote) {
CustomGuiSlot guiSlot = null;
if (this.getSlot(slotId) instanceof CustomGuiSlot) {
guiSlot = (CustomGuiSlot) this.getSlot(slotId);
}
if(!EventHooks.onCustomGuiSlotClicked((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, slotId, guiSlot, dragType, clickTypeIn)) {
ItemStack item = super.slotClick(slotId, dragType, clickTypeIn, player);
EntityPlayerMP p = (EntityPlayerMP) player;
p.sendContainerToPlayer(this);
@@ -123,7 +123,11 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent {
super(player, gui);
this.slotId = slotId;
this.stack = stack;
this.slot = (IItemSlot) gui.getComponent(((CustomGuiSlot)(((EntityPlayerMP)player.getMCEntity()).openContainer.getSlot(slotId))).guiSlotId);
if ((((EntityPlayerMP)player.getMCEntity()).openContainer.getSlot(slotId) instanceof CustomGuiSlot)) {
this.slot = (IItemSlot) gui.getComponent(((CustomGuiSlot) (((EntityPlayerMP) player.getMCEntity()).openContainer.getSlot(slotId))).guiSlotId);
} else {
this.slot = null;
}
}
public String getHookName() {
@@ -150,13 +154,17 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent {
*/
public final int clickType;
public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, int guiSlotId, IItemStack stack, int dragType, int clickType) {
public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, CustomGuiSlot guiSlot, 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);
if (guiSlot != null) {
this.slot = (IItemSlot) gui.getComponent(guiSlot.guiSlotId);
} else {
this.slot = null;
}
}
public String getHookName() {
@@ -143,13 +143,13 @@ public class ScriptGui implements ICustomGui {
}
public IItemSlot addItemSlot(int x, int y) {
ScriptGuiItemSlot slot = new ScriptGuiItemSlot(this.getMaxId() + 1, x, y);
ScriptGuiItemSlot slot = new ScriptGuiItemSlot(-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(this.getMaxId() + 1, x, y, stack);
ScriptGuiItemSlot slot = new ScriptGuiItemSlot(-1, x, y, stack);
this.slots.add(slot);
return (IItemSlot)this.slots.get(this.slots.size() - 1);
}
@@ -308,6 +308,9 @@ public class ScriptGui implements ICustomGui {
while(var3.hasNext()) {
c = (ICustomGuiComponent)var3.next();
if (c.getID() == -1) {
c.setID(this.getMaxId()+1);
}
list.appendTag(((ScriptGuiComponent)c).toNBT(new NBTTagCompound()));
}