mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 18:45:54 +01:00
Improve NavigationListener patches.
reduces diff and cleans up implementation of goals greatly.
This commit is contained in:
parent
d9853fab8e
commit
354ed8ed65
@ -1,11 +1,11 @@
|
||||
From 919039afb553383de586fa3c5eecd56dab683712 Mon Sep 17 00:00:00 2001
|
||||
From 30ba4b11e81ab0057e2762deabc9f74957c60159 Mon Sep 17 00:00:00 2001
|
||||
From: Sudzzy <originmc@outlook.com>
|
||||
Date: Wed, 2 Mar 2016 14:48:03 -0600
|
||||
Subject: [PATCH] Disable explosion knockback
|
||||
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
||||
index 8d6e0a2..6b5067a 100644
|
||||
index 1c8e310..694b448 100644
|
||||
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
||||
@@ -213,4 +213,9 @@ public class PaperWorldConfig {
|
||||
@ -19,10 +19,10 @@ index 8d6e0a2..6b5067a 100644
|
||||
+ }
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
||||
index 0248a9e..2e671fd 100644
|
||||
index 0a75123..aef9cb7 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
||||
@@ -852,12 +852,14 @@ public abstract class EntityLiving extends Entity {
|
||||
@@ -851,12 +851,14 @@ public abstract class EntityLiving extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ index 0248a9e..2e671fd 100644
|
||||
this.world.broadcastEntityEffect(this, (byte) 2);
|
||||
}
|
||||
|
||||
@@ -881,6 +883,8 @@ public abstract class EntityLiving extends Entity {
|
||||
@@ -880,6 +882,8 @@ public abstract class EntityLiving extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
From 109e5cd2ebdbd397a04cc135c465e1e655adea0a Mon Sep 17 00:00:00 2001
|
||||
From ec613026d5eee3c631569a806a4342cca6153443 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Thu, 3 Mar 2016 04:00:11 -0600
|
||||
Subject: [PATCH] Timings v2
|
||||
@ -290,7 +290,7 @@ index dd3abb8..a0186ef 100644
|
||||
import org.bukkit.craftbukkit.util.Waitable;
|
||||
import org.bukkit.event.server.RemoteServerCommandEvent;
|
||||
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
||||
index a6c1136..c2771e7 100644
|
||||
index 768b6e7..2406968 100644
|
||||
--- a/src/main/java/net/minecraft/server/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/server/Entity.java
|
||||
@@ -24,7 +24,8 @@ import org.bukkit.block.BlockFace;
|
||||
@ -329,7 +329,7 @@ index a6c1136..c2771e7 100644
|
||||
|
||||
public void recalcPosition() {
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
||||
index 2e671fd..b10475f 100644
|
||||
index aef9cb7..847dafd 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
||||
@@ -23,7 +23,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
@ -341,7 +341,7 @@ index 2e671fd..b10475f 100644
|
||||
|
||||
public abstract class EntityLiving extends Entity {
|
||||
|
||||
@@ -1686,7 +1686,6 @@ public abstract class EntityLiving extends Entity {
|
||||
@@ -1685,7 +1685,6 @@ public abstract class EntityLiving extends Entity {
|
||||
}
|
||||
|
||||
public void m() {
|
||||
@ -349,7 +349,7 @@ index 2e671fd..b10475f 100644
|
||||
super.m();
|
||||
this.cu();
|
||||
if (!this.world.isClientSide) {
|
||||
@@ -1759,9 +1758,7 @@ public abstract class EntityLiving extends Entity {
|
||||
@@ -1758,9 +1757,7 @@ public abstract class EntityLiving extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
@ -359,7 +359,7 @@ index 2e671fd..b10475f 100644
|
||||
double d0 = this.locX - this.lastX;
|
||||
double d1 = this.locZ - this.lastZ;
|
||||
float f = (float) (d0 * d0 + d1 * d1);
|
||||
@@ -1830,8 +1827,6 @@ public abstract class EntityLiving extends Entity {
|
||||
@@ -1829,8 +1826,6 @@ public abstract class EntityLiving extends Entity {
|
||||
} else {
|
||||
this.bo = 0;
|
||||
}
|
||||
@ -368,7 +368,7 @@ index 2e671fd..b10475f 100644
|
||||
}
|
||||
|
||||
protected float h(float f, float f1) {
|
||||
@@ -1896,7 +1891,6 @@ public abstract class EntityLiving extends Entity {
|
||||
@@ -1895,7 +1890,6 @@ public abstract class EntityLiving extends Entity {
|
||||
}
|
||||
|
||||
this.world.methodProfiler.a("ai");
|
||||
@ -376,7 +376,7 @@ index 2e671fd..b10475f 100644
|
||||
if (this.cf()) {
|
||||
this.bc = false;
|
||||
this.bd = 0.0F;
|
||||
@@ -1907,7 +1901,6 @@ public abstract class EntityLiving extends Entity {
|
||||
@@ -1906,7 +1900,6 @@ public abstract class EntityLiving extends Entity {
|
||||
this.doTick();
|
||||
this.world.methodProfiler.b();
|
||||
}
|
||||
@ -384,7 +384,7 @@ index 2e671fd..b10475f 100644
|
||||
|
||||
this.world.methodProfiler.b();
|
||||
this.world.methodProfiler.a("jump");
|
||||
@@ -1930,14 +1923,10 @@ public abstract class EntityLiving extends Entity {
|
||||
@@ -1929,14 +1922,10 @@ public abstract class EntityLiving extends Entity {
|
||||
this.be *= 0.98F;
|
||||
this.bf *= 0.9F;
|
||||
this.r();
|
||||
|
101
Spigot-Server-Patches/0078-Optimize-Navigation-Listener.patch
Normal file
101
Spigot-Server-Patches/0078-Optimize-Navigation-Listener.patch
Normal file
@ -0,0 +1,101 @@
|
||||
From 24c626d4c99727d3d22ce44cf7357708fbf4bd5b Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Tue, 8 Mar 2016 19:13:54 -0500
|
||||
Subject: [PATCH] Optimize Navigation Listener
|
||||
|
||||
Mojang was abusing a WeakHashMap to do clean up. However this has some
|
||||
scary object life concerns as you could have a NavigationListener being
|
||||
ticked even after the entity it was bound to was removed from world.
|
||||
|
||||
Switching this to an Array List gives superior iteration performance
|
||||
at a slight cost to removal performance.
|
||||
|
||||
Additionally, change listener registration to be done upon world add
|
||||
instead of immediate up creation.
|
||||
|
||||
This provides benefit of only registering and ticking REAL Navigation
|
||||
objects, and not invalid entities (cancelled entity spawns for example)
|
||||
|
||||
Gives us a much leaner NavigationListener list.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/NavigationAbstract.java b/src/main/java/net/minecraft/server/NavigationAbstract.java
|
||||
index 7d794b9..aa18f54 100644
|
||||
--- a/src/main/java/net/minecraft/server/NavigationAbstract.java
|
||||
+++ b/src/main/java/net/minecraft/server/NavigationAbstract.java
|
||||
@@ -32,7 +32,7 @@ public abstract class NavigationAbstract {
|
||||
this.b = world;
|
||||
this.g = entityinsentient.getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
|
||||
this.s = this.a();
|
||||
- this.b.C().a(this);
|
||||
+ //this.b.C().a(this); // Paper - Optimized Nav Listener - registered on world add
|
||||
}
|
||||
|
||||
protected abstract Pathfinder a();
|
||||
diff --git a/src/main/java/net/minecraft/server/NavigationListener.java b/src/main/java/net/minecraft/server/NavigationListener.java
|
||||
index f82ea80..aade479 100644
|
||||
--- a/src/main/java/net/minecraft/server/NavigationListener.java
|
||||
+++ b/src/main/java/net/minecraft/server/NavigationListener.java
|
||||
@@ -1,26 +1,32 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+import java.util.ArrayList; // Paper
|
||||
+import java.util.List; // Paper
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class NavigationListener implements IWorldAccess {
|
||||
|
||||
private static final Object a = new Object();
|
||||
- private final WeakHashMap<NavigationAbstract, Object> b = new WeakHashMap();
|
||||
+ private final List<NavigationAbstract> navigators = new ArrayList<>(); // Paper
|
||||
|
||||
public NavigationListener() {}
|
||||
|
||||
public void a(NavigationAbstract navigationabstract) {
|
||||
- this.b.put(navigationabstract, NavigationListener.a);
|
||||
+ //this.b.put(navigationabstract, NavigationListener.a); // Paper
|
||||
+ System.err.println("Unexpected NavigationListener add"); // Paper
|
||||
}
|
||||
|
||||
public void a(World world, BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1, int i) {
|
||||
if (this.a(world, blockposition, iblockdata, iblockdata1)) {
|
||||
+ /* // Paper start
|
||||
NavigationAbstract[] anavigationabstract = (NavigationAbstract[]) this.b.keySet().toArray(new NavigationAbstract[0]);
|
||||
NavigationAbstract[] anavigationabstract1 = anavigationabstract;
|
||||
int j = anavigationabstract.length;
|
||||
|
||||
- for (int k = 0; k < j; ++k) {
|
||||
- NavigationAbstract navigationabstract = anavigationabstract1[k];
|
||||
+ */
|
||||
+ for (int k = 0; k < this.navigators.size(); ++k) {
|
||||
+ NavigationAbstract navigationabstract = this.navigators.get(k);
|
||||
+ // Paper end
|
||||
|
||||
if (navigationabstract != null && !navigationabstract.i()) {
|
||||
PathEntity pathentity = navigationabstract.k();
|
||||
@@ -55,9 +61,21 @@ public class NavigationListener implements IWorldAccess {
|
||||
|
||||
public void a(int i, boolean flag, double d0, double d1, double d2, double d3, double d4, double d5, int... aint) {}
|
||||
|
||||
- public void a(Entity entity) {}
|
||||
+ public void a(Entity entity) {
|
||||
+ // Paper start
|
||||
+ if (entity instanceof EntityInsentient) {
|
||||
+ this.navigators.add(((EntityInsentient) entity).navigation);
|
||||
+ }
|
||||
+ // Paper end
|
||||
+ }
|
||||
|
||||
- public void b(Entity entity) {}
|
||||
+ public void b(Entity entity) {
|
||||
+ // Paper start
|
||||
+ if (entity instanceof EntityInsentient) {
|
||||
+ this.navigators.remove(((EntityInsentient) entity).navigation);
|
||||
+ }
|
||||
+ // Paper end
|
||||
+ }
|
||||
|
||||
public void a(SoundEffect soundeffect, BlockPosition blockposition) {}
|
||||
|
||||
--
|
||||
2.7.2
|
||||
|
@ -1,48 +0,0 @@
|
||||
From 18aa79ba6e1de6ef27606f71a06aa35768470161 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Mon, 7 Mar 2016 20:41:27 -0500
|
||||
Subject: [PATCH] Optimize NavigationListener
|
||||
|
||||
I believe Mojang intended to call the NavigationListener Block Update
|
||||
method anytime a block is changed, but accidently added it for every
|
||||
block physics event instead.
|
||||
|
||||
This code is massively ineffecient, and physics is so super hot, it
|
||||
destroys server performance.
|
||||
|
||||
This patch moves the block update call to setTypeAndData instead of
|
||||
on Physics.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
||||
index 1db5334..cae2873 100644
|
||||
--- a/src/main/java/net/minecraft/server/World.java
|
||||
+++ b/src/main/java/net/minecraft/server/World.java
|
||||
@@ -89,7 +89,7 @@ public abstract class World implements IBlockAccess {
|
||||
private int K;
|
||||
public final Random random = new Random();
|
||||
public WorldProvider worldProvider;
|
||||
- protected NavigationListener t = new NavigationListener();
|
||||
+ protected NavigationListener t = new NavigationListener(); public NavigationListener getNavListener() { return this.t; } // Paper
|
||||
protected List<IWorldAccess> u;
|
||||
protected IChunkProvider chunkProvider;
|
||||
protected final IDataManager dataManager;
|
||||
@@ -168,7 +168,7 @@ public abstract class World implements IBlockAccess {
|
||||
this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit
|
||||
this.ticksPerMonsterSpawns = this.getServer().getTicksPerMonsterSpawns(); // CraftBukkit
|
||||
// CraftBukkit end
|
||||
- this.u = Lists.newArrayList(new IWorldAccess[] { this.t});
|
||||
+ this.u = Lists.newArrayList(new IWorldAccess[] {}); // Paper
|
||||
this.L = Calendar.getInstance();
|
||||
this.scoreboard = new Scoreboard();
|
||||
this.allowMonsters = true;
|
||||
@@ -412,6 +412,7 @@ public abstract class World implements IBlockAccess {
|
||||
if (!this.captureBlockStates) { // Don't notify clients or update physics while capturing blockstates
|
||||
// Modularize client and physic updates
|
||||
notifyAndUpdatePhysics(blockposition, chunk, iblockdata1, iblockdata, i);
|
||||
+ this.getNavListener().a(this, blockposition, iblockdata1, iblockdata, i); // Paper
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
--
|
||||
2.7.2
|
||||
|
@ -1,100 +0,0 @@
|
||||
From 9c96f51c8068de370baeb9fa4aee91c82d273e42 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Mon, 7 Mar 2016 22:43:26 -0500
|
||||
Subject: [PATCH] Optimize NavigationListener Iteration
|
||||
|
||||
I don't know what the person who wrote that code was smoking, but I
|
||||
don't think it was good.
|
||||
|
||||
Gets rid of the WeakHashMap that mojang was abusing purely to be lazy
|
||||
on clean up, and handles registering and deregistering navigation
|
||||
upon world add/remove operations.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/NavigationAbstract.java b/src/main/java/net/minecraft/server/NavigationAbstract.java
|
||||
index 7d794b9..ca4cb26 100644
|
||||
--- a/src/main/java/net/minecraft/server/NavigationAbstract.java
|
||||
+++ b/src/main/java/net/minecraft/server/NavigationAbstract.java
|
||||
@@ -32,7 +32,7 @@ public abstract class NavigationAbstract {
|
||||
this.b = world;
|
||||
this.g = entityinsentient.getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
|
||||
this.s = this.a();
|
||||
- this.b.C().a(this);
|
||||
+ //this.b.C().a(this); // Paper
|
||||
}
|
||||
|
||||
protected abstract Pathfinder a();
|
||||
diff --git a/src/main/java/net/minecraft/server/NavigationListener.java b/src/main/java/net/minecraft/server/NavigationListener.java
|
||||
index f82ea80..ef446fc 100644
|
||||
--- a/src/main/java/net/minecraft/server/NavigationListener.java
|
||||
+++ b/src/main/java/net/minecraft/server/NavigationListener.java
|
||||
@@ -1,26 +1,41 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+import java.util.ArrayList; // Paper
|
||||
+import java.util.List; // Paper
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class NavigationListener implements IWorldAccess {
|
||||
|
||||
private static final Object a = new Object();
|
||||
- private final WeakHashMap<NavigationAbstract, Object> b = new WeakHashMap();
|
||||
+ private final List<NavigationAbstract> navigators = new ArrayList<>(); // Paper
|
||||
|
||||
public NavigationListener() {}
|
||||
|
||||
+
|
||||
public void a(NavigationAbstract navigationabstract) {
|
||||
- this.b.put(navigationabstract, NavigationListener.a);
|
||||
+ this.add(navigationabstract); // Paper
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ public void add(NavigationAbstract navigationabstract) {
|
||||
+ this.navigators.add(navigationabstract);
|
||||
+ }
|
||||
+ public void remove(NavigationAbstract navigationabstract) {
|
||||
+ this.navigators.remove(navigationabstract);
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
public void a(World world, BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1, int i) {
|
||||
if (this.a(world, blockposition, iblockdata, iblockdata1)) {
|
||||
- NavigationAbstract[] anavigationabstract = (NavigationAbstract[]) this.b.keySet().toArray(new NavigationAbstract[0]);
|
||||
- NavigationAbstract[] anavigationabstract1 = anavigationabstract;
|
||||
- int j = anavigationabstract.length;
|
||||
+ // Paper start
|
||||
+ //NavigationAbstract[] anavigationabstract = (NavigationAbstract[]) this.navigators.keySet().toArray(new NavigationAbstract[0]);
|
||||
+ //NavigationAbstract[] anavigationabstract1 = anavigationabstract;
|
||||
+ int j = this.navigators.size();
|
||||
+
|
||||
|
||||
for (int k = 0; k < j; ++k) {
|
||||
- NavigationAbstract navigationabstract = anavigationabstract1[k];
|
||||
+ NavigationAbstract navigationabstract = this.navigators.get(k);
|
||||
+ // Paper end
|
||||
|
||||
if (navigationabstract != null && !navigationabstract.i()) {
|
||||
PathEntity pathentity = navigationabstract.k();
|
||||
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
||||
index cae2873..5ae2f14 100644
|
||||
--- a/src/main/java/net/minecraft/server/World.java
|
||||
+++ b/src/main/java/net/minecraft/server/World.java
|
||||
@@ -1024,6 +1024,7 @@ public abstract class World implements IBlockAccess {
|
||||
this.getChunkAt(i, j).a(entity);
|
||||
this.entityList.add(entity);
|
||||
this.b(entity);
|
||||
+ if (entity instanceof EntityInsentient) { this.getNavListener().add(((EntityInsentient) entity).navigation); } // Paper
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1105,6 +1106,7 @@ public abstract class World implements IBlockAccess {
|
||||
}
|
||||
// CraftBukkit end
|
||||
} // Spigot
|
||||
+ if (entity instanceof EntityInsentient) { this.getNavListener().remove(((EntityInsentient) entity).navigation); } // Paper
|
||||
this.c(entity);
|
||||
}
|
||||
|
||||
--
|
||||
2.7.2
|
||||
|
Loading…
Reference in New Issue
Block a user