Merge pull request #21 from c0508383/master

Custom GUI slot fix & Custom Particle fix
This commit is contained in:
Kamron Vaswani authored and GitHub committed 2022-01-14 19:11:15 -05:00
commit e10aa09728
16 files changed
+80 -21

No files matched your search

+5 -1
View File
@@ -69,7 +69,7 @@ public class CustomNpcs {
private static int NewEntityStartId = 0;
@ConfigProp(info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server")
@ConfigProp(info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96.")
public static int NpcNavRange = 32;
@ConfigProp(info = "Set to true if you want the dialog command option to be able to use op commands like tp etc")
@@ -167,6 +167,10 @@ public class CustomNpcs {
if (NpcNavRange < 16) {
NpcNavRange = 16;
}
if (NpcNavRange > 96) {
NpcNavRange = 96;
}
EnchantInterface.load();
CustomItems.load();
@@ -328,6 +328,11 @@ public class EventHooks {
CustomGuiController.onSlotChange(event);
}
public static void onCustomGuiUnfocused(ScriptPlayer player, ICustomGui gui, int textfieldId) {
CustomGuiEvent.UnfocusedEvent event = new CustomGuiEvent.UnfocusedEvent(player, gui, textfieldId);
CustomGuiController.onCustomGuiUnfocused(event);
}
public static void onCustomGuiScrollClick(ScriptPlayer player, ICustomGui gui, int scrollId, int scrollIndex, String[] selection, boolean doubleClick) {
CustomGuiEvent.ScrollEvent event = new CustomGuiEvent.ScrollEvent(player, gui, scrollId, scrollIndex, selection, doubleClick);
CustomGuiController.onScrollClick(event);
@@ -319,7 +319,7 @@ public class NoppesUtilServer {
float alpha1, float alpha2, float alphaRate, int alphaRateStart,
int entityID
){
Server.sendAssociatedData(entity, EnumPacketClient.SCRIPTED_PARTICLE,
Server.sendToAll(EnumPacketClient.SCRIPTED_PARTICLE,
directory, HEXcolor, amount, maxAge,
x, y, z,
motionX, motionY, motionZ, gravity,
@@ -75,24 +75,25 @@ public class PacketHandlerServer{
if(type == EnumPacketServer.IsGuiOpen) {
isGuiOpenPacket(buffer, player);
return;
} else if (type == EnumPacketServer.CustomGuiButton) {
if (player.openContainer instanceof ContainerCustomGui) {
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
EventHooks.onCustomGuiButton((ScriptPlayer)NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt());
return;
}
} else if (type == EnumPacketServer.CustomGuiSlotChange) {
if (player.openContainer instanceof ContainerCustomGui) {
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
EventHooks.onCustomGuiSlot((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt());
return;
}
} else if (type == EnumPacketServer.CustomGuiButton && player.openContainer instanceof ContainerCustomGui) {
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
EventHooks.onCustomGuiButton((ScriptPlayer)NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt());
return;
} else if (type == EnumPacketServer.CustomGuiSlotChange && player.openContainer instanceof ContainerCustomGui) {
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
EventHooks.onCustomGuiSlot((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt());
return;
} else if(type == EnumPacketServer.CustomGuiUnfocused && player.openContainer instanceof ContainerCustomGui) {
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
EventHooks.onCustomGuiUnfocused((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt());
return;
} else if (type == EnumPacketServer.CustomGuiScrollClick && player.openContainer instanceof ContainerCustomGui) {
((ContainerCustomGui) player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
EventHooks.onCustomGuiScrollClick((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt(), buffer.readInt(), CustomGuiController.readScrollSelection(buffer), buffer.readBoolean());
return;
} else if (type == EnumPacketServer.CustomGuiClose) {
EventHooks.onCustomGuiClose((ScriptPlayer)NpcAPI.Instance().getIEntity(player), (new ScriptGui()).fromNBT(Server.readNBT(buffer)));
return;
}
if(type.needsNpc && npc == null){
@@ -55,6 +55,9 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList
addButton(new GuiNpcButtonYesNo(15, guiLeft + 120, y += 22, dialog.disableEsc));
addLabel(new GuiNpcLabel(15, "dialog.disableEsc", guiLeft + 4, y + 5));
addButton(new GuiNpcButtonYesNo(16, guiLeft + 120, y += 22, dialog.darkenScreen));
addLabel(new GuiNpcLabel(16, "Darken Screen", guiLeft + 4, y + 5));
this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 192,98, 20, "gui.done"));
@@ -76,6 +79,9 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList
if(button.id == 15){
dialog.disableEsc = button.getValue() == 1;
}
if(button.id == 15){
dialog.darkenScreen = button.getValue() == 1;
}
if(button.id == 13){
setSubGui(new SubGuiMailmanSendSetup(dialog.mail, getParent()));
}
@@ -466,6 +466,10 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD
}
}
public void onTextFieldUnfocused(CustomGuiTextField textField){
Client.sendData(EnumPacketServer.CustomGuiUnfocused, new Object[]{this.updateGui().toNBT(), textField.getID()});
}
ScriptGui updateGui() {
Iterator var1 = this.dataHolders.iterator();
@@ -537,11 +541,19 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD
this.field_146995_H = false;
if (mouseButton == 0 || mouseButton == 1 || flag) {
int i1 = guiLeft + ((ContainerCustomGui)this.inventorySlots).playerInvX;
int j1 = guiTop + ((ContainerCustomGui)this.inventorySlots).playerInvY;
boolean flag1 = mouseX < i1 || mouseY < j1 || mouseX >= i1 + this.xSize || mouseY >= j1 + this.ySize;
boolean flag1 = true;
int k1 = -1;
for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i)
{
Slot invSlot = (Slot)this.inventorySlots.inventorySlots.get(i);
if (invSlot.equals(slot))
{
flag1 = false;
}
}
if (slot != null) {
k1 = slot.slotNumber;
}
@@ -8,10 +8,12 @@ package noppes.npcs.client.gui.custom.components;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.custom.interfaces.IClickListener;
import noppes.npcs.client.gui.custom.interfaces.IDataHolder;
import noppes.npcs.client.gui.custom.interfaces.IKeyListener;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.scripted.gui.ScriptGuiTextField;
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
@@ -74,7 +76,14 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID
}
public boolean mouseClicked(GuiCustom gui, int mouseX, int mouseY, int mouseButton) {
boolean flag = mouseX >= this.xPosition && mouseX < this.xPosition + this.width && mouseY >= this.yPosition && mouseY < this.yPosition + this.height;
if (this.isFocused() && mouseButton == 0 && !flag){
parent.onTextFieldUnfocused(this);
}
this.mouseClicked(mouseX, mouseY, mouseButton);
return true;
}
}
@@ -56,7 +56,7 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
boolean hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
mc.getTextureManager().bindTexture(this.texture);
this.drawTexturedModalRect(this.textureX, this.textureY, 0, 0, (int)(this.width*this.scale), (int)(this.height*this.scale));
this.drawTexturedModalRect(this.x + this.textureX, this.y + this.textureY, 0, 0, (int)(this.width*this.scale), (int)(this.height*this.scale));
if (hovered && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
@@ -64,6 +64,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose
grabMouse(dialog.showWheel);
guiTop = (height - ySize);
calculateRowHeight();
this.drawDefaultBackground = dialog.darkenScreen;
}
public void grabMouse(boolean grab){
@@ -146,6 +146,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
hookList.add("customGuiButton");
hookList.add("customGuiSlot");
hookList.add("customGuiScroll");
hookList.add("customGuiTextfield");
}
else if(handler instanceof ForgeDataScript) {
hooks.setSize(238, 198);
@@ -78,7 +78,7 @@ public enum EnumPacketServer {
NaturalSpawnGetAll, MailOpenSetup,
DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen,
CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose;
CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused;
public CustomNpcsPermissions.Permission permission = null;
public boolean needsNpc = false;
@@ -57,6 +57,7 @@ public enum EnumScriptType {
CUSTOM_GUI_BUTTON("customGuiButton"),
CUSTOM_GUI_SLOT("customGuiSlot"),
CUSTOM_GUI_SCROLL("customGuiScroll"),
CUSTOM_GUI_TEXTFIELD("customGuiTextfield"),
PICKUP_XP("pickupXP"),
MOUSE_CLICKED("mouseClicked"),
START_USING_ITEM("startItem"),
@@ -83,6 +83,15 @@ public class CustomGuiController {
WrapperNpcAPI.EVENT_BUS.post(event);
}
public static void onCustomGuiUnfocused(CustomGuiEvent.UnfocusedEvent event) {
EntityPlayer player = (EntityPlayer) event.player.getMCEntity();
if (checkGui(event) && getOpenGui(player).getScriptHandler() != null) {
getOpenGui(player).getScriptHandler().callScript(EnumScriptType.CUSTOM_GUI_TEXTFIELD, event);
}
WrapperNpcAPI.EVENT_BUS.post(event);
}
public static void onScrollClick(CustomGuiEvent.ScrollEvent event) {
EntityPlayer player = (EntityPlayer) event.player.getMCEntity();
if (checkGui(event) && getOpenGui(player).getScriptHandler() != null) {
@@ -30,6 +30,7 @@ public class Dialog implements ICompatibilty, IDialog {
public boolean hideNPC = false;
public boolean showWheel = false;
public boolean disableEsc = false;
public boolean darkenScreen = true;
public boolean hasDialogs(EntityPlayer player) {
for(DialogOption option: options.values())
@@ -23,6 +23,15 @@ public class CustomGuiEvent extends Event {
}
}
public static class UnfocusedEvent extends CustomGuiEvent {
public final int textfieldId;
public UnfocusedEvent(IPlayer player, ICustomGui gui, int textfieldId) {
super(player, gui);
this.textfieldId = textfieldId;
}
}
public static class CloseEvent extends CustomGuiEvent {
public CloseEvent(IPlayer player, ICustomGui gui) {
super(player, gui);
@@ -22,12 +22,12 @@ public class ScriptGuiTexturedRect extends ScriptGuiComponent implements ITextur
this.scale = 1.0F;
this.setID(id);
this.setTexture(texture);
this.setPos(GuiCustom.guiLeft + x, GuiCustom.guiTop + y);
this.setPos(x, y);
this.setSize(width, height);
}
public ScriptGuiTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) {
this(id, texture, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, width, height);
this(id, texture, x, y, width, height);
this.setTextureOffset(textureX, textureY);
}