Skip to content

Commit

Permalink
Re-add and fix the patch that optimizes light level comparisons
Browse files Browse the repository at this point in the history
Fix issue #257 getSkylightSubtracted() returning incorrect var and fix this.random.nextInt passing 9 instead of 8
  • Loading branch information
uRyanxD authored Nov 12, 2024
1 parent 5cefdb8 commit 14d8410
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions patches/server/0072-Add-World-Util-Methods.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ index 03fe76355813497a5db33ad185db0e4b40c6f85a..df28cca6175ff3ddf4992c44a0760ef1
int j = blockposition.getX() & 15;
int k = blockposition.getY();
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 084f107bf019b0f2e00d17a470632780db490abc..a429dc5e950a31557d444d0a50ed71d13f13d555 100644
index 589bf95c13e9c78c792498a7b73fd0480f4a503d..36524e82242dbe948b8a0dba1d538e48b5653a9b 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -93,7 +93,7 @@ public abstract class World implements IBlockAccess {
public final boolean isClientSide;
// CraftBukkit - longhashset
// protected LongHashSet chunkTickList = new LongHashSet(); // Spigot
- private int L;
+ private int L; private int getSkylightSubtracted() { return this.L; } // PandaSpigot - OBFHELPER
public boolean allowMonsters; // CraftBukkit - public
public boolean allowAnimals; // CraftBukkit - public
private boolean M;
@@ -70,7 +70,7 @@ public abstract class World implements IBlockAccess {
public final List<Entity> k = Lists.newArrayList();
protected final IntHashMap<Entity> entitiesById = new IntHashMap();
private long d = 16777215L;
- private int I;
+ private int I; private int getSkylightSubtracted() { return this.I; } // PandaSpigot - OBFHELPER
protected int m = (new Random()).nextInt();
protected final int n = 1013904223;
protected float o;
@@ -175,6 +175,12 @@ public abstract class World implements IBlockAccess {
return (CraftServer) Bukkit.getServer();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: mechoriet <kevinworm92@gmail.com>
Date: Mon, 24 Oct 2022 00:04:41 +0200
Subject: [PATCH] Optimize light level comparisons
Date: Mon, 11 Nov 2024 19:10:53 -0300
Subject: [PATCH] Optimized Light Level Comparisons


diff --git a/src/main/java/net/minecraft/server/BlockCrops.java b/src/main/java/net/minecraft/server/BlockCrops.java
Expand All @@ -18,7 +18,7 @@ index b91b2200d56d9f0b4a50293fbc497a7aca7b9cec..f9429059302cfeba9d7ea6c1cb7f0dbe

if (i < 7) {
diff --git a/src/main/java/net/minecraft/server/BlockGrass.java b/src/main/java/net/minecraft/server/BlockGrass.java
index 844ad30fd55cd8fed6e9b6c1d9f964a72a501b16..f38d0bf6a2b85ea0757319acb07fe32088481cd6 100644
index 844ad30fd55cd8fed6e9b6c1d9f964a72a501b16..fdef82427d2721ac068f7d24025438c70f6e237c 100644
--- a/src/main/java/net/minecraft/server/BlockGrass.java
+++ b/src/main/java/net/minecraft/server/BlockGrass.java
@@ -29,7 +29,8 @@ public class BlockGrass extends Block implements IBlockFragilePlantElement {
Expand Down Expand Up @@ -53,7 +53,7 @@ index 844ad30fd55cd8fed6e9b6c1d9f964a72a501b16..f38d0bf6a2b85ea0757319acb07fe320
+ }

- if (iblockdata1.getBlock() == Blocks.DIRT && iblockdata1.get(BlockDirt.VARIANT) == BlockDirt.EnumDirtVariant.DIRT && world.getLightLevel(blockposition1.up()) >= 4 && block.p() <= 2) {
+ if (iblockdata1.getBlock() == Blocks.DIRT && iblockdata1.get(BlockDirt.VARIANT) == BlockDirt.EnumDirtVariant.DIRT && block.p() <= 2 && world.isLightLevel(blockposition1.up(), 4)) {
+ if (iblockdata1.getBlock() == Blocks.DIRT && iblockdata1.get(BlockDirt.VARIANT) == BlockDirt.EnumDirtVariant.DIRT && block.p() <= 2 && world.isLightLevel(blockposition1.up(), 4)) { // Move last check before isLightLevel to avoid unneeded light checks
+ // PandaSpigot end
// CraftBukkit start
// world.setTypeUpdate(blockposition1, Blocks.GRASS.getBlockData());
Expand Down Expand Up @@ -85,7 +85,7 @@ index 2618c40f25ccf51d50e83aaa1109b493bf13c2fb..24daf93ef18f46e307cf35e627f900a5

if (random.nextInt((int) (world.growthOdds / (this == Blocks.PUMPKIN_STEM? world.spigotConfig.pumpkinModifier : world.spigotConfig.melonModifier) * (25.0F / f)) + 1) == 0) { // Spigot
diff --git a/src/main/java/net/minecraft/server/EntityMonster.java b/src/main/java/net/minecraft/server/EntityMonster.java
index 9fefb867bca8685b7c571dda0d05091c05d335d6..4bf4de3ddb13718a854b4e9c6eeb2483ae5f448d 100644
index 9fefb867bca8685b7c571dda0d05091c05d335d6..05e4dbc1d130c497e2455d9eb1b339d10cd1527b 100644
--- a/src/main/java/net/minecraft/server/EntityMonster.java
+++ b/src/main/java/net/minecraft/server/EntityMonster.java
@@ -107,17 +107,20 @@ public abstract class EntityMonster extends EntityCreature implements IMonster {
Expand All @@ -94,7 +94,7 @@ index 9fefb867bca8685b7c571dda0d05091c05d335d6..4bf4de3ddb13718a854b4e9c6eeb2483
} else {
- int i = this.world.getLightLevel(blockposition);
+ // PandaSpigot start
+ //int i = this.world.getLightLevel(blockposition);
+ // int i = this.world.getLightLevel(blockposition);
+ boolean passes;
+ // PandaSpigot end

Expand All @@ -103,10 +103,10 @@ index 9fefb867bca8685b7c571dda0d05091c05d335d6..4bf4de3ddb13718a854b4e9c6eeb2483

this.world.c(10);
- i = this.world.getLightLevel(blockposition);
+ passes = !world.isLightLevel(blockposition, this.random.nextInt(9)); // PandaSpigot
+ passes = !this.world.isLightLevel(blockposition, this.random.nextInt(8)); // PandaSpigot
this.world.c(j);
- }
+ } else { passes = !world.isLightLevel(blockposition, this.random.nextInt(9)); } // PandaSpigot
+ } else { passes = !this.world.isLightLevel(blockposition, this.random.nextInt(8)); } // PandaSpigot

- return i <= this.random.nextInt(8);
+ return passes; // PandaSpigot
Expand Down

0 comments on commit 14d8410

Please sign in to comment.