diff --git a/core/src/main/java/com/boydti/fawe/config/Settings.java b/core/src/main/java/com/boydti/fawe/config/Settings.java index b386d9f6..2c101516 100644 --- a/core/src/main/java/com/boydti/fawe/config/Settings.java +++ b/core/src/main/java/com/boydti/fawe/config/Settings.java @@ -331,6 +331,7 @@ public class Settings extends Config { "If packet sending should be delayed until relight is finished", }) public boolean DELAY_PACKET_SENDING = true; + public boolean ASYNC = true; @Comment({ "The relighting mode to use:", " - 0 = None (Do no relighting)", diff --git a/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java b/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java index 17e52228..336afd78 100644 --- a/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java +++ b/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java @@ -1,10 +1,13 @@ package com.boydti.fawe.example; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.IntegerTrio; +import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.util.MathMan; +import com.boydti.fawe.util.TaskManager; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import java.util.ArrayDeque; @@ -220,15 +223,25 @@ public class NMSRelighter implements Relighter{ } public synchronized void sendChunks() { - Iterator> iter = chunksToSend.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = iter.next(); - long pair = entry.getKey(); - int bitMask = entry.getValue(); - int x = MathMan.unpairIntX(pair); - int z = MathMan.unpairIntY(pair); - queue.sendChunk(x, z, bitMask); - iter.remove(); + RunnableVal runnable = new RunnableVal() { + @Override + public void run(Object value) { + Iterator> iter = chunksToSend.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + long pair = entry.getKey(); + int bitMask = entry.getValue(); + int x = MathMan.unpairIntX(pair); + int z = MathMan.unpairIntY(pair); + queue.sendChunk(x, z, bitMask); + iter.remove(); + } + } + }; + if (Settings.IMP.LIGHTING.ASYNC) { + runnable.run(); + } else { + TaskManager.IMP.sync(runnable); } } diff --git a/core/src/main/java/com/sk89q/worldedit/LocalSession.java b/core/src/main/java/com/sk89q/worldedit/LocalSession.java index 12696ab9..27bc9aa4 100644 --- a/core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit; import com.boydti.fawe.Fawe; +import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweInputStream; import com.boydti.fawe.object.FaweOutputStream; @@ -955,9 +956,15 @@ public class LocalSession { * @param item the item type ID * @return the tool, which may be {@link null} */ + @Deprecated @Nullable public Tool getTool(int item) { - return tools.get(item); + return tools.get(FaweCache.getCombined(item, 0)); + } + + @Nullable + public Tool getTool(int id, int data) { + return tools.get(FaweCache.getCombined(id, data)); } @Nullable @@ -1007,19 +1014,25 @@ public class LocalSession { * @param tool the tool to set, which can be {@code null} * @throws InvalidToolBindException if the item can't be bound to that item */ + @Deprecated public void setTool(int item, @Nullable Tool tool) throws InvalidToolBindException { setTool(item, tool, null); } + @Deprecated public void setTool(int item, @Nullable Tool tool, Player player) throws InvalidToolBindException { - if (item > 0 && item < 255) { - throw new InvalidToolBindException(item, "Blocks can't be used"); - } else if (item == config.wandItem) { - throw new InvalidToolBindException(item, "Already used for the wand"); - } else if (item == config.navigationWand) { - throw new InvalidToolBindException(item, "Already used for the navigation wand"); + setTool(item, 0, tool, player); + } + + public void setTool(int id, int data, @Nullable Tool tool, Player player) throws InvalidToolBindException { + if (id > 0 && id < 255) { + throw new InvalidToolBindException(id, "Blocks can't be used"); + } else if (id == config.wandItem) { + throw new InvalidToolBindException(id, "Already used for the wand"); + } else if (id == config.navigationWand) { + throw new InvalidToolBindException(id, "Already used for the navigation wand"); } - Tool previous = this.tools.put(item, tool); + Tool previous = this.tools.put(FaweCache.getCombined(id, data), tool); if (player != null) { if (previous instanceof BrushTool) { BrushTool brushTool = (BrushTool) previous;