Added CustomGuiEvent.SlotClickEvent.

This commit is contained in:
Luis C.M committed 2022-06-18 12:52:23 -05:00
1 parent cc1c6c1910
commit b45cad77dd
5 files changed
+55

No files matched your search

@@ -512,6 +512,11 @@ 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);
return CustomGuiController.onSlotClick(event);
}
public static void onCustomGuiUnfocused(IPlayer player, ICustomGui gui, int textfieldId) {
CustomGuiEvent.UnfocusedEvent event = new CustomGuiEvent.UnfocusedEvent(player, gui, textfieldId);
CustomGuiController.onCustomGuiUnfocused(event);
@@ -56,6 +56,7 @@ public enum EnumScriptType {
CUSTOM_GUI_CLOSED("customGuiClosed"),
CUSTOM_GUI_BUTTON("customGuiButton"),
CUSTOM_GUI_SLOT("customGuiSlot"),
CUSTOM_GUI_SLOT_CLICKED("customGuiSlotClicked"),
CUSTOM_GUI_SCROLL("customGuiScroll"),
CUSTOM_GUI_TEXTFIELD("customGuiTextfield"),
PICKUP_XP("pickupXP"),
@@ -7,10 +7,14 @@ package noppes.npcs.containers;
import java.util.Iterator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import noppes.npcs.EventHooks;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.interfaces.entity.IPlayer;
import noppes.npcs.scripted.interfaces.gui.IItemSlot;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.client.gui.custom.components.CustomGuiSlot;
@@ -99,5 +103,22 @@ public class ContainerCustomGui extends Container {
return true;
}
@Override
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)) {
ItemStack item = super.slotClick(slotId, dragType, clickTypeIn, player);
EntityPlayerMP p = (EntityPlayerMP) player;
p.sendContainerToPlayer(this);
return item;
}
}
return null;
}
public boolean canDragIntoSlot(Slot p_94531_1_) { return true; }
}
@@ -89,6 +89,14 @@ public class CustomGuiController {
NpcAPI.EVENT_BUS.post(event);
}
public static boolean onSlotClick(CustomGuiEvent.SlotClickEvent event) {
EntityPlayer player = (EntityPlayer) event.player.getMCEntity();
if(checkGui(event) && getOpenGui(player).getScriptHandler()!=null) {
(getOpenGui(player).getScriptHandler()).callScript(EnumScriptType.CUSTOM_GUI_SLOT_CLICKED, event);
}
return NpcAPI.EVENT_BUS.post(event);
}
public static void onCustomGuiUnfocused(CustomGuiEvent.UnfocusedEvent event) {
EntityPlayer player = (EntityPlayer) event.player.getMCEntity();
if (checkGui(event) && getOpenGui(player).getScriptHandler() != null) {
@@ -1,5 +1,6 @@
package noppes.npcs.scripted.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import noppes.npcs.scripted.interfaces.gui.ICustomGui;
import noppes.npcs.scripted.interfaces.item.IItemStack;
@@ -63,4 +64,23 @@ public class CustomGuiEvent extends Event {
this.stack = stack;
}
}
@Cancelable
public static class SlotClickEvent extends CustomGuiEvent {
public final int slotId;
public final IItemStack stack;
public final int dragType;
/**
*
*/
public final int clickType;
public SlotClickEvent(IPlayer player, ICustomGui gui, int slotId, IItemStack stack, int dragType, int clickType) {
super(player,gui);
this.slotId = slotId;
this.stack = stack;
this.dragType = dragType;
this.clickType = clickType;
}
}
}