From 9bc40493a3f5ea12dcf32d55b0de0ad986dee99b Mon Sep 17 00:00:00 2001 From: Jakllp <57708725+Jakllp@users.noreply.github.com> Date: Mon, 7 Mar 2022 13:35:28 +0100 Subject: [PATCH] Field-Fix and Pitching Added: - Pitching the car on ascent/descent through the config-value `cars.general.enablePitch` which is defaulted to true Fixed: - Fixed some field-stuff --- .../com/useful/ucars/CartOrientationUtil.java | 16 ++++++++-------- .../java/com/useful/ucars/uCarsListener.java | 15 ++++++++++++++- src/main/java/com/useful/ucars/ucars.java | 3 +++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/useful/ucars/CartOrientationUtil.java b/src/main/java/com/useful/ucars/CartOrientationUtil.java index 3506f91..47308ba 100644 --- a/src/main/java/com/useful/ucars/CartOrientationUtil.java +++ b/src/main/java/com/useful/ucars/CartOrientationUtil.java @@ -3,6 +3,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; +import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.Minecart; @@ -39,15 +40,13 @@ public static void setPitch(Entity cart, float pitch){ Method getHandle = cmr.getMethod("getHandle"); Object nmsCart = getHandle.invoke(cmr.cast(cart)); Field p = null; - Class ema; + Class ema = Reflect.getNMSClass("world.entity.","Entity"); if(ucars.MCVersion.get(0) == 1) { if(ucars.MCVersion.get(1) >= 18) { - ema = Reflect.getNMSClass("world.entity.","Entity"); - p = ema.getField("aB"); + p = ema.getDeclaredField("aB"); } else if(ucars.MCVersion.get(1) == 17) { - ema = Reflect.getNMSClass("world.entity.","Entity"); - p = ema.getField("az"); + p = ema.getDeclaredField("az"); } else { ema = Reflect.getNMSClass("world.entity.vehicle.","EntityMinecartAbstract"); p = ema.getField("pitch"); @@ -72,16 +71,17 @@ public static void setYaw(Entity cart, float yaw){ try { Class cmr = cart.getClass(); Method getHandle = cmr.getMethod("getHandle"); - Class ema = Reflect.getNMSClass("world.entity.vehicle.","EntityMinecartAbstract"); + Class ema = Reflect.getNMSClass("world.entity.","Entity"); Object nmsCart = getHandle.invoke(cmr.cast(cart)); Field p = null; if(ucars.MCVersion.get(0) == 1) { if(ucars.MCVersion.get(1) >= 18) { - p = ema.getField("aA"); + p = ema.getDeclaredField("aA"); } else if(ucars.MCVersion.get(1) == 17) { - p = ema.getField("ay"); + p = ema.getDeclaredField("ay"); } else { + ema = Reflect.getNMSClass("world.entity.vehicle.","EntityMinecartAbstract"); p = ema.getField("yaw"); } } diff --git a/src/main/java/com/useful/ucars/uCarsListener.java b/src/main/java/com/useful/ucars/uCarsListener.java index c5a26dd..26e048c 100644 --- a/src/main/java/com/useful/ucars/uCarsListener.java +++ b/src/main/java/com/useful/ucars/uCarsListener.java @@ -80,6 +80,7 @@ public class uCarsListener implements Listener { private Boolean fuelEnabled = false; private Boolean fuelUseItems = false; private Boolean disableFallDamage = false; + private Boolean pitchEnabled = true; private double defaultSpeed = 30; private static double defaultHealth = 10; @@ -1260,7 +1261,18 @@ public void run() { car.setVelocity(calculateCarStats(car, player, travel, multiplier)); } - + + //Pitch the car + if(travel.getY()!=0 && pitchEnabled) { + if(travel.getY()<0) { + CartOrientationUtil.setPitch(car, (float) (-35*travel.getY())); + } else { + CartOrientationUtil.setPitch(car, (float) (-20*travel.getY())); + } + } else { + CartOrientationUtil.setPitch(car, 0); + } + // Recalculate car health if (recalculateHealth) { updateCarHealthHandler(car, health); @@ -2111,6 +2123,7 @@ public void init() { fuelEnabled = ucars.config.getBoolean("general.cars.fuel.enable"); fuelUseItems = ucars.config.getBoolean("general.cars.fuel.items.enable"); disableFallDamage = ucars.config.getBoolean("general.cars.fallDamageDisabled"); + pitchEnabled = ucars.config.getBoolean("general.cars.enablePitch"); if(roadBlocksEnabled){ List ids = ucars.config diff --git a/src/main/java/com/useful/ucars/ucars.java b/src/main/java/com/useful/ucars/ucars.java index 671e5d0..bb19f5b 100644 --- a/src/main/java/com/useful/ucars/ucars.java +++ b/src/main/java/com/useful/ucars/ucars.java @@ -369,6 +369,9 @@ public void onEnable() { if (!config.contains("general.permissions.enable")) { config.set("general.permissions.enable", true); } + if (!config.contains("general.cars.enablePitch")) { + config.set("general.cars.enablePitch", true); + } if (!config.contains("general.cars.defSpeed")) { config.set("general.cars.defSpeed", (double) 30); }