Skip to content

Commit

Permalink
More refinement to seat GUI
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
broscolotos committed Sep 12, 2023
1 parent 5fc3418 commit 77063b6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/main/java/ebf/tim/gui/GUIButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/ebf/tim/gui/GUISeatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class GUISeatManager extends GUIPaintBucket {
public ArrayList<Integer> filledSeatIDs = new ArrayList<>();
public EntitySeat currentSeat;

public int lastClickTick = 0;

public ArrayList<Vector2f> locations;
public GUISeatManager(GenericRailTransport transport) {
super(transport);
Expand Down Expand Up @@ -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;}
Expand Down
36 changes: 1 addition & 35 deletions src/main/java/ebf/tim/gui/GUITransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -404,40 +404,6 @@ private void renderTrainInventory(Minecraft mc){
GL11.glEnable(GL11.GL_LIGHTING);
}


/**
* <h2>Render Passenger GUI</h2>
* 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<transport.getRiderOffsets().length; i++) {
if (i/(rows+1) >=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<transport.getRiderOffsets().length; i++) {
if (i/(rows+1) >=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);
}

/**
* <h2>Render Freight GUI</h2>
* NOTE: this is only designed for inventory sized with 9 columns.
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/ebf/tim/networking/PacketSeatUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<PacketSeatUpdate,IMessage> {
Expand All @@ -61,12 +64,12 @@ public static class Handler implements IMessageHandler<PacketSeatUpdate,IMessage
}
oldSeat = rollingStockEntity.seats.get(message.oldSeatIndex);
newSeat = rollingStockEntity.seats.get(message.newSeatIndex);
newSeat.addPassenger(playerEntity);
oldSeat.removePassenger(playerEntity);
newSeat.addPassenger(playerEntity);
playerEntity.mountEntity(newSeat);
if (ctx.side == Side.SERVER) {
TrainsInMotion.updateChannel.sendToAllAround(new PacketSeatUpdate(message.rollingStockId,message.playerId,message.oldSeatIndex,message.newSeatIndex),
new NetworkRegistry.TargetPoint(playerEntity.dimension,rollingStockEntity.posX,rollingStockEntity.posY,rollingStockEntity.posZ,256D));
TrainsInMotion.updateChannel.sendToAllAround(new PacketSeatUpdate(message.rollingStockId,message.playerId,message.oldSeatIndex,message.newSeatIndex, message.dimension),
new NetworkRegistry.TargetPoint(message.dimension,rollingStockEntity.posX,rollingStockEntity.posY,rollingStockEntity.posZ,256D));
}
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ebf/tim/utility/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import ebf.tim.TrainsInMotion;
import ebf.tim.blocks.BlockDynamic;
import ebf.tim.entities.EntityBogie;
import ebf.tim.entities.EntitySeat;
import ebf.tim.entities.EntityTrainCore;
import ebf.tim.entities.GenericRailTransport;
import ebf.tim.gui.*;
import ebf.tim.items.ItemCraftGuide;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ebf/tim/utility/TransportSlotManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ebf.tim.blocks.TileEntityStorage;
import ebf.tim.entities.EntitySeat;
import ebf.tim.entities.EntityTrainCore;
import ebf.tim.entities.GenericRailTransport;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -642,6 +643,13 @@ public void onContainerClosed(EntityPlayer p_75134_1_) {
*/
@Override
public boolean canInteractWith(EntityPlayer player) {
if (((GenericRailTransport) hostInventory).seats.size() > 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);
}
}

0 comments on commit 77063b6

Please sign in to comment.