From 4e3ee63303ce64a12f14f32b820d71537890ff27 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 27 Jul 2020 17:49:17 +0800 Subject: [PATCH] Backport boat movement to 1.8.8 --- .../entity/nonliving/BoatController.java | 3 - .../entity/nonliving/BoatController.java | 132 ++++++++++++++++++ 2 files changed, 132 insertions(+), 3 deletions(-) diff --git a/v1_16_R1/src/main/java/net/citizensnpcs/nms/v1_16_R1/entity/nonliving/BoatController.java b/v1_16_R1/src/main/java/net/citizensnpcs/nms/v1_16_R1/entity/nonliving/BoatController.java index 08834f682..9a5667b42 100644 --- a/v1_16_R1/src/main/java/net/citizensnpcs/nms/v1_16_R1/entity/nonliving/BoatController.java +++ b/v1_16_R1/src/main/java/net/citizensnpcs/nms/v1_16_R1/entity/nonliving/BoatController.java @@ -205,10 +205,7 @@ public class BoatController extends MobEntityController { } move(EnumMoveType.SELF, getMot()); if (isVehicle()) { - float f = 0.0F; this.yaw += this.ar; - setMot(getMot().add((MathHelper.sin(-this.yaw * 0.017453292F) * f), 0.0D, - (MathHelper.cos(this.yaw * 0.017453292F) * f))); } } else { super.tick(); diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/BoatController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/BoatController.java index d4a3a312b..b6fa47ee8 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/BoatController.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/nonliving/BoatController.java @@ -4,6 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_8_R3.CraftServer; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftBoat; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory; import org.bukkit.entity.Boat; import org.bukkit.util.Vector; @@ -14,7 +15,15 @@ import net.citizensnpcs.nms.v1_8_R3.util.NMSImpl; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.util.Util; +import net.minecraft.server.v1_8_R3.AxisAlignedBB; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.Blocks; import net.minecraft.server.v1_8_R3.EntityBoat; +import net.minecraft.server.v1_8_R3.EntityLiving; +import net.minecraft.server.v1_8_R3.EnumParticle; +import net.minecraft.server.v1_8_R3.Material; +import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.NBTTagCompound; import net.minecraft.server.v1_8_R3.World; @@ -43,6 +52,7 @@ public class BoatController extends MobEntityController { } public static class EntityBoatNPC extends EntityBoat implements NPCHolder { + private double b; private final CitizensNPC npc; public EntityBoatNPC(World world) { @@ -117,9 +127,131 @@ public class BoatController extends MobEntityController { public void t_() { if (npc != null) { npc.update(); + updateBoat(); } else { super.t_(); } } + + private void updateBoat() { + this.lastX = this.locX; + this.lastY = this.locY; + this.lastZ = this.locZ; + byte b0 = 5; + double d0 = 0.0D; + for (int i = 0; i < b0; i++) { + double d1 = (getBoundingBox()).b + ((getBoundingBox()).e - (getBoundingBox()).b) * (i + 0) / b0 + - 0.125D; + double d2 = (getBoundingBox()).b + ((getBoundingBox()).e - (getBoundingBox()).b) * (i + 1) / b0 + - 0.125D; + AxisAlignedBB axisalignedbb = new AxisAlignedBB((getBoundingBox()).a, d1, (getBoundingBox()).c, + (getBoundingBox()).d, d2, (getBoundingBox()).f); + if (this.world.b(axisalignedbb, Material.WATER)) + d0 += 1.0D / b0; + } + double d3 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ); + if (d3 > 0.2975D) { + double d4 = Math.cos(this.yaw * Math.PI / 180.0D); + double d5 = Math.sin(this.yaw * Math.PI / 180.0D); + for (int j = 0; j < 1.0D + d3 * 60.0D; j++) { + double d6 = (this.random.nextFloat() * 2.0F - 1.0F); + double d7 = (this.random.nextInt(2) * 2 - 1) * 0.7D; + if (this.random.nextBoolean()) { + double d8 = this.locX - d4 * d6 * 0.8D + d5 * d7; + double d9 = this.locZ - d5 * d6 * 0.8D - d4 * d7; + this.world.addParticle(EnumParticle.WATER_SPLASH, d8, this.locY - 0.125D, d9, this.motX, + this.motY, this.motZ, new int[0]); + } else { + double d8 = this.locX + d4 + d5 * d6 * 0.7D; + double d9 = this.locZ + d5 - d4 * d6 * 0.7D; + this.world.addParticle(EnumParticle.WATER_SPLASH, d8, this.locY - 0.125D, d9, this.motX, + this.motY, this.motZ, new int[0]); + } + } + } + if (d0 < 1.0D) { + double d = d0 * 2.0D - 1.0D; + this.motY += 0.04D * d; + } else { + if (this.motY < 0.0D) + this.motY /= 2.0D; + this.motY += 0.007D; + } + if (this.passenger instanceof EntityLiving) { + EntityLiving entityliving = (EntityLiving) this.passenger; + float f = this.passenger.yaw + -entityliving.aZ * 90.0F; + this.motX += -Math.sin((f * 3.1415927F / 180.0F)) * this.b * entityliving.ba * 0.05000000074505806D; + this.motZ += Math.cos((f * 3.1415927F / 180.0F)) * this.b * entityliving.ba * 0.05000000074505806D; + } else if (this.unoccupiedDeceleration >= 0.0D) { + this.motX *= this.unoccupiedDeceleration; + this.motZ *= this.unoccupiedDeceleration; + if (this.motX <= 1.0E-5D) + this.motX = 0.0D; + if (this.motZ <= 1.0E-5D) + this.motZ = 0.0D; + } + double d4 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ); + if (d4 > 0.35D) { + double d = 0.35D / d4; + this.motX *= d; + this.motZ *= d; + d4 = 0.35D; + } + if (d4 > d3 && this.b < 0.35D) { + this.b += (0.35D - this.b) / 35.0D; + if (this.b > 0.35D) + this.b = 0.35D; + } else { + this.b -= (this.b - 0.07D) / 35.0D; + if (this.b < 0.07D) + this.b = 0.07D; + } + for (int k = 0; k < 4; k++) { + int l = MathHelper.floor(this.locX + ((k % 2) - 0.5D) * 0.8D); + int j = MathHelper.floor(this.locZ + ((k / 2) - 0.5D) * 0.8D); + for (int i1 = 0; i1 < 2; i1++) { + int j1 = MathHelper.floor(this.locY) + i1; + BlockPosition blockposition = new BlockPosition(l, j1, j); + Block block = this.world.getType(blockposition).getBlock(); + if (block == Blocks.SNOW_LAYER) { + if (!CraftEventFactory.callEntityChangeBlockEvent(this, l, j1, j, Blocks.AIR, 0) + .isCancelled()) { + this.world.setAir(blockposition); + this.positionChanged = false; + } + } else if (block == Blocks.WATERLILY) { + if (!CraftEventFactory.callEntityChangeBlockEvent(this, l, j1, j, Blocks.AIR, 0) + .isCancelled()) { + this.world.setAir(blockposition, true); + this.positionChanged = false; + } + } + } + } + if (this.onGround && !this.landBoats) { + this.motX *= 0.5D; + this.motY *= 0.5D; + this.motZ *= 0.5D; + } + move(this.motX, this.motY, this.motZ); + if (this.positionChanged && d3 > 0.2975D) { + } else { + this.motX *= 0.99D; + this.motY *= 0.95D; + this.motZ *= 0.99D; + } + this.pitch = 0.0F; + double d5 = this.yaw; + double d10 = this.lastX - this.locX; + double d11 = this.lastZ - this.locZ; + if (d10 * d10 + d11 * d11 > 0.001D) + d5 = (float) (MathHelper.b(d11, d10) * 180.0D / Math.PI); + double d12 = MathHelper.g(d5 - this.yaw); + if (d12 > 20.0D) + d12 = 20.0D; + if (d12 < -20.0D) + d12 = -20.0D; + this.yaw += d12; + } } } \ No newline at end of file