papermc/Spigot-Server-Patches/0072-Optimize-isValidLocation-getType-and-getBlockData-fo.patch

100 lines
4.3 KiB
Diff
Raw Normal View History

From ad7babe3efdc1b799a999c0fcf8e4d3f49344752 Mon Sep 17 00:00:00 2001
2019-04-27 03:05:36 +00:00
From: Aikar <aikar@aikar.co>
Date: Thu, 3 Mar 2016 02:07:55 -0600
Subject: [PATCH] Optimize isValidLocation, getType and getBlockData for inling
Hot methods, so reduce # of instructions for the method.
Move is valid location test to the BlockPosition class so that it can access local variables.
Replace all calls to the new place to the unnecessary forward.
Optimize getType and getBlockData to manually inline and optimize the calls
diff --git a/src/main/java/net/minecraft/server/BaseBlockPosition.java b/src/main/java/net/minecraft/server/BaseBlockPosition.java
index a3b5793e4..71089442c 100644
2019-04-27 03:05:36 +00:00
--- a/src/main/java/net/minecraft/server/BaseBlockPosition.java
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
2019-12-11 02:43:21 +00:00
@@ -13,6 +13,14 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
2019-04-27 03:05:36 +00:00
private final int b;
2019-12-11 02:43:21 +00:00
@Deprecated
2019-04-27 03:05:36 +00:00
private final int c;
+ // Paper start
+ public boolean isValidLocation() {
+ return a >= -30000000 && c >= -30000000 && a < 30000000 && c < 30000000 && b >= 0 && b < 256;
+ }
+ public boolean isInvalidYLocation() {
+ return b < 0 || b >= 256;
+ }
+ // Paper end
public BaseBlockPosition(int i, int j, int k) {
this.a = i;
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index f3d20f214..ee94f59e6 100644
2019-04-27 03:05:36 +00:00
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -208,12 +208,24 @@ public class Chunk implements IChunkAccess {
2019-04-27 03:05:36 +00:00
return this.sections;
}
- @Override
2019-05-14 02:20:58 +00:00
+ // Paper start - Optimize getBlockData to reduce instructions
+ public final IBlockData getBlockData(BlockPosition pos) { return getBlockData(pos.getX(), pos.getY(), pos.getZ()); } // Paper
public IBlockData getType(BlockPosition blockposition) {
2019-04-27 03:05:36 +00:00
- int i = blockposition.getX();
- int j = blockposition.getY();
- int k = blockposition.getZ();
+ return this.getBlockData(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ }
+ public final IBlockData getBlockData(final int x, final int y, final int z) {
+ // Method body / logic copied from below
+ final int i = y >> 4;
+ if (y >= 0 && i < this.sections.length && this.sections[i] != null) {
+ // Inlined ChunkSection.getType() and DataPaletteBlock.a(int,int,int)
+ return this.sections[i].blockIds.a((y & 15) << 8 | (z & 15) << 4 | x & 15);
+ }
+ return Blocks.AIR.getBlockData();
+ }
+
+ public IBlockData getBlockData_unused(int i, int j, int k) {
+ // Paper end
if (this.world.P() == WorldType.DEBUG_ALL_BLOCK_STATES) {
IBlockData iblockdata = null;
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java
index 652067757..0d5deee36 100644
2019-04-27 03:05:36 +00:00
--- a/src/main/java/net/minecraft/server/ChunkSection.java
+++ b/src/main/java/net/minecraft/server/ChunkSection.java
@@ -9,7 +9,7 @@ public class ChunkSection {
private short nonEmptyBlockCount;
private short tickingBlockCount;
private short e;
- private final DataPaletteBlock<IBlockData> blockIds;
2019-12-11 02:43:21 +00:00
+ final DataPaletteBlock<IBlockData> blockIds;
2019-04-27 03:05:36 +00:00
public ChunkSection(int i) {
this(i, (short) 0, (short) 0, (short) 0);
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index c2039d0e4..502da7f52 100644
2019-04-27 03:05:36 +00:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -171,11 +171,11 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-04-27 03:05:36 +00:00
}
public static boolean isValidLocation(BlockPosition blockposition) {
2019-05-14 02:20:58 +00:00
- return !isOutsideWorld(blockposition) && blockposition.getX() >= -30000000 && blockposition.getZ() >= -30000000 && blockposition.getX() < 30000000 && blockposition.getZ() < 30000000;
2019-12-11 02:43:21 +00:00
+ return blockposition.isValidLocation();
2019-04-27 03:05:36 +00:00
}
2019-05-14 02:20:58 +00:00
public static boolean isOutsideWorld(BlockPosition blockposition) {
2019-04-27 03:05:36 +00:00
- return b(blockposition.getY());
2019-12-11 02:43:21 +00:00
+ return blockposition.isInvalidYLocation();
2019-04-27 03:05:36 +00:00
}
public static boolean b(int i) {
--
Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 93e39ce1 Clarify documentation regarding getMaterial with legacyName = true c3aeaea0 Improve dependency tracker 14c9d275 Add support for transitive depends in load access warning c8afe560 SPIGOT-5526: Add EntityEnterBlockEvent 6bb6f07d SPIGOT-5548: Show error that hints towards plugins misusing reflection ed75537d SPIGOT-5546: Fix bad depend access using wrong provider in message 4e4c0ee9 Fix buggy classloader warning triggering for all classes 89586a4c Print warning when loading classes from depends that have not been specified d4fe9680 Fix bug where disablePlugin could remove ConfigurationSerializable classes from other plugins 85e683b7 Add additional checkstyle checks 612fd8e1 Correct max page count in BookMeta docs fa8a9781 Correct max title length in BookMeta docs CraftBukkit Changes: ab13a117 SPIGOT-5550: Cancelled ProjectileLaunchEvent still plays sound for eggs 44016b1d SPIGOT-5538: Using javaw to run GUI prints input error e653ae76 SPIGOT-5526: Call EntityEnterBlockEvent for bees trying to enter hives 6515ea49 SPIGOT-5537: Bee nests generated by growing trees near flower have no bees d82b3149 Remove unused CraftWorld.getId method 10763a88 Change some block == AIR checks to isAir to catch CAVE_AIR Spigot Changes: f2c1cd15 Rebuild patches bcd458ad Reformat patches
2020-01-28 19:43:57 +00:00
2.25.0
2019-04-27 03:05:36 +00:00