From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic 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 e06d5eea4bc81be264a1f5d5fad2d4548c4ae8d2..55026e1731e41b4e3e4c6a8fef5d96a32051a556 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Bee.java +++ b/src/main/java/net/minecraft/world/entity/animal/Bee.java @@ -1029,7 +1029,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)); } @@ -1146,7 +1146,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 b76270c37b568b69af99a2a99dbab3f2f1b57d22..08a2ce0ab024b99df5f6e23aa5a13c9d6f431db6 100644 --- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java @@ -64,7 +64,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 57f9bf73ee14bc8811d0192543caf2b02e890ee0..4ce3e69970dd9eb251d0538a2d233ca30e9e5e47 100644 --- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java +++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java @@ -36,7 +36,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);