mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Add toggle for RNG manipulation
Paper patches RNG maniplulation by using a shared (and locked) random source. This comes with a performance gain, but technical players may prefer the ability to manipulate RNG.
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Encode42 <me@encode42.dev>
|
||||
Date: Tue, 12 Jul 2022 14:16:10 -0400
|
||||
Subject: [PATCH] Add toggle for RNG manipulation
|
||||
|
||||
Paper patches RNG maniplulation by using a shared (and locked) random source.
|
||||
This comes with a performance gain, but technical players may prefer the ability to manipulate RNG.
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 25a6f228bad7deca7e7301868039d27bf65505c8..35cd273eb885558003a728eedc63f958e5accf74 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -599,7 +599,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
this.bb = Entity.INITIAL_AABB;
|
||||
this.stuckSpeedMultiplier = Vec3.ZERO;
|
||||
this.nextStep = 1.0F;
|
||||
- this.random = SHARED_RANDOM; // Paper - Share random for entities to make them more random
|
||||
+ this.random = world == null || world.purpurConfig.entitySharedRandom ? SHARED_RANDOM : RandomSource.create(); // Paper - Share random for entities to make them more random // Purpur
|
||||
this.remainingFireTicks = -this.getFireImmuneTicks();
|
||||
this.fluidHeight = new Object2DoubleArrayMap(2);
|
||||
this.fluidOnEyes = new HashSet();
|
||||
diff --git a/net/minecraft/world/entity/animal/Squid.java b/net/minecraft/world/entity/animal/Squid.java
|
||||
index a2f51788f88c20f282ea2a20485c56109b90c22b..c7a7d1df79beb527ff94f876ca36a861c37c4947 100644
|
||||
--- a/net/minecraft/world/entity/animal/Squid.java
|
||||
+++ b/net/minecraft/world/entity/animal/Squid.java
|
||||
@@ -46,7 +46,7 @@ public class Squid extends AgeableWaterCreature {
|
||||
|
||||
public Squid(EntityType<? extends Squid> type, Level world) {
|
||||
super(type, world);
|
||||
- //this.random.setSeed((long)this.getId()); // Paper - Share random for entities to make them more random
|
||||
+ if (!world.purpurConfig.entitySharedRandom) this.random.setSeed((long)this.getId()); // Paper - Share random for entities to make them more random // Purpur
|
||||
this.tentacleSpeed = 1.0F / (this.random.nextFloat() + 1.0F) * 0.2F;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
index d80584a0412b6699c24f5817e8ec26cf9f46d92d..596a4d0a7c6851c31ee2c09cfc11400683336e6d 100644
|
||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
||||
@@ -211,9 +211,11 @@ public class PurpurWorldConfig {
|
||||
|
||||
public int entityLifeSpan = 0;
|
||||
public float entityLeftHandedChance = 0.05f;
|
||||
+ public boolean entitySharedRandom = true;
|
||||
private void entitySettings() {
|
||||
entityLifeSpan = getInt("gameplay-mechanics.entity-lifespan", entityLifeSpan);
|
||||
entityLeftHandedChance = (float) getDouble("gameplay-mechanics.entity-left-handed-chance", entityLeftHandedChance);
|
||||
+ entitySharedRandom = getBoolean("settings.entity.shared-random", entitySharedRandom);
|
||||
}
|
||||
|
||||
public boolean infinityWorksWithoutArrows = false;
|
||||
@@ -9,15 +9,28 @@
|
||||
// CraftBukkit start
|
||||
private static final int CURRENT_LEVEL = 2;
|
||||
public boolean preserveMotion = true; // Paper - Fix Entity Teleportation and cancel velocity if teleported; keep initial motion on first setPositionRotation
|
||||
@@ -253,6 +_,7 @@
|
||||
@@ -253,9 +_,10 @@
|
||||
public double xOld;
|
||||
public double yOld;
|
||||
public double zOld;
|
||||
+ public float maxUpStep; // Purpur - Add option to set armorstand step height
|
||||
public boolean noPhysics;
|
||||
private boolean wasOnFire;
|
||||
public final RandomSource random = SHARED_RANDOM; // Paper - Share random for entities to make them more random
|
||||
@@ -526,6 +_,12 @@
|
||||
- public final RandomSource random = SHARED_RANDOM; // Paper - Share random for entities to make them more random
|
||||
+ public final RandomSource random; // Paper - Share random for entities to make them more random // Add toggle for RNG manipulation
|
||||
public int tickCount;
|
||||
private int remainingFireTicks = -this.getFireImmuneTicks();
|
||||
public boolean wasTouchingWater;
|
||||
@@ -289,7 +_,7 @@
|
||||
public PortalProcessor portalProcess;
|
||||
public int portalCooldown;
|
||||
private boolean invulnerable;
|
||||
- protected UUID uuid = Mth.createInsecureUUID(this.random);
|
||||
+ protected UUID uuid; // Purpur - Add toggle for RNG manipulation
|
||||
protected String stringUUID = this.uuid.toString();
|
||||
private boolean hasGlowingTag;
|
||||
private final Set<String> tags = new io.papermc.paper.util.SizeLimitedSet<>(new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>(), MAX_ENTITY_TAG_COUNT); // Paper - fully limit tag size - replace set impl
|
||||
@@ -526,10 +_,20 @@
|
||||
}
|
||||
// Paper end - optimise entity tracker
|
||||
|
||||
@@ -30,6 +43,14 @@
|
||||
public Entity(EntityType<?> entityType, Level level) {
|
||||
this.type = entityType;
|
||||
this.level = level;
|
||||
this.dimensions = entityType.getDimensions();
|
||||
+ // Purpur start - Add toggle for RNG manipulation
|
||||
+ this.random = level == null || level.purpurConfig.entitySharedRandom ? SHARED_RANDOM : RandomSource.create();
|
||||
+ this.uuid = Mth.createInsecureUUID(this.random);
|
||||
+ // Purpur end - Add toggle for RNG manipulation
|
||||
this.position = Vec3.ZERO;
|
||||
this.blockPosition = BlockPos.ZERO;
|
||||
this.chunkPosition = ChunkPos.ZERO;
|
||||
@@ -1899,7 +_,7 @@
|
||||
return this.isInWater() || flag;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
--- a/net/minecraft/world/entity/animal/Squid.java
|
||||
+++ b/net/minecraft/world/entity/animal/Squid.java
|
||||
@@ -50,6 +_,25 @@
|
||||
@@ -46,10 +_,29 @@
|
||||
|
||||
public Squid(EntityType<? extends Squid> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
- //this.random.setSeed(this.getId()); // Paper - Share random for entities to make them more random
|
||||
+ if (!level.purpurConfig.entitySharedRandom) this.random.setSeed(this.getId()); // Paper - Share random for entities to make them more random // Purpur - Add toggle for RNG manipulation
|
||||
this.tentacleSpeed = 1.0F / (this.random.nextFloat() + 1.0F) * 0.2F;
|
||||
}
|
||||
|
||||
|
||||
@@ -210,9 +210,11 @@ public class PurpurWorldConfig {
|
||||
|
||||
public int entityLifeSpan = 0;
|
||||
public float entityLeftHandedChance = 0.05f;
|
||||
public boolean entitySharedRandom = true;
|
||||
private void entitySettings() {
|
||||
entityLifeSpan = getInt("gameplay-mechanics.entity-lifespan", entityLifeSpan);
|
||||
entityLeftHandedChance = (float) getDouble("gameplay-mechanics.entity-left-handed-chance", entityLeftHandedChance);
|
||||
entitySharedRandom = getBoolean("settings.entity.shared-random", entitySharedRandom);
|
||||
}
|
||||
|
||||
public boolean infinityWorksWithoutArrows = false;
|
||||
|
||||
Reference in New Issue
Block a user