From ea4dafe9af5a4e3d6705c1f1235660078de47cb5 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Tue, 12 Jan 2016 02:03:02 -0800 Subject: [PATCH] Use ATs for accessing fields. --- worldedit-forge/build.gradle | 3 +- .../com/sk89q/worldedit/forge/ForgeWorld.java | 60 ++++--------------- .../main/resources/META-INF/worldedit_at.cfg | 4 ++ 3 files changed, 19 insertions(+), 48 deletions(-) create mode 100644 worldedit-forge/src/main/resources/META-INF/worldedit_at.cfg diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index f95b9d4fb..dd5d5c9bd 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -55,7 +55,8 @@ processResources { jar { manifest { attributes("Class-Path": "truezip.jar WorldEdit/truezip.jar js.jar WorldEdit/js.jar", - "WorldEdit-Version": version) + "WorldEdit-Version": version, + "FMLAT": "worldedit_at.cfg") } } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index 6b3f5e655..73eea7866 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -40,6 +40,14 @@ import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.registry.WorldData; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.Nullable; import net.minecraft.block.Block; import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockOldLeaf; @@ -56,7 +64,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.ClassInheritanceMultiMap; -import net.minecraft.util.LongHashMap; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -77,16 +84,6 @@ import net.minecraft.world.gen.feature.WorldGenTaiga2; import net.minecraft.world.gen.feature.WorldGenTrees; import net.minecraft.world.gen.feature.WorldGenerator; -import javax.annotation.Nullable; - -import java.lang.ref.WeakReference; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; import static com.google.common.base.Preconditions.checkNotNull; @@ -276,38 +273,7 @@ public class ForgeWorld extends AbstractWorld { return false; } ChunkProviderServer chunkServer = (ChunkProviderServer) provider; - Field u; - try { - u = ChunkProviderServer.class.getDeclaredField("field_73248_b"); // chunksToUnload - } catch(NoSuchFieldException e) { - u = ChunkProviderServer.class.getDeclaredField("chunksToUnload"); - } - u.setAccessible(true); - Set unloadQueue = (Set) u.get(chunkServer); - Field m; - try { - m = ChunkProviderServer.class.getDeclaredField("field_73244_f"); // loadedChunkHashMap - } catch(NoSuchFieldException e) { - m = ChunkProviderServer.class.getDeclaredField("loadedChunkHashMap"); - } - m.setAccessible(true); - LongHashMap loadedMap = (LongHashMap) m.get(chunkServer); - Field lc; - try { - lc = ChunkProviderServer.class.getDeclaredField("field_73245_g"); // loadedChunkHashMap - } catch(NoSuchFieldException e) { - lc = ChunkProviderServer.class.getDeclaredField("loadedChunks"); - } - lc.setAccessible(true); - @SuppressWarnings("unchecked") List loaded = (List) lc.get(chunkServer); - Field p; - try { - p = ChunkProviderServer.class.getDeclaredField("field_73246_d"); // currentChunkProvider - } catch(NoSuchFieldException e) { - p = ChunkProviderServer.class.getDeclaredField("currentChunkProvider"); - } - p.setAccessible(true); - IChunkProvider chunkProvider = (IChunkProvider) p.get(chunkServer); + IChunkProvider chunkProvider = chunkServer.serverChunkGenerator; for (Vector2D coord : chunks) { long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ()); @@ -316,11 +282,11 @@ public class ForgeWorld extends AbstractWorld { mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ()); mcChunk.onChunkUnload(); } - unloadQueue.remove(pos); - loadedMap.remove(pos); + chunkServer.droppedChunksSet.remove(pos); + chunkServer.id2ChunkMap.remove(pos); mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ()); - loadedMap.add(pos, mcChunk); - loaded.add(mcChunk); + chunkServer.id2ChunkMap.add(pos, mcChunk); + chunkServer.loadedChunks.add(mcChunk); if (mcChunk != null) { mcChunk.onChunkLoad(); mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ()); diff --git a/worldedit-forge/src/main/resources/META-INF/worldedit_at.cfg b/worldedit-forge/src/main/resources/META-INF/worldedit_at.cfg new file mode 100644 index 000000000..33f039ce3 --- /dev/null +++ b/worldedit-forge/src/main/resources/META-INF/worldedit_at.cfg @@ -0,0 +1,4 @@ +public net.minecraft.world.gen.ChunkProviderServer field_73248_b # droppedChunksSet +public net.minecraft.world.gen.ChunkProviderServer field_73244_f # id2ChunkMap +public net.minecraft.world.gen.ChunkProviderServer field_73245_g # loadedChunks +public net.minecraft.world.gen.ChunkProviderServer field_73246_d # serverChunkGenerator