mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-16 21:31:25 +01:00
Fix random position generator's tendency to move north-west
Fixes the issue of mobs constantly going North-West in pens and other areas backported from 1.8
This commit is contained in:
parent
e35070d9b9
commit
b178d09bd4
@ -0,0 +1,76 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Zach Brown <1254957+zachbr@users.noreply.github.com>
|
||||
Date: Tue, 22 Jul 2014 21:52:19 -0500
|
||||
Subject: [PATCH] Fix random position generator tendency to move north west
|
||||
|
||||
Fixes mobs sticking to one side of pens and "migrating" to the north west constantly
|
||||
Backported fix from 1.8
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/RandomPositionGenerator.java b/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
||||
+++ b/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
||||
@@ -0,0 +0,0 @@ public class RandomPositionGenerator {
|
||||
private static Vec3D c(EntityCreature entitycreature, int i, int j, Vec3D vec3d) {
|
||||
Random random = entitycreature.aI();
|
||||
boolean flag = false;
|
||||
- int k = 0;
|
||||
- int l = 0;
|
||||
- int i1 = 0;
|
||||
+ // PaperSpigot start - int -> double
|
||||
+ double k = 0;
|
||||
+ double l = 0;
|
||||
+ double i1 = 0;
|
||||
+ // PaperSpigot end
|
||||
float f = -99999.0F;
|
||||
boolean flag1;
|
||||
|
||||
@@ -0,0 +0,0 @@ public class RandomPositionGenerator {
|
||||
}
|
||||
|
||||
for (int j1 = 0; j1 < 10; ++j1) {
|
||||
- int k1 = random.nextInt(2 * i) - i;
|
||||
- int l1 = random.nextInt(2 * j) - j;
|
||||
- int i2 = random.nextInt(2 * i) - i;
|
||||
+ // PaperSpigot start - Even distribution and average of 0
|
||||
+ int k1 = random.nextInt(2 * i + 1) - i;
|
||||
+ int l1 = random.nextInt(2 * j + 1) - j;
|
||||
+ int i2 = random.nextInt(2 * i + 1) - i;
|
||||
+ // PaperSpigot end
|
||||
|
||||
if (vec3d == null || (double) k1 * vec3d.a + (double) i2 * vec3d.c >= 0.0D) {
|
||||
- k1 += MathHelper.floor(entitycreature.locX);
|
||||
- l1 += MathHelper.floor(entitycreature.locY);
|
||||
- i2 += MathHelper.floor(entitycreature.locZ);
|
||||
- if (!flag1 || entitycreature.b(k1, l1, i2)) {
|
||||
- float f1 = entitycreature.a(k1, l1, i2);
|
||||
+ // PaperSpigot start - Use truncated absolute destination position for checking things
|
||||
+ int k1Mod = k1 + MathHelper.floor(entitycreature.locX);
|
||||
+ int l1Mod = l1 + MathHelper.floor(entitycreature.locY);
|
||||
+ int i2Mod = i2 + MathHelper.floor(entitycreature.locZ);
|
||||
+ if (!flag1 || entitycreature.b(k1Mod, l1Mod, i2Mod)) {
|
||||
+ float f1 = entitycreature.a(k1Mod, l1Mod, i2Mod);
|
||||
|
||||
if (f1 > f) {
|
||||
f = f1;
|
||||
- k = k1;
|
||||
- l = l1;
|
||||
- i1 = i2;
|
||||
+ // but then the full value to set where to move
|
||||
+ k = entitycreature.locX + k1;
|
||||
+ l = entitycreature.locY + l1;
|
||||
+ i1 = entitycreature.locZ + i2;
|
||||
+ // PaperSpigot end
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class RandomPositionGenerator {
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
- return Vec3D.a((double) k, (double) l, (double) i1);
|
||||
+ return Vec3D.a(k, l, i1); // PaperSpigot remove unnecessary cast
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
--
|
87
Spigot-Server-Patches/mc-dev-imports.patch
Normal file
87
Spigot-Server-Patches/mc-dev-imports.patch
Normal file
@ -0,0 +1,87 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Zach Brown <1254957+zachbr@users.noreply.github.com>
|
||||
Date: Tue, 22 Jul 2014 21:05:53 -0500
|
||||
Subject: [PATCH] mc-dev imports
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/RandomPositionGenerator.java b/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package net.minecraft.server;
|
||||
+
|
||||
+import java.util.Random;
|
||||
+
|
||||
+public class RandomPositionGenerator {
|
||||
+
|
||||
+ private static Vec3D a = Vec3D.a(0.0D, 0.0D, 0.0D);
|
||||
+
|
||||
+ public static Vec3D a(EntityCreature entitycreature, int i, int j) {
|
||||
+ return c(entitycreature, i, j, (Vec3D) null);
|
||||
+ }
|
||||
+
|
||||
+ public static Vec3D a(EntityCreature entitycreature, int i, int j, Vec3D vec3d) {
|
||||
+ a.a = vec3d.a - entitycreature.locX;
|
||||
+ a.b = vec3d.b - entitycreature.locY;
|
||||
+ a.c = vec3d.c - entitycreature.locZ;
|
||||
+ return c(entitycreature, i, j, a);
|
||||
+ }
|
||||
+
|
||||
+ public static Vec3D b(EntityCreature entitycreature, int i, int j, Vec3D vec3d) {
|
||||
+ a.a = entitycreature.locX - vec3d.a;
|
||||
+ a.b = entitycreature.locY - vec3d.b;
|
||||
+ a.c = entitycreature.locZ - vec3d.c;
|
||||
+ return c(entitycreature, i, j, a);
|
||||
+ }
|
||||
+
|
||||
+ private static Vec3D c(EntityCreature entitycreature, int i, int j, Vec3D vec3d) {
|
||||
+ Random random = entitycreature.aI();
|
||||
+ boolean flag = false;
|
||||
+ int k = 0;
|
||||
+ int l = 0;
|
||||
+ int i1 = 0;
|
||||
+ float f = -99999.0F;
|
||||
+ boolean flag1;
|
||||
+
|
||||
+ if (entitycreature.bY()) {
|
||||
+ double d0 = (double) (entitycreature.bV().e(MathHelper.floor(entitycreature.locX), MathHelper.floor(entitycreature.locY), MathHelper.floor(entitycreature.locZ)) + 4.0F);
|
||||
+ double d1 = (double) (entitycreature.bW() + (float) i);
|
||||
+
|
||||
+ flag1 = d0 < d1 * d1;
|
||||
+ } else {
|
||||
+ flag1 = false;
|
||||
+ }
|
||||
+
|
||||
+ for (int j1 = 0; j1 < 10; ++j1) {
|
||||
+ int k1 = random.nextInt(2 * i) - i;
|
||||
+ int l1 = random.nextInt(2 * j) - j;
|
||||
+ int i2 = random.nextInt(2 * i) - i;
|
||||
+
|
||||
+ if (vec3d == null || (double) k1 * vec3d.a + (double) i2 * vec3d.c >= 0.0D) {
|
||||
+ k1 += MathHelper.floor(entitycreature.locX);
|
||||
+ l1 += MathHelper.floor(entitycreature.locY);
|
||||
+ i2 += MathHelper.floor(entitycreature.locZ);
|
||||
+ if (!flag1 || entitycreature.b(k1, l1, i2)) {
|
||||
+ float f1 = entitycreature.a(k1, l1, i2);
|
||||
+
|
||||
+ if (f1 > f) {
|
||||
+ f = f1;
|
||||
+ k = k1;
|
||||
+ l = l1;
|
||||
+ i1 = i2;
|
||||
+ flag = true;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (flag) {
|
||||
+ return Vec3D.a((double) k, (double) l, (double) i1);
|
||||
+ } else {
|
||||
+ return null;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
--
|
Loading…
Reference in New Issue
Block a user