summaryrefslogtreecommitdiffhomepage
path: root/patches/unapplied/server/0865-Don-t-use-level-random-in-entity-constructors.patch
blob: 342c4ce11a2b8395500f28b1116594a40a4890a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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 a7ccbe4d32e9ea481447b6813efb8a56a529b6bd..c33e5c51839c8e6ec04c1b302127d2bf0f48664c 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Bee.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Bee.java
@@ -1026,7 +1026,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));
         }
@@ -1143,7 +1143,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 8a757e6682fb7a58bfd76290bd79ee3cc3dc27b9..2be70d950be48014c4e9792adfc1d05da5aa6a59 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -63,7 +63,12 @@ public class ItemEntity extends Entity implements TraceableEntity {
     }
 
     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 94e3ce40da0401a94a24a6c0f9e7ffa3d0ef850d..dfdf7e7fc1070975ec18fd215c724f4fc84d3705 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -33,7 +33,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
     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);