78 lines
3.3 KiB
Diff
78 lines
3.3 KiB
Diff
From 8b0d449cb76d89090aae4723793e9d58a5301d72 Mon Sep 17 00:00:00 2001
|
|
From: Zach Brown <Zbob750@live.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 9342a3f..fa20a7d 100644
|
|
--- a/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
|
+++ b/src/main/java/net/minecraft/server/RandomPositionGenerator.java
|
|
@@ -27,9 +27,11 @@ 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;
|
|
|
|
@@ -43,22 +45,27 @@ 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;
|
|
}
|
|
}
|
|
@@ -66,7 +73,7 @@ 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;
|
|
}
|
|
--
|
|
1.9.1
|
|
|