9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2026-01-06 15:51:33 +00:00
Files
LeavesMC/leaves-server/minecraft-patches/features/0037-Configurable-vanilla-random.patch
2025-11-28 00:17:52 +08:00

87 lines
5.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Thu, 16 Feb 2023 17:25:01 +0800
Subject: [PATCH] Configurable vanilla random
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index c6815ffef7fb2fd2e5ef2769c2c93135b52558f5..f6dd8e81f6881400c3278ea53e2ed248625744e1 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -282,7 +282,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
public double yOld;
public double zOld;
public boolean noPhysics;
- public final RandomSource random = SHARED_RANDOM; // Paper - Share random for entities to make them more random
+ public final RandomSource random = org.leavesmc.leaves.LeavesConfig.modify.useVanillaRandom ? RandomSource.create() : SHARED_RANDOM; // Paper - Share random for entities to make them more random // Leaves - but mojang use it, optimize? no!
public int tickCount;
private int remainingFireTicks;
public boolean wasTouchingWater;
diff --git a/net/minecraft/world/entity/animal/Bee.java b/net/minecraft/world/entity/animal/Bee.java
index e94c6c1ee969a7d0953b933fb0633cebb510a68c..97fbdb90db218c6f2f81487cc30430d7c90afa8e 100644
--- a/net/minecraft/world/entity/animal/Bee.java
+++ b/net/minecraft/world/entity/animal/Bee.java
@@ -808,7 +808,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
@VisibleForDebug
public class BeeGoToHiveGoal extends Bee.BaseBeeGoal {
public static final int MAX_TRAVELLING_TICKS = 2400;
- int travellingTicks;
+ int travellingTicks; // TODO: int travellingTicks = org.leavesmc.leaves.LeavesConfig.modify.useVanillaRandom ? Bee.this.level().random.nextInt(10) : Bee.this.random.nextInt(10); // CraftBukkit - SPIGOT-7495: Give Bees another chance and let them use their own random, avoid concurrency issues // Leaves - why no vanilla
private static final int MAX_BLACKLISTED_TARGETS = 3;
final List<BlockPos> blacklistedTargets = Lists.newArrayList();
@Nullable
@@ -924,7 +924,7 @@ public class Bee extends Animal implements NeutralMob, FlyingAnimal {
public class BeeGoToKnownFlowerGoal extends Bee.BaseBeeGoal {
private static final int MAX_TRAVELLING_TICKS = 2400;
- int travellingTicks;
+ int travellingTicks; // TODO: int travellingTicks = org.leavesmc.leaves.LeavesConfig.modify.useVanillaRandom ? Bee.this.level().random.nextInt(10) : Bee.this.random.nextInt(10); // CraftBukkit - SPIGOT-7495: Give Bees another chance and let them use their own random, avoid concurrency issues // Leaves - why no vanilla
BeeGoToKnownFlowerGoal() {
this.setFlags(EnumSet.of(Goal.Flag.MOVE));
diff --git a/net/minecraft/world/entity/animal/Squid.java b/net/minecraft/world/entity/animal/Squid.java
index 8313ea146ba6910d92653c29887c94b75f68cce4..9b8775a9069db99605ac5367804923d537320d68 100644
--- a/net/minecraft/world/entity/animal/Squid.java
+++ b/net/minecraft/world/entity/animal/Squid.java
@@ -47,7 +47,7 @@ public class Squid extends AgeableWaterCreature {
public Squid(EntityType<? extends Squid> type, Level level) {
super(type, level);
- // this.random.setSeed(this.getId()); // Paper - Share random for entities to make them more random
+ if (org.leavesmc.leaves.LeavesConfig.modify.useVanillaRandom) this.random.setSeed(this.getId()); // Paper - Share random for entities to make them more random // Leaves - vanilla plz
this.tentacleSpeed = 1.0F / (this.random.nextFloat() + 1.0F) * 0.2F;
}
diff --git a/net/minecraft/world/entity/item/ItemEntity.java b/net/minecraft/world/entity/item/ItemEntity.java
index e198e4c1ee267c6738117959e71cf4018bf6ef1d..671ae6195c86b44dfb2df4414a35287e3acd954f 100644
--- a/net/minecraft/world/entity/item/ItemEntity.java
+++ b/net/minecraft/world/entity/item/ItemEntity.java
@@ -66,7 +66,13 @@ public class ItemEntity extends Entity implements TraceableEntity {
// Paper start - Don't use level random in entity constructors (to make them thread-safe)
this(EntityType.ITEM, level);
this.setPos(posX, posY, posZ);
- this.setDeltaMovement(this.random.nextDouble() * 0.2 - 0.1, 0.2, this.random.nextDouble() * 0.2 - 0.1);
+ // Leaves start - vanilla yes, safe no
+ if (org.leavesmc.leaves.LeavesConfig.modify.useVanillaRandom) {
+ this.setDeltaMovement(level.random.nextDouble() * 0.2 - 0.1, 0.2, level.random.nextDouble() * 0.2 - 0.1);
+ } else {
+ this.setDeltaMovement(this.random.nextDouble() * 0.2 - 0.1, 0.2, this.random.nextDouble() * 0.2 - 0.1);
+ }
+ // Leaves end - vanilla yes, safe no
this.setItem(stack);
// Paper end - Don't use level random in entity constructors
}
diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java
index d36ce16724e9f5a79960f0aa265a0354f5240abc..8230b42919bd8888acf656c5846601bead39598f 100644
--- a/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
@@ -68,7 +68,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
public PrimedTnt(Level level, double x, double y, double z, @Nullable LivingEntity owner) {
this(EntityType.TNT, level);
this.setPos(x, y, z);
- double d = this.random.nextDouble() * (float) (Math.PI * 2); // Paper - Don't use level random in entity constructors
+ double d = (org.leavesmc.leaves.LeavesConfig.modify.useVanillaRandom ? level.random.nextDouble() : this.random.nextDouble()) * (float) (Math.PI * 2); // Paper - Don't use level random in entity constructors // Leaves - why?
this.setDeltaMovement(-Math.sin(d) * 0.02, 0.2F, -Math.cos(d) * 0.02);
this.setFuse(80);
this.xo = x;