PaperMC/Remapped-Spigot-Server-Patches/0415-Optimise-Chunk-getFluid.patch

68 lines
3.4 KiB
Diff
Raw Normal View History

2021-06-11 13:56:17 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 14 Jan 2020 14:59:08 -0800
Subject: [PATCH] Optimise Chunk#getFluid
Removing the try catch and generally reducing ops should make it
faster on its own, however removing the try catch makes it
easier to inline due to code size
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index 87d7a87a2925f2c062658e960bb5128738828d9f..8a14bdda4a408ec1e2b51efeb35467835f62b42c 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -430,25 +430,29 @@ public class LevelChunk implements ChunkAccess {
}
public FluidState getFluidState(int x, int y, int z) {
- try {
- if (y >= 0 && y >> 4 < this.sections.length) {
- LevelChunkSection chunksection = this.sections[y >> 4];
-
- if (!LevelChunkSection.isEmpty(chunksection)) {
- return chunksection.getFluidState(x & 15, y & 15, z & 15);
+ //try { // Paper - remove try catch
+ // Paper start - reduce the number of ops in this call
+ int index = y >> 4;
+ if (index >= 0 && index < this.sections.length) {
+ LevelChunkSection chunksection = this.sections[index];
+
+ if (chunksection != null) {
+ return chunksection.states.get((y & 15) << 8 | (z & 15) << 4 | x & 15).getFluidState();
}
+ // Paper end
}
return Fluids.EMPTY.defaultFluidState();
- } catch (Throwable throwable) {
- CrashReport crashreport = CrashReport.forThrowable(throwable, "Getting fluid state");
- CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Block being got");
+ /*} catch (Throwable throwable) { // Paper - remove try catch
+ CrashReport crashreport = CrashReport.a(throwable, "Getting fluid state");
+ CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Block being got");
- crashreportsystemdetails.setDetail("Location", () -> {
- return CrashReportCategory.formatLocation(x, y, z);
+ crashreportsystemdetails.a("Location", () -> {
+ return CrashReportSystemDetails.a(i, j, k);
});
throw new ReportedException(crashreport);
}
+ */ // Paper - remove try catch
}
// CraftBukkit start
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
index c44d32f966c61497b4a8892eb51da3a71ad031d9..5e7f6000df129100ef306703f325af9f60da8ae6 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -45,7 +45,7 @@ public class LevelChunkSection {
}
public FluidState getFluidState(int x, int y, int z) {
- return ((BlockState) this.states.get(x, y, z)).getFluidState();
+ return ((BlockState) this.states.get(x, y, z)).getFluidState(); // Paper - diff on change - we expect this to be effectively just getType(x, y, z).getFluid(). If this changes we need to check other patches that use IBlockData#getFluid.
}
public void acquire() {