From e16bcae0718c92d2316a9148193c2e30194d380f Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 18 Nov 2016 08:44:16 +1100 Subject: [PATCH] Some minor fixes --- .../fawe/bukkit/v0/BukkitChunk_All.java | 21 ++ .../fawe/bukkit/v0/BukkitQueue_All.java | 2 +- .../BukkitCommandSender_unused_for_now.java | 219 ++++++++++++++++++ .../fawe/bukkit/v1_10/BukkitChunk_1_10.java | 62 ++++- .../fawe/bukkit/v1_10/BukkitQueue_1_10.java | 12 +- .../fawe/bukkit/v1_11/BukkitChunk_1_11.java | 33 ++- .../fawe/bukkit/v1_11/BukkitQueue_1_11.java | 12 +- .../fawe/bukkit/v1_7/BukkitChunk_1_7.java | 53 ++--- .../fawe/bukkit/v1_7/BukkitQueue17.java | 11 +- .../fawe/bukkit/v1_8/BukkitChunk_1_8.java | 24 +- .../fawe/bukkit/v1_8/BukkitQueue18R3.java | 12 +- .../fawe/bukkit/v1_9/BukkitChunk_1_9.java | 63 ++++- .../fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java | 12 +- .../main/java/com/boydti/fawe/FaweCache.java | 18 ++ .../boydti/fawe/example/CharFaweChunk.java | 62 ++--- .../fawe/example/NMSMappedFaweQueue.java | 2 +- .../com/boydti/fawe/example/NMSRelighter.java | 17 -- .../com/boydti/fawe/jnbt/anvil/MCAQueue.java | 7 +- .../object/extent/FastWorldEditExtent.java | 20 ++ .../java/com/boydti/fawe/util/MemUtil.java | 8 +- .../java/com/boydti/fawe/util/WEManager.java | 42 ++-- .../function/entity/ExtentEntityCopy.java | 16 +- .../boydti/fawe/forge/v0/ForgeChunk_All.java | 37 ++- .../boydti/fawe/forge/v0/ForgeQueue_All.java | 12 +- .../boydti/fawe/forge/v0/ForgeChunk_All.java | 53 +++-- .../boydti/fawe/forge/v0/ForgeQueue_All.java | 11 +- .../boydti/fawe/forge/v0/ForgeChunk_All.java | 23 ++ .../boydti/fawe/forge/v0/ForgeQueue_All.java | 12 +- .../boydti/fawe/forge/v0/ForgeChunk_All.java | 37 ++- .../boydti/fawe/forge/v0/ForgeQueue_All.java | 12 +- .../optimization/queue/NukkitChunk.java | 28 ++- .../optimization/queue/NukkitQueue.java | 7 +- 32 files changed, 700 insertions(+), 260 deletions(-) create mode 100644 bukkit0/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender_unused_for_now.java diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java index 08ff48b5..ace2ac84 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitChunk_All.java @@ -31,6 +31,27 @@ public class BukkitChunk_All extends CharFaweChunk { super(parent, x, z); } + public BukkitChunk_All(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap) { + super(parent, x, z, ids, count, air, relight, heightMap); + } + + @Override + public CharFaweChunk copy(boolean shallow) { + BukkitChunk_All copy; + if (shallow) { + copy = new BukkitChunk_All(getParent(), getX(), getZ(), ids, count, air, relight, heightMap); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new BukkitChunk_All(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } + return copy; + } + @Override public Chunk getNewChunk() { return Bukkit.getWorld(getParent().getWorldName()).getChunkAt(getX(), getZ()); diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java index 90e1e9b1..35421d4e 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java @@ -38,7 +38,7 @@ public class BukkitQueue_All extends BukkitQueue_0 { } @Override - public void setHeightMap(FaweChunk chunk, int[] heightMap) { + public void setHeightMap(FaweChunk chunk, byte[] heightMap) { // Do nothing } diff --git a/bukkit0/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender_unused_for_now.java b/bukkit0/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender_unused_for_now.java new file mode 100644 index 00000000..0f6796f0 --- /dev/null +++ b/bukkit0/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender_unused_for_now.java @@ -0,0 +1,219 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.bukkit; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldVector; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.extension.platform.AbstractPlayerActor; +import com.sk89q.worldedit.extent.inventory.BlockBag; +import com.sk89q.worldedit.internal.cui.CUIEvent; +import com.sk89q.worldedit.session.SessionKey; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.auth.AuthorizationException; +import com.sk89q.worldedit.world.World; +import java.io.File; +import java.util.UUID; +import javax.annotation.Nullable; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +public class BukkitCommandSender_unused_for_now extends AbstractPlayerActor { + + /** + * One time generated ID. + */ + private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be"); + + private CommandSender player; + private WorldEditPlugin plugin; + + public BukkitCommandSender_unused_for_now(WorldEditPlugin plugin, CommandSender sender) { + checkNotNull(plugin); + checkNotNull(sender); + checkArgument(!(sender instanceof Player), "Cannot wrap a player"); + + this.plugin = plugin; + this.player = sender; + } + + @Override + public UUID getUniqueId() { + return DEFAULT_ID; + } + + @Override + public String getName() { + return player.getName(); + } + + @Override + public void printRaw(String msg) { + for (String part : msg.split("\n")) { + player.sendMessage(part); + } + } + + @Override + public void print(String msg) { + for (String part : msg.split("\n")) { + player.sendMessage("\u00A7d" + part); + } + } + + @Override + public void printDebug(String msg) { + for (String part : msg.split("\n")) { + player.sendMessage("\u00A77" + part); + } + } + + @Override + public void printError(String msg) { + for (String part : msg.split("\n")) { + player.sendMessage("\u00A7c" + part); + } + } + + @Override + public boolean canDestroyBedrock() { + return true; + } + + @Override + public String[] getGroups() { + return new String[0]; + } + + @Override + public boolean hasPermission(String perm) { + return true; + } + + @Override + public void checkPermission(String permission) throws AuthorizationException { + } + + @Override + public boolean isPlayer() { + return false; + } + + @Override + public File openFileOpenDialog(String[] extensions) { + return null; + } + + @Override + public File openFileSaveDialog(String[] extensions) { + return null; + } + + @Override + public void dispatchCUIEvent(CUIEvent event) { + } + + @Override + public SessionKey getSessionKey() { + return new SessionKey() { + @Nullable + @Override + public String getName() { + return null; + } + + @Override + public boolean isActive() { + return false; + } + + @Override + public boolean isPersistent() { + return false; + } + + @Override + public UUID getUniqueId() { + return DEFAULT_ID; + } + }; + } + + @Override + public World getWorld() { + return null; + } + + @Override + public int getItemInHand() { + return 0; + } + + @Override + public void giveItem(int type, int amount) { + + } + + @Override + public BlockBag getInventoryBlockBag() { + return null; + } + + @Override + public WorldVector getPosition() { + return null; + } + + @Override + public double getPitch() { + return 0; + } + + @Override + public double getYaw() { + return 0; + } + + @Override + public void setPosition(Vector pos, float pitch, float yaw) { + + } + + @Nullable + @Override + public BaseEntity getState() { + return null; + } + + @Override + public Location getLocation() { + return null; + } + + @Nullable + @Override + public T getFacet(Class cls) { + return null; + } +} \ No newline at end of file diff --git a/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitChunk_1_10.java b/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitChunk_1_10.java index edcab622..37c0164a 100644 --- a/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitChunk_1_10.java +++ b/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitChunk_1_10.java @@ -10,12 +10,35 @@ import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; -import com.sk89q.jnbt.*; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.LongTag; +import com.sk89q.jnbt.StringTag; +import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.internal.Constants; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.util.*; -import net.minecraft.server.v1_10_R1.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import net.minecraft.server.v1_10_R1.Block; +import net.minecraft.server.v1_10_R1.BlockPosition; +import net.minecraft.server.v1_10_R1.ChunkSection; +import net.minecraft.server.v1_10_R1.DataBits; +import net.minecraft.server.v1_10_R1.DataPalette; +import net.minecraft.server.v1_10_R1.DataPaletteBlock; +import net.minecraft.server.v1_10_R1.DataPaletteGlobal; +import net.minecraft.server.v1_10_R1.Entity; +import net.minecraft.server.v1_10_R1.EntityPlayer; +import net.minecraft.server.v1_10_R1.EntityTypes; +import net.minecraft.server.v1_10_R1.IBlockData; +import net.minecraft.server.v1_10_R1.NBTTagCompound; +import net.minecraft.server.v1_10_R1.TileEntity; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.craftbukkit.v1_10_R1.CraftChunk; @@ -36,16 +59,26 @@ public class BukkitChunk_1_10 extends CharFaweChunk { super(parent, x, z); } - @Override - public Chunk getNewChunk() { - return ((com.boydti.fawe.bukkit.v1_10.BukkitQueue_1_10) getParent()).getWorld().getChunkAt(getX(), getZ()); + public BukkitChunk_1_10(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap) { + super(parent, x, z, ids, count, air, relight, heightMap); } @Override - public CharFaweChunk copy(boolean shallow) { - BukkitChunk_1_10 value = (BukkitChunk_1_10) super.copy(shallow); + public CharFaweChunk copy(boolean shallow) { + BukkitChunk_1_10 copy; + if (shallow) { + copy = new BukkitChunk_1_10(getParent(), getX(), getZ(), ids, count, air, relight, heightMap); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new BukkitChunk_1_10(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } if (sectionPalettes != null) { - value.sectionPalettes = new DataPaletteBlock[16]; + copy.sectionPalettes = new DataPaletteBlock[16]; try { Field fieldBits = DataPaletteBlock.class.getDeclaredField("b"); fieldBits.setAccessible(true); @@ -83,13 +116,18 @@ public class BukkitChunk_1_10 extends CharFaweChunk { field.set(newBits, currentValue); } fieldBits.set(paletteBlock, newBits); - value.sectionPalettes[i] = paletteBlock; + copy.sectionPalettes[i] = paletteBlock; } } catch (Throwable e) { MainUtil.handleError(e); } } - return value; + return copy; + } + + @Override + public Chunk getNewChunk() { + return ((com.boydti.fawe.bukkit.v1_10.BukkitQueue_1_10) getParent()).getWorld().getChunkAt(getX(), getZ()); } public DataPaletteBlock newDataPaletteBlock() { @@ -152,6 +190,8 @@ public class BukkitChunk_1_10 extends CharFaweChunk { Class clazzChunk = nmsChunk.getClass(); final Collection[] entities = (Collection[]) getParent().getEntitySlices.invoke(nmsChunk); Map tiles = nmsChunk.getTileEntities(); + // Set heightmap + getParent().setHeightMap(this, heightMap); // Remove entities for (int i = 0; i < entities.length; i++) { int count = this.getCount(i); diff --git a/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitQueue_1_10.java b/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitQueue_1_10.java index ea84f48b..26bcbb55 100644 --- a/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitQueue_1_10.java +++ b/bukkit110/src/main/java/com/boydti/fawe/bukkit/v1_10/BukkitQueue_1_10.java @@ -81,13 +81,14 @@ public class BukkitQueue_1_10 extends BukkitQueue_0 otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } @@ -288,7 +289,7 @@ public class BukkitQueue_1_10 extends BukkitQueue_0[] entities = (Collection[]) entitiesGeneric; BukkitChunk_1_10 previous = getFaweChunk(fs.getX(), fs.getZ()); // Copy blocks - char[][] idPrevious = new char[16][]; + char[][] idPrevious = previous.getCombinedIdArrays(); for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { ChunkSection section = sections[layer]; @@ -459,7 +460,6 @@ public class BukkitQueue_1_10 extends BukkitQueue_0 entry : tiles.entrySet()) { diff --git a/bukkit111/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitChunk_1_11.java b/bukkit111/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitChunk_1_11.java index 70f379de..18bc16f2 100644 --- a/bukkit111/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitChunk_1_11.java +++ b/bukkit111/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitChunk_1_11.java @@ -62,16 +62,26 @@ public class BukkitChunk_1_11 extends CharFaweChunk copy(boolean shallow) { - BukkitChunk_1_11 value = (BukkitChunk_1_11) super.copy(shallow); + public CharFaweChunk copy(boolean shallow) { + BukkitChunk_1_11 copy; + if (shallow) { + copy = new BukkitChunk_1_11(getParent(), getX(), getZ(), ids, count, air, relight, heightMap); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new BukkitChunk_1_11(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } if (sectionPalettes != null) { - value.sectionPalettes = new DataPaletteBlock[16]; + copy.sectionPalettes = new DataPaletteBlock[16]; try { Field fieldBits = DataPaletteBlock.class.getDeclaredField("b"); fieldBits.setAccessible(true); @@ -109,13 +119,18 @@ public class BukkitChunk_1_11 extends CharFaweChunk clazzChunk = nmsChunk.getClass(); final Collection[] entities = (Collection[]) getParent().getEntitySlices.invoke(nmsChunk); Map tiles = nmsChunk.getTileEntities(); + // Set heightmap + getParent().setHeightMap(this, heightMap); // Remove entities for (int i = 0; i < entities.length; i++) { int count = this.getCount(i); diff --git a/bukkit111/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitQueue_1_11.java b/bukkit111/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitQueue_1_11.java index 9e4a755f..7e768b2d 100644 --- a/bukkit111/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitQueue_1_11.java +++ b/bukkit111/src/main/java/com/boydti/fawe/bukkit/v1_11/BukkitQueue_1_11.java @@ -55,13 +55,14 @@ public class BukkitQueue_1_11 extends BukkitQueue_0 otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } @@ -262,7 +263,7 @@ public class BukkitQueue_1_11 extends BukkitQueue_0[] entities = (Collection[]) entitiesGeneric; BukkitChunk_1_11 previous = getFaweChunk(fs.getX(), fs.getZ()); // Copy blocks - char[][] idPrevious = new char[16][]; + char[][] idPrevious = previous.getCombinedIdArrays(); for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { ChunkSection section = sections[layer]; @@ -433,7 +434,6 @@ public class BukkitQueue_1_11 extends BukkitQueue_0 entry : tiles.entrySet()) { diff --git a/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitChunk_1_7.java b/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitChunk_1_7.java index d0099353..b9eaa802 100644 --- a/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitChunk_1_7.java +++ b/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitChunk_1_7.java @@ -43,8 +43,8 @@ public class BukkitChunk_1_7 extends CharFaweChunk { return Bukkit.getWorld(getParent().getWorldName()).getChunkAt(getX(), getZ()); } - public byte[][] byteIds; - public NibbleArray[] datas; + public final byte[][] byteIds; + public final NibbleArray[] datas; public BukkitChunk_1_7(FaweQueue parent, int x, int z) { super(parent, x, z); @@ -52,6 +52,29 @@ public class BukkitChunk_1_7 extends CharFaweChunk { this.datas = new NibbleArray[16]; } + public BukkitChunk_1_7(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap, byte[][] byteIds, NibbleArray[] datas) { + super(parent, x, z, ids, count, air, relight, heightMap); + this.byteIds = byteIds; + this.datas = datas; + } + + @Override + public CharFaweChunk copy(boolean shallow) { + BukkitChunk_1_7 copy; + if (shallow) { + copy = new BukkitChunk_1_7(getParent(), getX(), getZ(), ids, count, air, relight, heightMap, byteIds, datas); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new BukkitChunk_1_7(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone(), (byte[][]) MainUtil.copyNd(byteIds), datas.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } + return copy; + } + public byte[] getByteIdArray(int i) { return this.byteIds[i]; } @@ -114,29 +137,6 @@ public class BukkitChunk_1_7 extends CharFaweChunk { } } - @Override - public BukkitChunk_1_7 copy(boolean shallow) { - BukkitChunk_1_7 copy = new BukkitChunk_1_7(getParent(), getX(), getZ()); - if (shallow) { - copy.byteIds = byteIds; - copy.datas = datas; - copy.air = air; - copy.biomes = biomes; - copy.chunk = chunk; - copy.count = count; - copy.relight = relight; - } else { - copy.byteIds = (byte[][]) MainUtil.copyNd(byteIds); - copy.datas = datas.clone(); - copy.air = air.clone(); - copy.biomes = biomes.clone(); - copy.chunk = chunk; - copy.count = count.clone(); - copy.relight = relight.clone(); - } - return copy; - } - @Override public void start() { getChunk().load(true); @@ -155,7 +155,8 @@ public class BukkitChunk_1_7 extends CharFaweChunk { ChunkSection[] sections = nmsChunk.getSections(); Map tiles = nmsChunk.tileEntities; Collection[] entities = nmsChunk.entitySlices; - + // Set heightmap + getParent().setHeightMap(this, heightMap); // Remove entities for (int i = 0; i < 16; i++) { int count = this.getCount(i); diff --git a/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitQueue17.java b/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitQueue17.java index dede9fa3..6014f6f6 100644 --- a/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitQueue17.java +++ b/bukkit1710/src/main/java/com/boydti/fawe/bukkit/v1_7/BukkitQueue17.java @@ -87,13 +87,14 @@ public class BukkitQueue17 extends BukkitQueue_0 otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } @@ -165,7 +166,6 @@ public class BukkitQueue17 extends BukkitQueue_0 tiles = (Map) tilesGeneric; Collection[] entities = (Collection[]) entitiesGeneric; CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); - char[][] idPrevious = new char[16][]; for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { ChunkSection section = sections[layer]; @@ -184,7 +184,6 @@ public class BukkitQueue17 extends BukkitQueue_0 entry : tiles.entrySet()) { TileEntity tile = entry.getValue(); @@ -298,7 +297,7 @@ public class BukkitQueue17 extends BukkitQueue_0 { super(parent, x, z); } + public BukkitChunk_1_8(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap) { + super(parent, x, z, ids, count, air, relight, heightMap); + } + + @Override + public CharFaweChunk copy(boolean shallow) { + BukkitChunk_1_8 copy; + if (shallow) { + copy = new BukkitChunk_1_8(getParent(), getX(), getZ(), ids, count, air, relight, heightMap); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new BukkitChunk_1_8(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } + return copy; + } + @Override public Chunk getNewChunk() { return Bukkit.getWorld(getParent().getWorldName()).getChunkAt(getX(), getZ()); @@ -69,7 +90,8 @@ public class BukkitChunk_1_8 extends CharFaweChunk { ChunkSection[] sections = nmsChunk.getSections(); Map tiles = nmsChunk.getTileEntities(); Collection[] entities = nmsChunk.getEntitySlices(); - + // Set heightmap + getParent().setHeightMap(this, heightMap); // Remove entities for (int i = 0; i < 16; i++) { int count = this.getCount(i); diff --git a/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java b/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java index 497b4ea0..edefd5f9 100644 --- a/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java +++ b/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java @@ -85,13 +85,14 @@ public class BukkitQueue18R3 extends BukkitQueue_0 otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } @@ -160,7 +161,7 @@ public class BukkitQueue18R3 extends BukkitQueue_0 tiles = (Map) tilesGeneric; Collection[] entities = (Collection[]) entitiesGeneric; CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); - char[][] idPrevious = new char[16][]; + char[][] idPrevious = previous.getCombinedIdArrays(); for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { ChunkSection section = sections[layer]; @@ -177,7 +178,6 @@ public class BukkitQueue18R3 extends BukkitQueue_0 entry : tiles.entrySet()) { TileEntity tile = entry.getValue(); @@ -286,7 +286,7 @@ public class BukkitQueue18R3 extends BukkitQueue_0 { super(parent, x, z); } - @Override - public Chunk getNewChunk() { - return ((BukkitQueue_1_9_R1) getParent()).getWorld().getChunkAt(getX(), getZ()); + public BukkitChunk_1_9(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap) { + super(parent, x, z, ids, count, air, relight, heightMap); } @Override - public BukkitChunk_1_9 copy(boolean shallow) { - BukkitChunk_1_9 value = (BukkitChunk_1_9) super.copy(shallow); + public CharFaweChunk copy(boolean shallow) { + BukkitChunk_1_9 copy; + if (shallow) { + copy = new BukkitChunk_1_9(getParent(), getX(), getZ(), ids, count, air, relight, heightMap); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new BukkitChunk_1_9(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } if (sectionPalettes != null) { - value.sectionPalettes = new DataPaletteBlock[16]; + copy.sectionPalettes = new DataPaletteBlock[16]; try { Field fieldBits = DataPaletteBlock.class.getDeclaredField("b"); fieldBits.setAccessible(true); @@ -84,13 +118,18 @@ public class BukkitChunk_1_9 extends CharFaweChunk { field.set(newBits, currentValue); } fieldBits.set(paletteBlock, newBits); - value.sectionPalettes[i] = paletteBlock; + copy.sectionPalettes[i] = paletteBlock; } } catch (Throwable e) { MainUtil.handleError(e); } } - return value; + return copy; + } + + @Override + public Chunk getNewChunk() { + return ((BukkitQueue_1_9_R1) getParent()).getWorld().getChunkAt(getX(), getZ()); } public DataPaletteBlock newDataPaletteBlock() { @@ -154,6 +193,8 @@ public class BukkitChunk_1_9 extends CharFaweChunk { final Field ef = clazzChunk.getDeclaredField("entitySlices"); final Collection[] entities = (Collection[]) ef.get(nmsChunk); Map tiles = nmsChunk.getTileEntities(); + // Set heightmap + getParent().setHeightMap(this, heightMap); // Remove entities for (int i = 0; i < entities.length; i++) { int count = this.getCount(i); diff --git a/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java b/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java index ac8e0f62..47ec0f6e 100644 --- a/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java +++ b/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java @@ -97,13 +97,14 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } @@ -154,7 +155,7 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0[] entities = (Collection[]) entitiesGeneric; CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); // Copy blocks - char[][] idPrevious = new char[16][]; + char[][] idPrevious = previous.getCombinedIdArrays(); for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { ChunkSection section = sections[layer]; @@ -411,7 +412,6 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 entry : tiles.entrySet()) { diff --git a/core/src/main/java/com/boydti/fawe/FaweCache.java b/core/src/main/java/com/boydti/fawe/FaweCache.java index f203d404..ea4cc610 100644 --- a/core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/core/src/main/java/com/boydti/fawe/FaweCache.java @@ -652,8 +652,26 @@ public class FaweCache { case 33: case 151: case 178: + case 209: case 210: case 211: + case 255: + case 219: + case 220: + case 221: + case 222: + case 223: + case 224: + case 225: + case 226: + case 227: + case 228: + case 229: + case 230: + case 231: + case 232: + case 233: + case 234: return true; default: return false; diff --git a/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java b/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java index 50ed82e3..6b9acc66 100644 --- a/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java +++ b/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java @@ -4,7 +4,6 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; -import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.world.biome.BaseBiome; @@ -17,21 +16,28 @@ import java.util.UUID; public abstract class CharFaweChunk extends FaweChunk { - public char[][] ids; - public short[] count; - public short[] air; - public short[] relight; + public final char[][] ids; + public final short[] count; + public final short[] air; + public final short[] relight; + public final byte[] heightMap; + public int[][] biomes; - private int bitMask = -1; - public HashMap tiles; - public HashSet entities; - public HashSet entityRemoves; public T chunk; + public CharFaweChunk(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap) { + super(parent, x, z); + this.ids = ids; + this.count = count; + this.air = air; + this.relight = relight; + this.heightMap = heightMap; + } + /** * A FaweSections object represents a chunk and the blocks that you wish to change in it. * @@ -45,6 +51,7 @@ public abstract class CharFaweChunk extends FaweChunk this.count = new short[HEIGHT >> 4]; this.air = new short[HEIGHT >> 4]; this.relight = new short[HEIGHT >> 4]; + this.heightMap = new byte[256]; } @Override @@ -117,21 +124,15 @@ public abstract class CharFaweChunk extends FaweChunk @Override public int getBitMask() { - if (bitMask == -1) { - this.bitMask = 0; - for (int section = 0; section < ids.length; section++) { - if (ids[section] != null) { - bitMask += 1 << section; - } + int bitMask = 0; + for (int section = 0; section < ids.length; section++) { + if (ids[section] != null) { + bitMask += 1 << section; } } return bitMask; } - public void setBitMask(int value) { - this.bitMask = value; - } - /** * Get the raw data for a section * @param i @@ -247,6 +248,7 @@ public abstract class CharFaweChunk extends FaweChunk this.relight[i]++; default: vs[j] = (char) (id << 4); + heightMap[z << 4 | x] = (byte) y; return; } } @@ -332,6 +334,7 @@ public abstract class CharFaweChunk extends FaweChunk case 191: case 192: vs[j] = (char) (id << 4); + heightMap[z << 4 | x] = (byte) y; return; case 130: case 76: @@ -346,6 +349,7 @@ public abstract class CharFaweChunk extends FaweChunk case 68: // removed default: vs[j] = (char) ((id << 4) + data); + heightMap[z << 4 | x] = (byte) y; return; } } @@ -363,23 +367,5 @@ public abstract class CharFaweChunk extends FaweChunk } @Override - public CharFaweChunk copy(boolean shallow) { - CharFaweChunk copy = (CharFaweChunk) getParent().getFaweChunk(getX(), getZ()); - if (shallow) { - copy.ids = ids; - copy.air = air; - copy.biomes = biomes; - copy.chunk = chunk; - copy.count = count; - copy.relight = relight; - } else { - copy.ids = (char[][]) MainUtil.copyNd(ids); - copy.air = air.clone(); - copy.biomes = biomes.clone(); - copy.chunk = chunk; - copy.count = count.clone(); - copy.relight = relight.clone(); - } - return copy; - } + public abstract CharFaweChunk copy(boolean shallow); } diff --git a/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java b/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java index 216a2355..1b1b701a 100644 --- a/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java @@ -91,7 +91,7 @@ public abstract class NMSMappedFaweQueue ex refreshChunk(fc); } - public abstract void setHeightMap(FaweChunk chunk, int[] heightMap); + public abstract void setHeightMap(FaweChunk chunk, byte[] heightMap); public abstract void setFullbright(CHUNKSECTION sections); 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 0a98e777..0687565c 100644 --- a/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java +++ b/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java @@ -3,9 +3,7 @@ package com.boydti.fawe.example; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweQueue; -import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.util.MathMan; -import com.boydti.fawe.util.TaskManager; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -130,21 +128,8 @@ public class NMSRelighter { for (Map.Entry entry : skyToRelight.entrySet()) { RelightSkyEntry chunk = entry.getValue(); CharFaweChunk fc = (CharFaweChunk) queue.getFaweChunk(chunk.x, chunk.z); - fcs.put(fc, chunk.heightMap); - fc.setBitMask(chunk.bitmask); queue.sendChunk(fc); } - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - for (Map.Entry entry : fcs.entrySet()) { - FaweChunk chunk = entry.getKey(); - if (queue.isChunkLoaded(chunk.getX(), chunk.getZ())) { - queue.setHeightMap(chunk, entry.getValue()); - } - } - } - }); } private boolean isTransparent(int x, int y, int z) { @@ -248,7 +233,6 @@ public class NMSRelighter { break; case 15: if (opacity > 1) { - chunk.heightMap[z << 4 | x] = y; value -= opacity; mask[j] = value; } @@ -347,7 +331,6 @@ public class NMSRelighter { public final int x; public final int z; public final byte[] mask; - public int[] heightMap = new int[256]; public final boolean[] fix; public int bitmask; public boolean smooth; diff --git a/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java b/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java index 962ce9de..bde26619 100644 --- a/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java +++ b/core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java @@ -163,13 +163,14 @@ public class MCAQueue extends NMSMappedFaweQueue otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } diff --git a/core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java b/core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java index ec0d65f3..c8c4c949 100644 --- a/core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java +++ b/core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java @@ -169,6 +169,26 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa case 33: case 151: case 178: + case 209: + case 210: + case 211: + case 255: + case 219: + case 220: + case 221: + case 222: + case 223: + case 224: + case 225: + case 226: + case 227: + case 228: + case 229: + case 230: + case 231: + case 232: + case 233: + case 234: // Tile return queue.setBlock(x, y, z, id, (byte) block.getData(), block.getNbtData()); case 0: diff --git a/core/src/main/java/com/boydti/fawe/util/MemUtil.java b/core/src/main/java/com/boydti/fawe/util/MemUtil.java index 56eca141..0eee3711 100644 --- a/core/src/main/java/com/boydti/fawe/util/MemUtil.java +++ b/core/src/main/java/com/boydti/fawe/util/MemUtil.java @@ -1,8 +1,8 @@ package com.boydti.fawe.util; import com.boydti.fawe.config.Settings; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; public class MemUtil { @@ -42,8 +42,8 @@ public class MemUtil { return size; } - private static BlockingQueue memoryLimitedTasks = new LinkedBlockingQueue<>(); - private static BlockingQueue memoryPlentifulTasks = new LinkedBlockingQueue<>(); + private static Queue memoryLimitedTasks = new ConcurrentLinkedQueue<>(); + private static Queue memoryPlentifulTasks = new ConcurrentLinkedQueue<>(); public static void addMemoryLimitedTask(Runnable run) { if (run != null) diff --git a/core/src/main/java/com/boydti/fawe/util/WEManager.java b/core/src/main/java/com/boydti/fawe/util/WEManager.java index 8419176f..5435bd28 100644 --- a/core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -4,7 +4,6 @@ import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RegionWrapper; -import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.object.extent.NullExtent; import com.boydti.fawe.regions.FaweMask; @@ -73,38 +72,25 @@ public class WEManager { * @return */ public RegionWrapper[] getMask(final FawePlayer player, FaweMaskManager.MaskType type) { -// HashSet mask = TaskManager.IMP.sync(new RunnableVal>() { if (player.hasPermission("fawe.bypass") || !Settings.REGION_RESTRICTIONS) { return new RegionWrapper[] {new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE)}; } - HashSet mask = new RunnableVal>() { - @Override - public void run(HashSet ignore) { - this.value = new HashSet<>(); - String world = player.getLocation().world; - if (!world.equals(player.getMeta("lastMaskWorld"))) { - player.deleteMeta("lastMaskWorld"); - player.deleteMeta("lastMask"); - } - player.setMeta("lastMaskWorld", world); - for (final FaweMaskManager manager : managers) { - if (player.hasPermission("fawe." + manager.getKey())) { - final FaweMask mask = manager.getMask(player); - if (mask != null) { - TaskManager.IMP.async(new Runnable() { - @Override - public void run() { - - } - }); - value.addAll(mask.getRegions()); - } - } + HashSet mask = new HashSet<>(); + String world = player.getLocation().world; + if (!world.equals(player.getMeta("lastMaskWorld"))) { + player.deleteMeta("lastMaskWorld"); + player.deleteMeta("lastMask"); + } + player.setMeta("lastMaskWorld", world); + for (final FaweMaskManager manager : managers) { + if (player.hasPermission("fawe." + manager.getKey())) { + final FaweMask fm = manager.getMask(player); + if (fm != null) { + mask.addAll(fm.getRegions()); } } -// }, 1000); - }.runAndGet(); - if (mask == null || mask.isEmpty()) { + } + if (mask.isEmpty()) { mask = player.getMeta("lastMask"); if (mask == null) { mask = new HashSet<>(); diff --git a/core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index 248775b9..c26c72b4 100644 --- a/core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -95,14 +95,14 @@ public class ExtentEntityCopy implements EntityFunction { Vector pivot = from.round().add(0.5, 0.5, 0.5); Vector newPosition = transform.apply(location.toVector().subtract(pivot)); Vector newDirection; - - newDirection = transform.isIdentity() ? - entity.getLocation().getDirection() - : new Vector(transform.apply(location.getDirection())).subtract(transform.apply(Vector.ZERO)).normalize(); - newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection); - - // Some entities store their position data in NBT - state = transformNbtData(state); + if (transform.isIdentity()) { + newDirection = entity.getLocation().getDirection(); + newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection); + } else { + newDirection = new Vector(transform.apply(location.getDirection())).subtract(transform.apply(Vector.ZERO)).normalize(); + newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection); + state = transformNbtData(state); + } boolean success = destination.createEntity(newLocation, state) != null; diff --git a/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java b/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java index 780fcfa3..17211d20 100644 --- a/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java +++ b/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java @@ -51,17 +51,26 @@ public class ForgeChunk_All extends CharFaweChunk { super(parent, x, z); } - @Override - public Chunk getNewChunk() { - World world = ((ForgeQueue_All) getParent()).getWorld(); - return world.getChunkProvider().provideChunk(getX(), getZ()); + public ForgeChunk_All(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap) { + super(parent, x, z, ids, count, air, relight, heightMap); } @Override - public ForgeChunk_All copy(boolean shallow) { - ForgeChunk_All value = (ForgeChunk_All) super.copy(shallow); + public CharFaweChunk copy(boolean shallow) { + ForgeChunk_All copy; + if (shallow) { + copy = new ForgeChunk_All(getParent(), getX(), getZ(), ids, count, air, relight, heightMap); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new ForgeChunk_All(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } if (sectionPalettes != null) { - value.sectionPalettes = new BlockStateContainer[16]; + copy.sectionPalettes = new BlockStateContainer[16]; try { Field fieldBits = BlockStateContainer.class.getDeclaredField("storage"); fieldBits.setAccessible(true); @@ -99,13 +108,19 @@ public class ForgeChunk_All extends CharFaweChunk { field.set(newBits, currentValue); } fieldBits.set(paletteBlock, newBits); - value.sectionPalettes[i] = paletteBlock; + copy.sectionPalettes[i] = paletteBlock; } } catch (Throwable e) { MainUtil.handleError(e); } } - return value; + return copy; + } + + @Override + public Chunk getNewChunk() { + World world = ((ForgeQueue_All) getParent()).getWorld(); + return world.getChunkProvider().provideChunk(getX(), getZ()); } public void optimize() { @@ -146,6 +161,10 @@ public class ForgeChunk_All extends CharFaweChunk { ExtendedBlockStorage[] sections = nmsChunk.getBlockStorageArray(); Map tiles = nmsChunk.getTileEntityMap(); ClassInheritanceMultiMap[] entities = nmsChunk.getEntityLists(); + + // Set heightmap + getParent().setHeightMap(this, heightMap); + // Remove entities for (int i = 0; i < 16; i++) { int count = this.getCount(i); diff --git a/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index fd1a708e..590fd9c4 100644 --- a/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge110/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -79,13 +79,14 @@ public class ForgeQueue_All extends NMSMappedFaweQueue otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } @@ -235,7 +236,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue tiles = (Map) tilesGeneric; ClassInheritanceMultiMap[] entities = (ClassInheritanceMultiMap[]) entitiesGeneric; CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); - char[][] idPrevious = new char[16][]; + char[][] idPrevious = previous.getCombinedIdArrays(); for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { ExtendedBlockStorage section = sections[layer]; @@ -265,7 +266,6 @@ public class ForgeQueue_All extends NMSMappedFaweQueue entry : tiles.entrySet()) { TileEntity tile = entry.getValue(); @@ -339,7 +339,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue { - public byte[][] byteIds; - public NibbleArray[] datas; + public final byte[][] byteIds; + public final NibbleArray[] datas; public ForgeChunk_All(FaweQueue parent, int x, int z) { super(parent, x, z); @@ -41,6 +41,29 @@ public class ForgeChunk_All extends CharFaweChunk { this.datas = new NibbleArray[16]; } + public ForgeChunk_All(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap, byte[][] byteIds, NibbleArray[] datas) { + super(parent, x, z, ids, count, air, relight, heightMap); + this.byteIds = byteIds; + this.datas = datas; + } + + @Override + public CharFaweChunk copy(boolean shallow) { + ForgeChunk_All copy; + if (shallow) { + copy = new ForgeChunk_All(getParent(), getX(), getZ(), ids, count, air, relight, heightMap, byteIds, datas); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new ForgeChunk_All(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone(), (byte[][]) MainUtil.copyNd(byteIds), datas.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } + return copy; + } + @Override public Chunk getNewChunk() { World world = ((ForgeQueue_All) getParent()).getWorld(); @@ -104,29 +127,6 @@ public class ForgeChunk_All extends CharFaweChunk { } } - @Override - public ForgeChunk_All copy(boolean shallow) { - ForgeChunk_All copy = new ForgeChunk_All(getParent(), getX(), getZ()); - if (shallow) { - copy.byteIds = byteIds; - copy.datas = datas; - copy.air = air; - copy.biomes = biomes; - copy.chunk = chunk; - copy.count = count; - copy.relight = relight; - } else { - copy.byteIds = (byte[][]) MainUtil.copyNd(byteIds); - copy.datas = datas.clone(); - copy.air = air.clone(); - copy.biomes = biomes.clone(); - copy.chunk = chunk; - copy.count = count.clone(); - copy.relight = relight.clone(); - } - return copy; - } - @Override public ForgeChunk_All call() { net.minecraft.world.chunk.Chunk nmsChunk = this.getChunk(); @@ -140,6 +140,9 @@ public class ForgeChunk_All extends CharFaweChunk { Map tiles = nmsChunk.chunkTileEntityMap; List[] entities = nmsChunk.entityLists; + // Set heightmap + getParent().setHeightMap(this, heightMap); + // Remove entities for (int i = 0; i < 16; i++) { int count = this.getCount(i); diff --git a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index e6184b48..220dc7c2 100644 --- a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -76,13 +76,14 @@ public class ForgeQueue_All extends NMSMappedFaweQueue otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } @@ -255,7 +256,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue tiles = (Map) tilesGeneric; Collection[] entities = (Collection[]) entitiesGeneric; CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); - char[][] idPrevious = new char[16][]; for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { ExtendedBlockStorage section = sections[layer]; @@ -315,7 +315,6 @@ public class ForgeQueue_All extends NMSMappedFaweQueue entry : tiles.entrySet()) { TileEntity tile = entry.getValue(); diff --git a/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java b/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java index 0c76e114..5eedbfab 100644 --- a/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java +++ b/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java @@ -41,6 +41,27 @@ public class ForgeChunk_All extends CharFaweChunk { super(parent, x, z); } + public ForgeChunk_All(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap) { + super(parent, x, z, ids, count, air, relight, heightMap); + } + + @Override + public CharFaweChunk copy(boolean shallow) { + ForgeChunk_All copy; + if (shallow) { + copy = new ForgeChunk_All(getParent(), getX(), getZ(), ids, count, air, relight, heightMap); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new ForgeChunk_All(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } + return copy; + } + @Override public Chunk getNewChunk() { World world = ((ForgeQueue_All) getParent()).getWorld(); @@ -60,6 +81,8 @@ public class ForgeChunk_All extends CharFaweChunk { Map tiles = nmsChunk.getTileEntityMap(); ClassInheritanceMultiMap[] entities = nmsChunk.getEntityLists(); + // Set heightmap + getParent().setHeightMap(this, heightMap); // Remove entities for (int i = 0; i < 16; i++) { diff --git a/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index 7fb00232..fb3fd43b 100644 --- a/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge189/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -73,13 +73,14 @@ public class ForgeQueue_All extends NMSMappedFaweQueue otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } @@ -198,7 +199,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue tiles = (Map) tilesGeneric; ClassInheritanceMultiMap[] entities = (ClassInheritanceMultiMap[]) entitiesGeneric; CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); - char[][] idPrevious = new char[16][]; + char[][] idPrevious = previous.getCombinedIdArrays(); for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { ExtendedBlockStorage section = sections[layer]; @@ -215,7 +216,6 @@ public class ForgeQueue_All extends NMSMappedFaweQueue entry : tiles.entrySet()) { TileEntity tile = entry.getValue(); @@ -285,7 +285,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue { super(parent, x, z); } - @Override - public Chunk getNewChunk() { - World world = ((ForgeQueue_All) getParent()).getWorld(); - return world.getChunkProvider().provideChunk(getX(), getZ()); + public ForgeChunk_All(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap) { + super(parent, x, z, ids, count, air, relight, heightMap); } @Override - public ForgeChunk_All copy(boolean shallow) { - ForgeChunk_All value = (ForgeChunk_All) super.copy(shallow); - if (sectionPalettes != null) { - value.sectionPalettes = new BlockStateContainer[16]; + public CharFaweChunk copy(boolean shallow) { + ForgeChunk_All copy; + if (shallow) { + copy = new ForgeChunk_All(getParent(), getX(), getZ(), ids, count, air, relight, heightMap); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new ForgeChunk_All(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } + if (copy != null) { + copy.sectionPalettes = new BlockStateContainer[16]; try { Field fieldBits = BlockStateContainer.class.getDeclaredField("storage"); fieldBits.setAccessible(true); @@ -99,13 +108,19 @@ public class ForgeChunk_All extends CharFaweChunk { field.set(newBits, currentValue); } fieldBits.set(paletteBlock, newBits); - value.sectionPalettes[i] = paletteBlock; + copy.sectionPalettes[i] = paletteBlock; } } catch (Throwable e) { MainUtil.handleError(e); } } - return value; + return copy; + } + + @Override + public Chunk getNewChunk() { + World world = ((ForgeQueue_All) getParent()).getWorld(); + return world.getChunkProvider().provideChunk(getX(), getZ()); } public void optimize() { @@ -147,6 +162,8 @@ public class ForgeChunk_All extends CharFaweChunk { Map tiles = nmsChunk.getTileEntityMap(); ClassInheritanceMultiMap[] entities = nmsChunk.getEntityLists(); + // Set heightmap + getParent().setHeightMap(this, heightMap); // Remove entities for (int i = 0; i < 16; i++) { diff --git a/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index d9f60377..4a5938fc 100644 --- a/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge194/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -81,13 +81,14 @@ public class ForgeQueue_All extends NMSMappedFaweQueue otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } } @@ -234,7 +235,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue tiles = (Map) tilesGeneric; ClassInheritanceMultiMap[] entities = (ClassInheritanceMultiMap[]) entitiesGeneric; CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); - char[][] idPrevious = new char[16][]; + char[][] idPrevious = previous.getCombinedIdArrays(); for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { ExtendedBlockStorage section = sections[layer]; @@ -264,7 +265,6 @@ public class ForgeQueue_All extends NMSMappedFaweQueue entry : tiles.entrySet()) { TileEntity tile = entry.getValue(); @@ -338,7 +338,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue { super(parent, x, z); } + public NukkitChunk(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, short[] relight, byte[] heightMap) { + super(parent, x, z, ids, count, air, relight, heightMap); + } + + @Override + public CharFaweChunk copy(boolean shallow) { + NukkitChunk copy; + if (shallow) { + copy = new NukkitChunk(getParent(), getX(), getZ(), ids, count, air, relight, heightMap); + copy.biomes = biomes; + copy.chunk = chunk; + } else { + copy = new NukkitChunk(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), relight.clone(), heightMap.clone()); + copy.biomes = biomes; + copy.chunk = chunk; + copy.biomes = biomes.clone(); + copy.chunk = chunk; + } + return copy; + } + @Override public BaseFullChunk getNewChunk() { - return ((NukkitQueue) getParent()).getWorld().getChunk(getX(), getZ()); + return ((NukkitQueue) getParent()).getWorld().getChunk(getX(), getZ(), true); } private int layer = -1; @@ -41,10 +63,12 @@ public class NukkitChunk extends CharFaweChunk { @Override public NukkitChunk call() { + // Set heightmap + getParent().setHeightMap(this, heightMap); NukkitQueue parent = (NukkitQueue) getParent(); Level world = ((NukkitQueue) getParent()).getWorld(); world.clearCache(true); - final BaseFullChunk chunk = (world.getChunk(getX(), getZ(), true)); + final BaseFullChunk chunk = getChunk(); char[][] sections = getCombinedIdArrays(); final int[][] biomes = getBiomeArray(); final int X = getX() << 4; diff --git a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java index 83f2937e..ab2ea81c 100644 --- a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java +++ b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java @@ -50,13 +50,14 @@ public class NukkitQueue extends NMSMappedFaweQueue otherMap[i]) { - otherMap[i] = heightMap[i]; + int value = heightMap[i] & 0xFF; + if (value > value) { + otherMap[i] = value; } } }