Skip to content

Commit

Permalink
Crashfix with seats
Browse files Browse the repository at this point in the history
- fixed a crash with seats when there weren't any on the train.
- fixed an issue where, because of code for seat compat, players would bypass the lock on a locomotive.
  • Loading branch information
broscolotos committed Jul 20, 2024
1 parent b655aa5 commit 573528f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
16 changes: 16 additions & 0 deletions src/main/java/train/common/api/EntityRollingStock.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,23 @@ public float getPlayerScale() {
*
* @param i
*/
public boolean isLockedAndNotOwner() {
if (this.getTrainLockedFromPacket()) {
if (this.riddenByEntity instanceof EntityPlayer && !((EntityPlayer) this.riddenByEntity).getDisplayName().equalsIgnoreCase(this.getTrainOwner())) {
return true;
}
if (this.seats.size() > 0 && this.seats.get(0).getPassenger() instanceof EntityPlayer && !((EntityPlayer) this.seats.get(0).getPassenger()).getDisplayName().equalsIgnoreCase(this.getTrainOwner())) {
return true;
}
}
return false;
}
public void keyHandlerFromPacket(int i) {
if (this.getTrainLockedFromPacket()) {
if (isLockedAndNotOwner()) {
return;
}
}
this.pressKey(i);
if (i == 7) {
if (this instanceof AbstractWorkCart) {
Expand Down
15 changes: 2 additions & 13 deletions src/main/java/train/common/api/Locomotive.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ public void keyHandlerFromPacket(int i) {
}

if (i == 7) {
((EntityPlayer) seats.get(0).getPassenger()).openGui(Traincraft.instance, GuiIDs.LOCO, worldObj, (int) this.posX, (int) this.posY, (int) this.posZ);
if (seats.size() != 0)
((EntityPlayer) seats.get(0).getPassenger()).openGui(Traincraft.instance, GuiIDs.LOCO, worldObj, (int) this.posX, (int) this.posY, (int) this.posZ);
}

if (i == 12) {
Expand Down Expand Up @@ -970,18 +971,6 @@ public void onUpdate() {
}
}

public boolean isLockedAndNotOwner() {
if (this.getTrainLockedFromPacket()) {
if (this.riddenByEntity instanceof EntityPlayer && !((EntityPlayer) this.riddenByEntity).getDisplayName().equalsIgnoreCase(this.getTrainOwner())) {
return true;
}
if (this.seats.size() > 0 && this.seats.get(0).getPassenger() instanceof EntityPlayer && !((EntityPlayer) this.seats.get(0).getPassenger()).getDisplayName().equalsIgnoreCase(this.getTrainOwner())) {
return true;
}
}
return false;
}


public boolean isNotOwner() {
if (this.riddenByEntity instanceof EntityPlayer && !((EntityPlayer) this.riddenByEntity).getDisplayName().equalsIgnoreCase(this.getTrainOwner())) {
Expand Down

0 comments on commit 573528f

Please sign in to comment.