Skip to content

Commit

Permalink
Fix vehicle guns not working after world reload (#1213)
Browse files Browse the repository at this point in the history
* fix vehicle won't fire after world reload

* correctly fix driver seat state issue

correctly fix driver seat state issue and indention

* refactor EnitySeat driver code as #1213 suggested

* remove another useless code

* remove unnecessary comment

Co-authored-by: ken1882 <qj6w94g0q@gmail.com>
  • Loading branch information
ken1882 authored May 8, 2020
1 parent 03f7621 commit a81fae7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/flansmod/client/ClientRenderHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public void updatePlayerView()
}

EntitySeat seat = ((IControllable)mc.player.getRidingEntity()).getSeat(mc.player);
if(seat != null && seat.driver && FlansMod.proxy.mouseControlEnabled())
if(seat != null && seat.isDriverSeat() && FlansMod.proxy.mouseControlEnabled())
{
seat.applyOrientationToEntity(mc.player);
}
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/flansmod/common/driveables/EntitySeat.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class EntitySeat extends Entity implements IControllable, IEntityAddition
public float playerRoll, prevPlayerRoll;

public Seat seatInfo;
public boolean driver;
public RotatedAxes playerLooking;
public RotatedAxes prevPlayerLooking;
/**
Expand Down Expand Up @@ -121,7 +120,6 @@ public EntitySeat(World world, EntityDriveable d, int id)
driveableID = d.getEntityId();
seatInfo = driveable.getDriveableType().seats[id];
seatID = id;
driver = id == 0;
setPosition(d.posX, d.posY, d.posZ);
playerPosX = prevPlayerPosX = posX;
playerPosY = prevPlayerPosY = posY;
Expand Down Expand Up @@ -185,7 +183,7 @@ public void onUpdate()
// If on the client
if(world.isRemote)
{
if(driver && isThePlayer && FlansMod.proxy.mouseControlEnabled() && driveable.hasMouseControlMode())
if(isDriverSeat() && isThePlayer && FlansMod.proxy.mouseControlEnabled() && driveable.hasMouseControlMode())
{
looking = new RotatedAxes();
playerLooking = new RotatedAxes();
Expand Down Expand Up @@ -551,12 +549,12 @@ public void onMouseMoved(int deltaX, int deltaY)
prevPlayerLooking = playerLooking.clone();

// Driver seat should pass input to driveable
if(driver)
if(isDriverSeat())
{
driveable.onMouseMoved(deltaX, deltaY);
}
// Other seats should look around, but also the driver seat if mouse control mode is disabled
if(!driver || !FlansModClient.controlModeMouse || !driveable.hasMouseControlMode())
if(!isDriverSeat() || !FlansModClient.controlModeMouse || !driveable.hasMouseControlMode())
{
float lookSpeed = 4F;

Expand Down Expand Up @@ -620,7 +618,7 @@ public void updateKeyHeldState(int key, boolean held)
FlansMod.getPacketHandler().sendToServer(new PacketDriveableKeyHeld(key, held));

}
if(driver)
if(isDriverSeat())
{
driveable.updateKeyHeldState(key, held);
}
Expand All @@ -635,7 +633,7 @@ else if(key == 9)
public boolean pressKey(int key, EntityPlayer player, boolean isOnTick)
{
// Driver seat should pass input to driveable
if(driver && driveable != null)
if(isDriverSeat() && driveable != null)
{
return driveable.pressKey(key, player, isOnTick);
}
Expand Down Expand Up @@ -817,6 +815,11 @@ public EntitySeat getSeat(EntityLivingBase living)
{
return this;
}

public boolean isDriverSeat()
{
return seatID == 0;
}

@Override
public boolean startRiding(Entity riding)
Expand Down Expand Up @@ -903,7 +906,6 @@ public void readSpawnData(ByteBuf data)
if(world.getEntityByID(driveableID) instanceof EntityDriveable)
driveable = (EntityDriveable)world.getEntityByID(driveableID);
seatID = data.readInt();
driver = seatID == 0;
if(seatID >= 0 && driveable != null)
{
seatInfo = driveable.getDriveableType().seats[seatID];
Expand Down

0 comments on commit a81fae7

Please sign in to comment.