From 77063b6b11b86dc48d0974c11d8a322c6bd865ce Mon Sep 17 00:00:00 2001 From: broscolotos Date: Tue, 12 Sep 2023 02:40:17 -0500 Subject: [PATCH] More refinement to seat GUI two crash fixes; one for opening any inventory that doesn't have seats and one for spam swapping seats on server. There is one more issue that needs fixed and will be the last:tm: push related to the seat GUI: when in a loco with more than one seat, after changing out of the main seat you can no longer open the GUI to change seats. --- src/main/java/ebf/tim/gui/GUIButton.java | 2 ++ src/main/java/ebf/tim/gui/GUISeatManager.java | 10 ++++-- src/main/java/ebf/tim/gui/GUITransport.java | 36 +------------------ .../ebf/tim/networking/PacketSeatUpdate.java | 13 ++++--- .../java/ebf/tim/utility/ClientProxy.java | 2 ++ .../ebf/tim/utility/TransportSlotManager.java | 8 +++++ 6 files changed, 29 insertions(+), 42 deletions(-) diff --git a/src/main/java/ebf/tim/gui/GUIButton.java b/src/main/java/ebf/tim/gui/GUIButton.java index 50b7831956..8a03580a82 100644 --- a/src/main/java/ebf/tim/gui/GUIButton.java +++ b/src/main/java/ebf/tim/gui/GUIButton.java @@ -111,6 +111,7 @@ else if (this.field_146123_n) { this.drawCenteredString(Minecraft.getMinecraft().fontRenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l); RenderHelper.disableStandardItemLighting(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPopMatrix(); } @@ -162,6 +163,7 @@ protected void drawHoveringText(String p_146283_1_, int p_146283_2_, int p_14628 GL11.glEnable(GL11.GL_DEPTH_TEST); RenderHelper.enableStandardItemLighting(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); } } diff --git a/src/main/java/ebf/tim/gui/GUISeatManager.java b/src/main/java/ebf/tim/gui/GUISeatManager.java index 3ab8eae34b..0477442b2a 100644 --- a/src/main/java/ebf/tim/gui/GUISeatManager.java +++ b/src/main/java/ebf/tim/gui/GUISeatManager.java @@ -26,6 +26,8 @@ public class GUISeatManager extends GUIPaintBucket { public ArrayList filledSeatIDs = new ArrayList<>(); public EntitySeat currentSeat; + public int lastClickTick = 0; + public ArrayList locations; public GUISeatManager(GenericRailTransport transport) { super(transport); @@ -122,8 +124,12 @@ public String getHoverText() { } @Override public void onClick() { - TrainsInMotion.updateChannel.sendToServer(new PacketSeatUpdate(entity.getEntityId(),currentSeat.getPassenger().getEntityId(),entity.seats.indexOf(currentSeat),buttonList.indexOf(this))); - + if (lastClickTick+5 < entity.ticksExisted) { + TrainsInMotion.updateChannel.sendToServer(new PacketSeatUpdate(entity.getEntityId(),currentSeat.getPassenger().getEntityId(),entity.seats.indexOf(currentSeat),buttonList.indexOf(this),entity.dimension)); + lastClickTick = entity.ticksExisted; + } else { + System.out.println("Too fast"); + } } @Override public FontRenderer getFont(){return fontRendererObj;} diff --git a/src/main/java/ebf/tim/gui/GUITransport.java b/src/main/java/ebf/tim/gui/GUITransport.java index eba0a4ada3..ee84aa7dc2 100644 --- a/src/main/java/ebf/tim/gui/GUITransport.java +++ b/src/main/java/ebf/tim/gui/GUITransport.java @@ -263,7 +263,7 @@ public void onClick() { @Override public FontRenderer getFont(){return fontRendererObj;} }); - if (transport.getRiderOffsets().length > 0 || transport.getRiderOffsets() != null) { + if (transport.getRiderOffsets() != null && transport.getRiderOffsets().length > 0) { this.buttons.add(new GUIButton((int)guiLeft+166,(int)guiTop+166, 18,18) { @Override public String getHoverText() { @@ -404,40 +404,6 @@ private void renderTrainInventory(Minecraft mc){ GL11.glEnable(GL11.GL_LIGHTING); } - - /** - *

