From 56c720914efc422ebec7cf0bdac9bc8c2fe72aac Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 8 May 2020 18:17:47 +0100 Subject: [PATCH] Settings.IMP is terrible. Don't initialise it thousands of times. --- .../fawe/bukkit/adapter/NMSAdapter.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/NMSAdapter.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/NMSAdapter.java index e5b9073ee..eb7bb9673 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/NMSAdapter.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/NMSAdapter.java @@ -15,6 +15,9 @@ public class NMSAdapter { int[] num_palette_buffer, char[] set, Map ticking_blocks) { int air = 0; int num_palette = 0; + char lastOrdinal = BlockID.__RESERVED__; + boolean lastticking = false; + boolean tick_placed = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED; for (int i = 0; i < 4096; i++) { char ordinal = set[i]; switch (ordinal) { @@ -26,11 +29,22 @@ public class NMSAdapter { air++; break; default: - BlockState state = BlockState.getFromOrdinal(ordinal); - if (state.getMaterial().isTicksRandomly()) { - ticking_blocks.put(BlockVector3.at(i & 15, (i >> 8) & 15, (i >> 4) & 15), - WorldEditPlugin.getInstance().getBukkitImplAdapter() - .getInternalBlockStateId(state).orElse(0)); + if (!tick_placed) { + boolean ticking; + if (ordinal != lastOrdinal) { + ticking = BlockTypesCache.ticking[ordinal]; + lastOrdinal = ordinal; + lastticking = ticking; + } else { + ticking = lastticking; + } + if (ticking) { + BlockState state = BlockState.getFromOrdinal(ordinal); + ticking_blocks + .put(BlockVector3.at(i & 15, (i >> 8) & 15, (i >> 4) & 15), + WorldEditPlugin.getInstance().getBukkitImplAdapter() + .getInternalBlockStateId(state).orElse(0)); + } } } int palette = blockToPalette[ordinal]; @@ -53,6 +67,7 @@ public class NMSAdapter { char[] getArr = null; char lastOrdinal = BlockID.__RESERVED__; boolean lastticking = false; + boolean tick_placed = Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED; for (int i = 0; i < 4096; i++) { char ordinal = set[i]; switch (ordinal) { @@ -70,7 +85,7 @@ public class NMSAdapter { air++; break; default: - if (!Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED) { + if (!tick_placed) { boolean ticking; if (ordinal != lastOrdinal) { ticking = BlockTypesCache.ticking[ordinal]; @@ -97,7 +112,7 @@ public class NMSAdapter { air++; break; } - if (Settings.IMP.EXPERIMENTAL.ALLOW_TICK_PLACED) { + if (tick_placed) { boolean ticking; if (ordinal != lastOrdinal) { ticking = BlockTypesCache.ticking[ordinal];