Skip to content

Commit

Permalink
Merge pull request #51 from rytina/fix-car-stuck-in-tiny-gaps
Browse files Browse the repository at this point in the history
Fix cars getting stuck in tiny gaps in dirt path and soul sand
  • Loading branch information
A5H73Y authored Nov 16, 2024
2 parents a2f9e67 + 3f988f3 commit 295a848
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/io/github/a5h73y/carz/listeners/VehicleListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void onVehicleUpdate(VehicleUpdateEvent event) {

Vector vehicleVelocity = event.getVehicle().getVelocity();
Vector playerLocationVelocity = player.getLocation().getDirection();
Block blockBelow = event.getVehicle().getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock();
Block blockBelow = event.getVehicle().getLocation().subtract(0.0D, 0.1D, 0.0D).getBlock();
Material materialBelow = blockBelow.getType();
BlocksConfig blocksConfig = (BlocksConfig) Carz.getConfig(BLOCKS);

Expand All @@ -258,7 +258,7 @@ public void onVehicleUpdate(VehicleUpdateEvent event) {
playerLocation.setPitch(0f);

Location twoBlocksAhead = playerLocation.add(playerLocation.getDirection().multiply(2));
twoBlocksAhead.setY(Math.max(playerLocation.getY() + 1, twoBlocksAhead.getY()));
twoBlocksAhead.setY(Math.max(playerLocation.getY() + getBlockHeight(twoBlocksAhead.getBlock()), twoBlocksAhead.getY()));

// determine if the Car should start climbing
boolean isClimbable = calculateIsClimbable(blockBelow, twoBlocksAhead, blocksConfig);
Expand Down Expand Up @@ -298,6 +298,18 @@ private boolean calculateIsClimbable(Block blockBelow, Location twoBlocksAhead,
return blocksConfig.getClimbBlocks().contains(twoBlocksAhead.getBlock().getType());
}

private double getBlockHeight(Block block) {
switch (block.getType().toString()) {
case "DIRT_PATH":
case "FARMLAND":
case "HONEY_BLOCK":
case "SOUL_SAND":
return 0.1;
default:
return 1.0;
}
}

/**
* Car destroy event.
*
Expand Down

0 comments on commit 295a848

Please sign in to comment.