Render Passenger GUI

- * basically the same as - * todo: set this up just to render the passenger icons and empty seats above the player inventory - */ - private void renderPassengerInventory(Minecraft mc){ - mc.getTextureManager().bindTexture(ClientUtil.vanillaInventory); - GL11.glDisable(GL11.GL_LIGHTING); - int rows=0; - //draw the character backgrounds. - //make a loop that will make a new row every 5 items - for (int i=0;i=5*(rows+1)){ - rows++; - } - ClientUtil.drawTexturedRect(guiLeft + 106 + (30*(i-(rows * 5))), guiTop + 30+(30*rows), 54, 51, 27, 27, 20, 20); - } - //make a new loop that does the same as above but binds the character's face rather than the inventory slot background. - for (int i=0;i=5*(rows+1)){ - rows++; - } - if (i==0 && transport.riddenByEntity instanceof AbstractClientPlayer){ - mc.getTextureManager().bindTexture(((AbstractClientPlayer) transport.riddenByEntity).getLocationSkin()); - ClientUtil.drawTexturedRect(guiLeft + 108 + (30*(i-(rows * 5))), guiTop + 32+(30*rows), 30, 70, 23, 23, 36, 56); - } else if (i>0 && transport.seats.get(i-1).riddenByEntity instanceof AbstractClientPlayer){ - mc.getTextureManager().bindTexture(((AbstractClientPlayer) transport.seats.get(i-1).riddenByEntity).getLocationSkin()); - ClientUtil.drawTexturedRect(guiLeft + 108 + (30*(i-(rows * 5))), guiTop + 32+(30*rows), 30, 70, 23, 23, 36, 56); - } - } - GL11.glEnable(GL11.GL_LIGHTING); - } - /** *

Render Freight GUI

* NOTE: this is only designed for inventory sized with 9 columns. diff --git a/src/main/java/ebf/tim/networking/PacketSeatUpdate.java b/src/main/java/ebf/tim/networking/PacketSeatUpdate.java index f37bbaa876..547b1e059a 100644 --- a/src/main/java/ebf/tim/networking/PacketSeatUpdate.java +++ b/src/main/java/ebf/tim/networking/PacketSeatUpdate.java @@ -19,14 +19,15 @@ */ public class PacketSeatUpdate implements IMessage { /**the ID of the entity to dismount from*/ - private int rollingStockId, playerId, oldSeatIndex, newSeatIndex; + private int rollingStockId, playerId, oldSeatIndex, newSeatIndex, dimension; public PacketSeatUpdate() {} - public PacketSeatUpdate(int rollingStockId, int playerId, int oldSeatIndex, int newSeatIndex) { + public PacketSeatUpdate(int rollingStockId, int playerId, int oldSeatIndex, int newSeatIndex, int dimension) { this.rollingStockId = rollingStockId; this.playerId = playerId; this.oldSeatIndex = oldSeatIndex; this.newSeatIndex = newSeatIndex; + this.dimension = dimension; } /**reads the packet on server to get the variables from the Byte Buffer*/ @Override @@ -35,6 +36,7 @@ public void fromBytes(ByteBuf bbuf) { playerId=bbuf.readInt(); oldSeatIndex=bbuf.readInt(); newSeatIndex=bbuf.readInt(); + dimension=bbuf.readInt(); } /**puts the variables into a Byte Buffer so they can be sent to server*/ @Override @@ -43,6 +45,7 @@ public void toBytes(ByteBuf bbuf) { bbuf.writeInt(playerId); bbuf.writeInt(oldSeatIndex); bbuf.writeInt(newSeatIndex); + bbuf.writeInt(dimension); } public static class Handler implements IMessageHandler { @@ -61,12 +64,12 @@ public static class Handler implements IMessageHandler 0) { //TODO: this feels super janky and it feels like this should be added in getPermissions + for(EntitySeat seat : ((GenericRailTransport) hostInventory).seats) { + if (seat.getPassenger() == player && ((GenericRailTransport) hostInventory).seats.indexOf(seat) != 0) { + return true; + } + } + } return (hostInventory instanceof GenericRailTransport?((GenericRailTransport)hostInventory).getPermissions(player, hostInventory instanceof EntityTrainCore, false): hostInventory!=null); } }