Skip to content

Commit

Permalink
[ci skip] Add more identifying patch comments, merge related patches
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Jan 19, 2024
1 parent 106c67a commit cc693ce
Show file tree
Hide file tree
Showing 396 changed files with 383 additions and 431 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ type and we are not using its capabilities.
Set thread priorities so main thread has above normal priority over
server threads

Allow usage of a single thread executor by not using ForkJoin so single core CPU's.
Allow usage of a single thread executor by not using ForkJoin so single core CPU's
and reduce worldgen thread worker count for low core count CPUs.

== AT ==
public net.minecraft.Util onThreadException(Ljava/lang/Thread;Ljava/lang/Throwable;)V

Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>

diff --git a/src/main/java/io/papermc/paper/util/ServerWorkerThread.java b/src/main/java/io/papermc/paper/util/ServerWorkerThread.java
new file mode 100644
index 0000000000000000000000000000000000000000..b60f59cf5cc8eb84a6055b7861857dece7f2501b
Expand All @@ -35,7 +38,7 @@ index 0000000000000000000000000000000000000000..b60f59cf5cc8eb84a6055b7861857dec
+ }
+}
diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java
index aa52b271bd556a29f774fde375b713d0d187521b..8188febd6f1039a31619b42af23df18afd2e985c 100644
index aa52b271bd556a29f774fde375b713d0d187521b..90f5e7d36719dc9b464dd6ba0335da035bab29d3 100644
--- a/src/main/java/net/minecraft/Util.java
+++ b/src/main/java/net/minecraft/Util.java
@@ -86,7 +86,7 @@ public class Util {
Expand All @@ -47,18 +50,27 @@ index aa52b271bd556a29f774fde375b713d0d187521b..8188febd6f1039a31619b42af23df18a
private static final ExecutorService IO_POOL = makeIoExecutor("IO-Worker-", false);
private static final ExecutorService DOWNLOAD_POOL = makeIoExecutor("Download-", true);
// Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
@@ -152,15 +152,18 @@ public class Util {
@@ -152,15 +152,27 @@ public class Util {
return FILENAME_DATE_TIME_FORMATTER.format(ZonedDateTime.now());
}

- private static ExecutorService makeExecutor(String name) {
- int i = Mth.clamp(Runtime.getRuntime().availableProcessors() - 1, 1, getMaxThreads());
+ private static ExecutorService makeExecutor(String s, int priorityModifier) { // Paper - add priority
+ // Paper start - use simpler thread pool that allows 1 thread
+ int i = Math.min(8, Math.max(Runtime.getRuntime().availableProcessors() - 2, 1));
+ // Paper start - use simpler thread pool that allows 1 thread and reduce worldgen thread worker count for low core count CPUs
+ int cpus = Runtime.getRuntime().availableProcessors() / 2;
+ int i;
+ if (cpus <= 4) {
+ i = cpus <= 2 ? 1 : 2;
+ } else if (cpus <= 8) {
+ // [5, 8]
+ i = Math.max(3, cpus - 2);
+ } else {
+ i = cpus * 2 / 3;
+ }
+ i = Math.min(8, i);
+ i = Integer.getInteger("Paper.WorkerThreadCount", i);
ExecutorService executorService;
+
if (i <= 0) {
executorService = MoreExecutors.newDirectExecutorService();
} else {
Expand All @@ -71,7 +83,7 @@ index aa52b271bd556a29f774fde375b713d0d187521b..8188febd6f1039a31619b42af23df18a
@Override
protected void onTermination(Throwable throwable) {
if (throwable != null) {
@@ -176,6 +179,7 @@ public class Util {
@@ -176,6 +188,7 @@ public class Util {
return forkJoinWorkerThread;
}, Util::onThreadException, true);
}
Expand All @@ -80,7 +92,7 @@ index aa52b271bd556a29f774fde375b713d0d187521b..8188febd6f1039a31619b42af23df18a
return executorService;
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 06d9cafeeedb3020c5e2313d32c6fe9285f99925..eac560bf8af3c7c28ed5eed61ef352f52d823cef 100644
index 79a7f64edcfc750bf2753b5b20e4c2ae322e01ab..7a12c0f5a6cb205e8ae7667b9334efe1999e2a6a 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -312,6 +312,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 10 May 2020 22:12:46 -0400
Subject: [PATCH] Ensure Entity AABB's are never invalid
Subject: [PATCH] Ensure Entity position and AABB are never invalid

Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index a1d990aa2e79af9e1ff078892cdb38a382f21da7..a1172531baf637915a65fbdee8ca08f08034811d 100644
index a1d990aa2e79af9e1ff078892cdb38a382f21da7..e1ce61dcadf325633ed809eef92fc07bac4cbf05 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -728,8 +728,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
Expand All @@ -14,33 +15,51 @@ index a1d990aa2e79af9e1ff078892cdb38a382f21da7..a1172531baf637915a65fbdee8ca08f0
public void setPos(double x, double y, double z) {
- this.setPosRaw(x, y, z);
- this.setBoundingBox(this.makeBoundingBox());
+ this.setPosRaw(x, y, z, true); // Paper - force bounding box update
+ // this.setBoundingBox(this.makeBoundingBox()); // Paper - move into setPositionRaw
+ this.setPosRaw(x, y, z, true); // Paper - Block invalid positions and bounding box; force update
+ // this.setBoundingBox(this.makeBoundingBox()); // Paper - Block invalid positions and bounding box; move into setPosRaw
}

protected AABB makeBoundingBox() {
@@ -4244,6 +4244,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -4243,7 +4243,29 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
return this.getZ((2.0D * this.random.nextDouble() - 1.0D) * widthScale);
}

+ // Paper start - Block invalid positions and bounding box
+ public static boolean checkPosition(Entity entity, double newX, double newY, double newZ) {
+ if (Double.isFinite(newX) && Double.isFinite(newY) && Double.isFinite(newZ)) {
+ return true;
+ }
+
+ String entityInfo;
+ try {
+ entityInfo = entity.toString();
+ } catch (Exception ex) {
+ entityInfo = "[Entity info unavailable] ";
+ }
+ LOGGER.error("New entity position is invalid! Tried to set invalid position ({},{},{}) for entity {} located at {}, entity info: {}", newX, newY, newZ, entity.getClass().getName(), entity.position, entityInfo, new Throwable());
+ return false;
+ }
public final void setPosRaw(double x, double y, double z) {
+ // Paper start
+ this.setPosRaw(x, y, z, false);
+ }
+ public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
+ // Paper end
+ if (!checkPosition(this, x, y, z)) {
+ return;
+ }
+ // Paper end - Block invalid positions and bounding box
// Paper start - rewrite chunk system
if (this.updatingSectionStatus) {
LOGGER.error("Refusing to update position for entity " + this + " to position " + new Vec3(x, y, z) + " since it is processing a section status update", new Throwable());
@@ -4267,6 +4272,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -4267,6 +4289,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
this.levelCallback.onMove();
}

+ // Paper start - never allow AABB to become desynced from position
+ // Paper start - Block invalid positions and bounding box; don't allow desync of pos and AABB
+ // hanging has its own special logic
+ if (!(this instanceof net.minecraft.world.entity.decoration.HangingEntity) && (forceBoundingBoxUpdate || this.position.x != x || this.position.y != y || this.position.z != z)) {
+ this.setBoundingBox(this.makeBoundingBox());
+ }
+ // Paper end
+ // Paper end - Block invalid positions and bounding box
}

public void checkDespawn() {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Expose the Entity Counter to allow plugins to use valid and


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index ec224193e9ca7734fe533d5cfc0e316d5eed2adb..03eee2a591a533ec9930a262ffd4af2023a07c91 100644
index 1f245a40358309f2e71f473af6df8e71739e8082..2b8706dfccd263c2843dd8661a260536134ad3f8 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4493,4 +4493,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -4510,4 +4510,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S

void accept(Entity entity, double x, double y, double z);
}
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0457-Entity-isTicking.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Entity#isTicking


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 03eee2a591a533ec9930a262ffd4af2023a07c91..4a1245fb3ad821ee997b35f180390a07bc871982 100644
index 2b8706dfccd263c2843dd8661a260536134ad3f8..cdfc00e4bee78fc7ac7dc9f52301f16cd7846698 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4498,5 +4498,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -4515,5 +4515,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
public static int nextEntityId() {
return ENTITY_COUNTER.incrementAndGet();
}
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0497-MC-4-Fix-item-position-desync.patch
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ index 05ac41e136da43284fb24a6b698ebd36318278fb..33d9131e9c75ef23cd637f5d6c39a270

public Vec3 decode(long x, long y, long z) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 82eb980dd463c423b2b30a3149166a227608bb96..5436949cd928303cf80b606c747f386f0189f774 100644
index 02b102b2d3e8e8ca9d0c95d3a44a56a88bee3b18..3a8572ded5c9bdf621a8c16123707da9ceb70d54 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4269,6 +4269,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -4286,6 +4286,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
return;
}
// Paper end - rewrite chunk system
Expand Down
8 changes: 4 additions & 4 deletions patches/server/0644-Add-back-EntityPortalExitEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Add back EntityPortalExitEvent


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index c598247bd8cf65f33845502107277518f7260d4d..8db434d01f2771a94cd4c4a662ea0482b2a02307 100644
index c598247bd8cf65f33845502107277518f7260d4d..80df6afacee92b205949322c9ccfba6f37af0279 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3373,6 +3373,28 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
Expand Down Expand Up @@ -33,7 +33,7 @@ index c598247bd8cf65f33845502107277518f7260d4d..8db434d01f2771a94cd4c4a662ea0482
+ pitch = event.getTo().getPitch();
+ velocity = org.bukkit.craftbukkit.util.CraftVector.toNMS(event.getAfter());
+ }
+ // Paper end
+ // Paper end - Call EntityPortalExitEvent
if (worldserver == this.level) {
// SPIGOT-6782: Just move the entity if a plugin changed the world to the one the entity is already in
this.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, shapedetectorshape.xRot);
Expand All @@ -43,8 +43,8 @@ index c598247bd8cf65f33845502107277518f7260d4d..8db434d01f2771a94cd4c4a662ea0482
entity.restoreFrom(this);
- entity.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, entity.getXRot());
- entity.setDeltaMovement(shapedetectorshape.speed);
+ entity.moveTo(position.x, position.y, position.z, yaw, pitch); // Paper - use EntityPortalExitEvent values
+ entity.setDeltaMovement(velocity); // Paper - use EntityPortalExitEvent values
+ entity.moveTo(position.x, position.y, position.z, yaw, pitch); // Paper - EntityPortalExitEvent
+ entity.setDeltaMovement(velocity); // Paper - EntityPortalExitEvent
// CraftBukkit start - Don't spawn the new entity if the current entity isn't spawned
if (this.inWorld) {
worldserver.addDuringTeleport(entity);
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ Subject: [PATCH] Add methods to find targets for lightning strikes
public net.minecraft.server.level.ServerLevel findLightningRod(Lnet/minecraft/core/BlockPos;)Ljava/util/Optional;

diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index dbfd4a642e862f46a8b4fd1f3fc52c13ecf74284..1629a94a272f34d395b6be8f16944b9a8837d195 100644
index dbfd4a642e862f46a8b4fd1f3fc52c13ecf74284..1e67fd45b4449b46992cb0617db22e74ce517b4d 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -998,6 +998,11 @@ public class ServerLevel extends Level implements WorldGenLevel {
}

protected BlockPos findLightningTargetAround(BlockPos pos) {
+ // Paper start
+ // Paper start - Add methods to find targets for lightning strikes
+ return this.findLightningTargetAround(pos, false);
+ }
+ public BlockPos findLightningTargetAround(BlockPos pos, boolean returnNullWhenNoTarget) {
+ // Paper end
+ // Paper end - Add methods to find targets for lightning strikes
BlockPos blockposition1 = this.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos);
Optional<BlockPos> optional = this.findLightningRod(blockposition1);

@@ -1012,6 +1017,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
if (!list.isEmpty()) {
return ((LivingEntity) list.get(this.random.nextInt(list.size()))).blockPosition();
} else {
+ if (returnNullWhenNoTarget) return null; // Paper
+ if (returnNullWhenNoTarget) return null; // Paper - Add methods to find targets for lightning strikes
if (blockposition1.getY() == this.getMinBuildHeight() - 1) {
blockposition1 = blockposition1.above(2);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index a920936018a2e05ea72d68a83e6debb3807df353..095fa9e4c4d367a3cdd343ca71bef7a6564759be 100644
index a920936018a2e05ea72d68a83e6debb3807df353..59ca5a224561f59bf1f44e11db9bc323ac2f6d71 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -701,6 +701,23 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return (LightningStrike) lightning.getBukkitEntity();
}

+ // Paper start
+ // Paper start - Add methods to find targets for lightning strikes
+ @Override
+ public Location findLightningRod(Location location) {
+ return this.world.findLightningRod(io.papermc.paper.util.MCUtil.toBlockPosition(location))
Expand All @@ -53,7 +53,7 @@ index a920936018a2e05ea72d68a83e6debb3807df353..095fa9e4c4d367a3cdd343ca71bef7a6
+ final BlockPos pos = this.world.findLightningTargetAround(io.papermc.paper.util.MCUtil.toBlockPosition(location), true);
+ return pos == null ? null : io.papermc.paper.util.MCUtil.toLocation(this.world, pos);
+ }
+ // Paper end
+ // Paper end - Add methods to find targets for lightning strikes
+
@Override
public boolean generateTree(Location loc, TreeType type) {
Expand Down
10 changes: 5 additions & 5 deletions patches/server/0648-Add-more-advancement-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ index 0000000000000000000000000000000000000000..adac21ce6db3ff7a56dbcd6bffc02143
+ }
+}
diff --git a/src/main/java/net/minecraft/advancements/DisplayInfo.java b/src/main/java/net/minecraft/advancements/DisplayInfo.java
index d357deb8a9e1d4043f5fb3302b957b20ffc0cc32..d83acd5eac3d7d1893b1b97ab0b0764c06da016b 100644
index d357deb8a9e1d4043f5fb3302b957b20ffc0cc32..54298a80bd86ae8c2bdbfc69d381173aea2f1410 100644
--- a/src/main/java/net/minecraft/advancements/DisplayInfo.java
+++ b/src/main/java/net/minecraft/advancements/DisplayInfo.java
@@ -24,6 +24,7 @@ public class DisplayInfo {
private final boolean hidden;
private float x;
private float y;
+ public final io.papermc.paper.advancement.AdvancementDisplay paper = new io.papermc.paper.advancement.PaperAdvancementDisplay(this); // Paper
+ public final io.papermc.paper.advancement.AdvancementDisplay paper = new io.papermc.paper.advancement.PaperAdvancementDisplay(this); // Paper - Add more advancement API

public DisplayInfo(ItemStack icon, Component title, Component description, Optional<ResourceLocation> background, AdvancementType frame, boolean showToast, boolean announceToChat, boolean hidden) {
this.title = title;
diff --git a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
index 52baf818579a6841b77ff80e42f4f1b9f635ea08..bd640e0d8d796ee114ff787def7e07edbeffc0a5 100644
index 52baf818579a6841b77ff80e42f4f1b9f635ea08..8dfaca2efa0b0bdc97b75aaa83158a2e46361e4e 100644
--- a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
+++ b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
@@ -29,12 +29,47 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement {
return Collections.unmodifiableCollection(this.handle.value().criteria().keySet());
}

+ // Paper start
+ // Paper start - Add more advancement API
@Override
- public AdvancementDisplay getDisplay() {
- if (this.handle.value().display().isEmpty()) {
Expand Down Expand Up @@ -149,7 +149,7 @@ index 52baf818579a6841b77ff80e42f4f1b9f635ea08..bd640e0d8d796ee114ff787def7e07ed
+ final net.minecraft.advancements.AdvancementNode advancementNode = net.minecraft.server.MinecraftServer.getServer().getAdvancements().tree().get(this.handle);
+ return java.util.Objects.requireNonNull(advancementNode, "could not find internal advancement node for advancement " + this.handle.id()).root().holder().toBukkit();
}
+ // Paper end
+ // Paper end - Add more advancement API
}
diff --git a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancementDisplay.java b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancementDisplay.java
index 8ca86852319d7463f60832bc98b825b0b4325995..62ada73302c6b3ce3fb2dcc8c31a1d9c0ac4fd09 100644
Expand Down
Loading

0 comments on commit cc693ce

Please sign in to comment.