From 91450e569b781ad03d28d4d79fc755527354f3eb Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 13 Mar 2017 18:55:33 +1100 Subject: [PATCH] Fixes for thermos --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 9 ++++ .../com/boydti/fawe/object/FawePlayer.java | 12 ++++- .../java/com/sk89q/worldedit/EditSession.java | 4 +- .../fawe/forge/v1710/ForgeChunk_All.java | 45 +++++++++++++++++-- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index 10e3cfb6..8160468f 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -29,6 +29,7 @@ import com.sk89q.worldedit.world.World; import java.io.File; import java.io.FileOutputStream; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.URL; import java.nio.channels.Channels; @@ -150,6 +151,14 @@ public class FaweBukkit implements IFawe, Listener { Player player = (Player) obj; FawePlayer existing = Fawe.get().getCachedPlayer(player.getName()); return existing != null ? existing : new BukkitPlayer(player); + } else if (obj != null && obj.getClass().getName().contains("EntityPlayer")) { + try { + Method method = obj.getClass().getDeclaredMethod("getBukkitEntity"); + return wrap(method.invoke(obj)); + } catch (Throwable e) { + e.printStackTrace(); + return null; + } } else { return null; } diff --git a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java index fee69f1e..e5ae1fd7 100644 --- a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -31,6 +31,7 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.registry.WorldData; import java.io.File; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -54,7 +55,7 @@ public abstract class FawePlayer extends Metadatable { * @param * @return */ - public static FawePlayer wrap(final Object obj) { + public static FawePlayer wrap(Object obj) { if (obj == null) { return FakePlayer.getConsole().toFawePlayer(); } @@ -93,6 +94,15 @@ public abstract class FawePlayer extends Metadatable { FakePlayer fake = new FakePlayer(actor.getName(), actor.getUniqueId(), actor); return fake.toFawePlayer(); } + if (obj != null && obj.getClass().getName().contains("CraftPlayer") && !Fawe.imp().getPlatform().equals("bukkit")) { + try { + Method methodGetHandle = obj.getClass().getDeclaredMethod("getHandle"); + obj = methodGetHandle.invoke(obj); + } catch (Throwable e) { + e.printStackTrace(); + return null; + } + } return Fawe.imp().wrap(obj); } diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index 4e7587f1..33ad67e3 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -1334,9 +1334,9 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting Operations.completeBlindly(visitor); return visitor.getAffected(); } - final boolean[] ids = new boolean[256]; + final boolean[] ids = new boolean[4096]; for (final int id : searchIDs) { - if ((id < 256) && (id >= 0)) { + if ((id < 4096) && (id >= 0)) { ids[id] = true; } } diff --git a/forge1710/src/main/java/com/boydti/fawe/forge/v1710/ForgeChunk_All.java b/forge1710/src/main/java/com/boydti/fawe/forge/v1710/ForgeChunk_All.java index d0bdc081..cf7564b4 100644 --- a/forge1710/src/main/java/com/boydti/fawe/forge/v1710/ForgeChunk_All.java +++ b/forge1710/src/main/java/com/boydti/fawe/forge/v1710/ForgeChunk_All.java @@ -32,29 +32,32 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage; public class ForgeChunk_All extends CharFaweChunk { public final byte[][] byteIds; + public final NibbleArray[] extended; public final NibbleArray[] datas; public ForgeChunk_All(FaweQueue parent, int x, int z) { super(parent, x, z); this.byteIds = new byte[16][]; + this.extended = new NibbleArray[16]; this.datas = new NibbleArray[16]; } - public ForgeChunk_All(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, byte[] heightMap, byte[][] byteIds, NibbleArray[] datas) { + public ForgeChunk_All(FaweQueue parent, int x, int z, char[][] ids, short[] count, short[] air, byte[] heightMap, byte[][] byteIds, NibbleArray[] datas, NibbleArray[] extended) { super(parent, x, z, ids, count, air, heightMap); this.byteIds = byteIds; this.datas = datas; + this.extended = extended; } @Override public CharFaweChunk copy(boolean shallow) { ForgeChunk_All copy; if (shallow) { - copy = new ForgeChunk_All(getParent(), getX(), getZ(), ids, count, air, heightMap, byteIds, datas); + copy = new ForgeChunk_All(getParent(), getX(), getZ(), ids, count, air, heightMap, byteIds, datas, extended); copy.biomes = biomes; copy.chunk = chunk; } else { - copy = new ForgeChunk_All(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), heightMap.clone(), (byte[][]) MainUtil.copyNd(byteIds), datas.clone()); + copy = new ForgeChunk_All(getParent(), getX(), getZ(), (char[][]) MainUtil.copyNd(ids), count.clone(), air.clone(), heightMap.clone(), (byte[][]) MainUtil.copyNd(byteIds), datas.clone(), extended.clone()); copy.biomes = biomes; copy.chunk = chunk; copy.biomes = biomes.clone(); @@ -77,6 +80,10 @@ public class ForgeChunk_All extends CharFaweChunk { return datas[i]; } + public NibbleArray getExtendedIdArray(int i) { + return extended[i]; + } + @Override public void setBlock(int x, int y, int z, int id, int data) { int i = FaweCache.CACHE_I[y][z][x]; @@ -122,6 +129,13 @@ public class ForgeChunk_All extends CharFaweChunk { } dataArray.set(x, y & 15, z, data); } + if (id > 255) { + NibbleArray nibble = extended[i]; + if (extended == null) { + extended[i] = nibble = new NibbleArray(4096, 4); + } + nibble.set(x, y & 15, z, id >> 8); + } return; } } @@ -243,6 +257,7 @@ public class ForgeChunk_All extends CharFaweChunk { } int countAir = this.getAir(j); NibbleArray newDataArray = this.getDataArray(j); + NibbleArray extendedArray = this.getExtendedIdArray(j); ExtendedBlockStorage section = sections[j]; if ((section == null)) { if (count == countAir) { @@ -253,6 +268,9 @@ public class ForgeChunk_All extends CharFaweChunk { if (newDataArray != null) { section.setBlockMetadataArray(newDataArray); } + if (extendedArray != null) { + section.setBlockMSBArray(extendedArray); + } continue; } else if (count >= 4096) { if (count == countAir) { @@ -262,6 +280,12 @@ public class ForgeChunk_All extends CharFaweChunk { section.setBlockLSBArray(newIdArray); if (newDataArray != null) { section.setBlockMetadataArray(newDataArray); + } else { + NibbleArray nibble = section.getMetadataArray(); + Arrays.fill(nibble.data, (byte) 0); + } + if (extendedArray != null) { + section.setBlockMSBArray(extendedArray); } else { NibbleArray nibble = section.getBlockMSBArray(); Arrays.fill(nibble.data, (byte) 0); @@ -270,10 +294,15 @@ public class ForgeChunk_All extends CharFaweChunk { } byte[] currentIdArray = section.getBlockLSBArray(); NibbleArray currentDataArray = section.getMetadataArray(); + NibbleArray currentExtraArray = section.getBlockMSBArray(); boolean data = currentDataArray != null && newDataArray != null; if (currentDataArray == null && newDataArray != null) { section.setBlockMetadataArray(newDataArray); } + boolean extra = currentExtraArray != null && extendedArray != null; + if (currentExtraArray == null && extendedArray != null) { + section.setBlockMSBArray(extendedArray); + } int solid = 0; char[] charArray = this.getIdArray(j); for (int k = 0; k < newIdArray.length; k++) { @@ -298,6 +327,16 @@ public class ForgeChunk_All extends CharFaweChunk { int newData = newDataArray.get(x, y, z); currentDataArray.set(x, y, z, newData); } + if (extra) { + int extraId = FaweCache.getId(combined) >> 8; + if (extraId != 0) { + int x = FaweCache.CACHE_X[0][k]; + int y = FaweCache.CACHE_Y[0][k]; + int z = FaweCache.CACHE_Z[0][k]; + int newExtra = extendedArray.get(x, y, z); + currentExtraArray.set(x, y, z, newExtra); + } + } continue; } }