Paper/patches/server/0871-Don-t-use-level-random-in-entity-constructors.patch
Jake Potrebic 9147456fc9
Updated Upstream (CraftBukkit/Spigot) (#8815)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

CraftBukkit Changes:
ab8ace685 SPIGOT-7236: Bone meal doesn't increase use statistic
7dcb59b8e Avoid switch on material in previous commit

Spigot Changes:
19641c75 SPIGOT-7235: World.Spigot#strikeLightningEffect doesn't do anything
2023-01-27 12:52:04 -08:00

64 lines
3.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 10 Jul 2022 14:13:22 -0700
Subject: [PATCH] Don't use level random in entity constructors
Paper makes the entity random thread-safe
and constructing an entity off the main thread
should be supported. Some entities (for whatever
reason) use the level's random in some places.
diff --git a/src/main/java/net/minecraft/world/entity/animal/Bee.java b/src/main/java/net/minecraft/world/entity/animal/Bee.java
index a3aeab5fa137f80a229db2edba07d9900f7becfe..337a88a7cd6445004d005ef8d56af1b1cdf800d9 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Bee.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Bee.java
@@ -1031,7 +1031,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
BeeGoToHiveGoal() {
super();
- this.travellingTicks = Bee.this.level.random.nextInt(10);
+ this.travellingTicks = Bee.this./* level. */random.nextInt(10); // Paper - use entity random
this.blacklistedTargets = Lists.newArrayList();
this.setFlags(EnumSet.of(Goal.Flag.MOVE));
}
@@ -1148,7 +1148,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
BeeGoToKnownFlowerGoal() {
super();
- this.travellingTicks = Bee.this.level.random.nextInt(10);
+ this.travellingTicks = Bee.this./* level. */random.nextInt(10); // Paper - use entity random
this.setFlags(EnumSet.of(Goal.Flag.MOVE));
}
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
index 62f2a070e4c80846a9d696445212c65289037928..d9da6728d60e97eb9032b0a5aa71757d11f36e22 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -62,7 +62,12 @@ public class ItemEntity extends Entity {
}
public ItemEntity(Level world, double x, double y, double z, ItemStack stack) {
- this(world, x, y, z, stack, world.random.nextDouble() * 0.2D - 0.1D, 0.2D, world.random.nextDouble() * 0.2D - 0.1D);
+ // Paper start - don't use world random in entity constructor
+ this(EntityType.ITEM, world);
+ this.setPos(x, y, z);
+ this.setDeltaMovement(this.random.nextDouble() * 0.2D - 0.1D, 0.2D, this.random.nextDouble() * 0.2D - 0.1D);
+ this.setItem(stack);
+ // Paper end
}
public ItemEntity(Level world, double x, double y, double z, ItemStack stack, double velocityX, double velocityY, double velocityZ) {
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
index 4b81d62d3250b99cbcb4eb2468ef81c149bf177e..bedee2c93bd0aff148f93dcf111e0fc3d9bce4a0 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -32,7 +32,7 @@ public class PrimedTnt extends Entity {
public PrimedTnt(Level world, double x, double y, double z, @Nullable LivingEntity igniter) {
this(EntityType.TNT, world);
this.setPos(x, y, z);
- double d3 = world.random.nextDouble() * 6.2831854820251465D;
+ double d3 = this.random.nextDouble() * 6.2831854820251465D; // Paper - don't use world random in entity constructor
this.setDeltaMovement(-Math.sin(d3) * 0.02D, 0.20000000298023224D, -Math.cos(d3) * 0.02D);
this.setFuse(80);