Skip to content

Commit

Permalink
Climbing exclusion tweaks
Browse files Browse the repository at this point in the history
Fixes:
- Better ignoreJump-System
- You can now get off of "softblocks" (Blocks with a full Hitbox even though entities are slightly lower when standing on them)

Tweaks:
- Fixed getting driving passenger
- Removed some Legacy-Materials

Internal:
- Version number is now controlled by pom.xml

Bump to 1.16-R1.1.2
  • Loading branch information
Jakllp committed Jun 30, 2021
1 parent 30e10e5 commit dd56b45
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 71 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<version>1.16-R1.1.1</version>
<version>1.16-R1.1.2</version>
</project>
110 changes: 41 additions & 69 deletions src/main/java/com/useful/ucars/uCarsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
public class uCarsListener implements Listener {
private ucars plugin;
private List<String> ignoreJump = null;
private List<String> softBlocks = null;

private static double GRAVITY_Y_VELOCITY_MAGNITUDE = 0.04;
private static double SIMULATED_FRICTION_SPEED_MULTIPLIER = 0.55;
Expand Down Expand Up @@ -342,14 +343,14 @@ public boolean inACar(Player p) {
}

public Entity getDrivingPassengerOfCar(Vehicle vehicle){ //Get the PLAYER passenger of the car
Entity passenger = vehicle.getPassenger(); //The vehicle's lowest passenger; may be a pig, etc... if pigucarting
if (passenger == null || !(vehicle instanceof Entity)) { //If it has nobody riding it, ignore it
if (vehicle.getPassengers().isEmpty() || !(vehicle instanceof Entity)) { //If it has nobody riding it, ignore it
return null;
}
Entity passenger = vehicle.getPassengers().get(0); //The vehicle's lowest passenger; may be a pig, etc... if pigucarting
if (!(passenger instanceof Player)) { //If not a player riding it; then keep looking until we find a player
while (!(passenger instanceof Player)
&& passenger.getPassenger() != null) { //While there's more entities above this in the 'stack'
passenger = passenger.getPassenger(); //Keep iterating
&& !passenger.getPassengers().isEmpty()) { //While there's more entities above this in the 'stack'
passenger = passenger.getPassengers().get(0); //Keep iterating
}
}
return passenger;
Expand Down Expand Up @@ -565,8 +566,7 @@ public void tickCalcsAndLegacy(VehicleUpdateEvent event) {
CarHealthData health = getCarHealthHandler(car);
Boolean recalculateHealth = false;
// Calculate health based on location
if (normalblock.getType().equals(Material.WATER)
|| normalblock.getType().equals(Material.LEGACY_STATIONARY_WATER)) {
if (normalblock.getType().equals(Material.WATER)) {
double damage = damage_water;
if (damage > 0) {
if (driven) {
Expand All @@ -587,8 +587,7 @@ public void tickCalcsAndLegacy(VehicleUpdateEvent event) {
recalculateHealth = true;
}
}
if (normalblock.getType().equals(Material.LAVA)
|| normalblock.getType().equals(Material.LEGACY_STATIONARY_LAVA)) {
if (normalblock.getType().equals(Material.LAVA)) {
double damage = damage_lava;
if (damage > 0) {
if (driven) {
Expand Down Expand Up @@ -907,19 +906,19 @@ public void onUcarUpdate(ucarUpdateEvent event) {
Vector faceDirVec = new Vector(fx, faceDir.getModY(), fz);
before=before.add(faceDirVec);
//Add the length of the car in so that we are able to climb up blocks with an entity that has length
Vector toRightOfFaceDir = unitVec.clone().crossProduct(new Vector(0,1,0));
before=before.add(unitVec.clone().multiply(length*0.5));
Location frontRight = before.clone().add(unitVec.clone().multiply(length*0.5));
Location frontLeft = before.clone().add(unitVec.clone().multiply(length*-0.5));
Block block = before.getBlock(); //Block we're driving into
Block frontRightInFront = frontRight.getBlock();
Block frontLeftInFront = frontLeft.getBlock();
//Hackish way to make this able to jump for wider vehicles
if(ignoreJump.contains(block.getType().name())){
if(!ignoreJump.contains(frontRightInFront.getType().name())){
boolean blockNoJump = noJump(block.getType().name());
if(blockNoJump){
if(!noJump(frontRightInFront.getType().name())){
block = frontRightInFront;
}
else if(!ignoreJump.contains(frontLeftInFront.getType().name())){
else if(!noJump(frontLeftInFront.getType().name())){
block = frontLeftInFront;
}
}
Expand Down Expand Up @@ -1039,7 +1038,6 @@ else if (fuelEnabled
travel.setY(newy);
}*/

Material bType = block.getType();
Boolean fly = false; // Fly is the 'easter egg' slab elevator
if (normalblock.getRelative(faceDir).getType().name().toLowerCase().contains("slab")) {
// If looking at slabs
Expand Down Expand Up @@ -1180,8 +1178,9 @@ public void run() {
cont = !plugin.isBlockEqualToConfigIds(barriers, block) && !plugin.isBlockEqualToConfigIds(barriers, frontLeftInFront) && !plugin.isBlockEqualToConfigIds(barriers, frontRightInFront);

Boolean inStairs = false;
Material carBlock = car.getLocation().getBlock().getType();
if (carBlock.name().toLowerCase().contains("stairs")) {
Block carBlock = car.getLocation().getBlock();
Material carBlockType = carBlock.getType();
if (carBlockType.name().toLowerCase().contains("stairs")) {
inStairs = true;
}
if (UEntityMeta.hasMetadata(car, "car.ascending")) {
Expand All @@ -1190,23 +1189,21 @@ public void run() {
//player.sendMessage(block.getType().name()+" "+faceDir+" "+fx+" "+fz);
// Make cars jump if needed
if (inStairs ||
(!ignoreJump.contains(bType.name().toUpperCase()) && cont && modY)) { //Should jump
/* player.sendMessage("Obstruction ahead");
player.sendMessage("above: "+bidU);*/
(!blockNoJump && !block.isPassable() && cont && modY &&
!(softBlocks.contains(block.getType().name()) && softBlocks.contains(carBlockType.name()) ) )) { //Softblocks floating problem
//Should jump

boolean calculated = false;
if (bidU == Material.AIR || bidU == Material.LAVA
|| bidU == Material.LEGACY_STATIONARY_LAVA || bidU == Material.WATER
|| bidU == Material.LEGACY_STATIONARY_WATER /*|| bidU == Material.STEP */
|| bidU == Material.LEGACY_CARPET
/*|| bidU == Material.DOUBLE_STEP*/ || inStairs) { //Clear air above
if (bidU == Material.AIR || bidU == Material.LAVA || bidU == Material.WATER || bidUpLoc.getBlock().isPassable() || noJump(bidU.name()) || inStairs) { //Clear air above
theNewLoc.add(0, 1.5d, 0);
double y = 0.0;
if(block.getBoundingBox().getMaxY() != car.getLocation().getBlock().getBoundingBox().getMaxY()) { //Check if we're staying on the same level (slabs, carpet etc -> no need to climb if not)
if(block.getBoundingBox().getMaxY() != car.getLocation().getBlock().getBoundingBox().getMaxY() ||
(car.getBoundingBox().getMinY() < car.getLocation().getBlock().getBoundingBox().getMaxY() && !inStairs)) { //Check if we're staying on the same level (slabs, carpet etc -> no need to climb if not)
calculated = true;
y = block.getBoundingBox().getMaxY()-block.getLocation().getBlockY() + 0.2;
}

if (carBlock.name().toLowerCase()
if (carBlockType.name().toLowerCase()
.contains(Pattern.quote("stairs"))
// ||
// underblock.getType().name().toLowerCase().contains(Pattern.quote("stairs"))
Expand Down Expand Up @@ -1237,7 +1234,7 @@ public void run() {
}
}
}
if (fly && cont && (bidUpLoc.getBlock().getType().name().toLowerCase().contains("slab") || underblock.isEmpty() && !carBlock.name().toLowerCase().contains("slab"))) {
if (fly && cont && (bidUpLoc.getBlock().getType().name().toLowerCase().contains("slab") || underblock.isEmpty() && !carBlockType.name().toLowerCase().contains("slab"))) {
// Make the car ascend (easter egg, slab elevator)
travel.setY(0.1); // Make a little easier
UEntityMeta.setMetadata(car, "car.ascending", new StatValue(null, plugin));
Expand Down Expand Up @@ -1339,10 +1336,7 @@ void hitByCar(VehicleEntityCollisionEvent event) {
return;
}

Entity passenger = cart.getPassengers().get(0);
while (!passenger.isEmpty()) {
passenger = passenger.getPassengers().get(0);
}
Entity passenger = getDrivingPassengerOfCar(cart);
if(passenger.equals(ent) || cart.getPassengers().contains(ent)){
return; //Player being hit is in the car
}
Expand Down Expand Up @@ -1508,7 +1502,7 @@ void interact(PlayerInteractEvent event) {
return;
}
Block block = event.getClickedBlock();
if (uCarsAPI.getAPI().isuCarsHandlingPlacingCars() && (plugin.API.hasItemCarCheckCriteria() || event.getPlayer().getItemInHand().getType() == Material.MINECART)) {
if (uCarsAPI.getAPI().isuCarsHandlingPlacingCars() && (plugin.API.hasItemCarCheckCriteria() || event.getPlayer().getInventory().getItemInMainHand().getType() == Material.MINECART)) {
// Its a minecart!
Material iar = block.getType();
if (ucars.ignoreRails && (iar == Material.RAIL || iar == Material.ACTIVATOR_RAIL
Expand Down Expand Up @@ -2069,46 +2063,24 @@ public void run() {
};
}*/

public boolean noJump(String bName) {
for(String str:ignoreJump) {
if(bName.contains(str)) {return true;}
}
return false;
}

public void init() {
ignoreJump = new ArrayList<String>();
ignoreJump.add("AIR"); //Air
ignoreJump.add("LAVA"); //Lava
ignoreJump.add("STATIONARY_LAVA"); //Lava
ignoreJump.add("WATER"); //Water
ignoreJump.add("STATIONARY_WATER"); //Water
ignoreJump.add("COBBLE_WALL"); //Cobble wall
ignoreJump.add("FENCE"); //fence
ignoreJump.add("NETHER_FENCE"); //Nether fence
ignoreJump.add("STONE_PLATE"); //Stone pressurepad
ignoreJump.add("WOOD_PLATE"); //Wood pressurepad
ignoreJump.add("TRIPWIRE"); // tripwires
ignoreJump.add("TRIPWIRE_HOOK"); // tripwires
ignoreJump.add("TORCH"); // torches
ignoreJump.add("REDSTONE_TORCH_ON"); // redstone torches
ignoreJump.add("REDSTONE_TORCH_OFF"); // redstone off torches
ignoreJump.add("DIODE_BLOCK_OFF"); // repeater off
ignoreJump.add("DIODE_BLOCK_ON"); // repeater on
ignoreJump.add("REDSTONE_COMPARATOR_OFF"); // comparator off
ignoreJump.add("REDSTONE_COMPARATOR_ON"); // comparator on
ignoreJump.add("VINE"); // vines
ignoreJump.add("LONG_GRASS"); // Tall grass
ignoreJump.add("GRASS");
ignoreJump.add("STONE_BUTTON"); // stone button
ignoreJump.add("WOOD_BUTTON"); // wood button
ignoreJump.add("FENCE_GATE"); // fence gate
ignoreJump.add("LEVER"); // lever
ignoreJump.add("SNOW"); // snow
ignoreJump.add("DAYLIGHT_DETECTOR"); // daylight detector
ignoreJump.add("SIGN_POST"); // sign
ignoreJump.add("WALL_SIGN"); // sign on the side of a block
ignoreJump.add(Material.ACACIA_FENCE.name());
ignoreJump.add(Material.ACACIA_FENCE_GATE.name());
ignoreJump.add(Material.BIRCH_FENCE.name());
ignoreJump.add(Material.BIRCH_FENCE_GATE.name());
ignoreJump.add(Material.JUNGLE_FENCE.name());
ignoreJump.add(Material.JUNGLE_FENCE_GATE.name());
/*ignoreJump.add("CARPET"); // carpet
*/
ignoreJump.add("WALL");
ignoreJump.add("FENCE");
ignoreJump.add("GATE");

softBlocks = new ArrayList<String>();
softBlocks.add("SNOW");
softBlocks.add("SOUL_SAND");
softBlocks.add("HONEY_BLOCK");

usePerms = ucars.config.getBoolean("general.permissions.enable");
carsEnabled = ucars.config.getBoolean("general.cars.enable");
defaultHealth = ucars.config.getDouble("general.cars.health.default");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: uCars
main: com.useful.ucars.ucars
version: 25.2
version: ${project.version}
api-version: 1.13
softdepend: [Vault]
depend: [ProtocolLib]
Expand Down

0 comments on commit dd56b45

Please sign in to comment.