From bd98e98698bac3b0e80279f7a019f5109ba02088 Mon Sep 17 00:00:00 2001 From: davboecki Date: Sun, 29 Sep 2013 15:30:06 +0200 Subject: [PATCH] Update Forge implementation and added build script. Including: * Update to new MCP names * Adding of an build script (see maven 'forge' profile) * Adding of an regeneration code * Simplifying of the command registration * Added command usage description to avoid empty help pages * Added missing raw information * Used a WeakReference as world reference to avoid keeping a world in memory * Added mcmod.info * Fixed player orientation * Fixed printRaw not splitting the message correct --- .gitignore | 3 +- pom.xml | 33 ++++ src/forge/ant/build.xml | 150 ++++++++++++++++++ .../worldedit/forge/ForgeBiomeTypes.java | 10 +- .../sk89q/worldedit/forge/ForgePlayer.java | 12 +- .../worldedit/forge/ForgeServerInterface.java | 54 ++++--- .../com/sk89q/worldedit/forge/ForgeUtil.java | 4 +- .../com/sk89q/worldedit/forge/ForgeWorld.java | 126 +++++++++------ .../worldedit/forge/TileEntityBaseBlock.java | 3 +- .../worldedit/forge/WECUIPacketHandler.java | 14 +- .../sk89q/worldedit/forge/WorldEditMod.java | 39 +++-- .../forge/selections/RegionSelection.java | 16 +- src/forge/resources/mcmod.info | 23 +++ 13 files changed, 370 insertions(+), 117 deletions(-) create mode 100644 src/forge/ant/build.xml create mode 100644 src/forge/resources/mcmod.info diff --git a/.gitignore b/.gitignore index 72613be5d..bb0f21178 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ /bin /dependency-reduced-pom.xml /*.iml -/.idea \ No newline at end of file +/.idea +/forge-download diff --git a/pom.xml b/pom.xml index 10c5d9f35..805bddd15 100644 --- a/pom.xml +++ b/pom.xml @@ -304,6 +304,39 @@ + + + forge + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.7 + + + compile + + + + + + + + + + + + + run + + + + + + + + attach-docs diff --git a/src/forge/ant/build.xml b/src/forge/ant/build.xml new file mode 100644 index 000000000..5753b52ce --- /dev/null +++ b/src/forge/ant/build.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgeBiomeTypes.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeBiomeTypes.java index 435583582..35b6f95b1 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgeBiomeTypes.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeBiomeTypes.java @@ -14,7 +14,7 @@ import com.sk89q.worldedit.BiomeTypes; import com.sk89q.worldedit.UnknownBiomeTypeException; public class ForgeBiomeTypes implements BiomeTypes { - private static BiMap biomes = HashBiMap.create(); + private static BiMap biomes = HashBiMap.create(); public ForgeBiomeTypes() { all(); @@ -33,7 +33,7 @@ public class ForgeBiomeTypes implements BiomeTypes { if (biomes == null) { all(); } - Iterator it = biomes.keySet().iterator(); + Iterator it = biomes.keySet().iterator(); while (it.hasNext()) { BiomeType test = (BiomeType) it.next(); if (test.getName().equalsIgnoreCase(name)) { @@ -43,9 +43,9 @@ public class ForgeBiomeTypes implements BiomeTypes { throw new UnknownBiomeTypeException(name); } - public List all() { + public List all() { if (biomes.isEmpty()) { - biomes = HashBiMap.create(new HashMap()); + biomes = HashBiMap.create(new HashMap()); for (BiomeGenBase biome : BiomeGenBase.biomeList) { if ((biome == null) || (biomes.containsValue(biome))) { continue; @@ -53,7 +53,7 @@ public class ForgeBiomeTypes implements BiomeTypes { biomes.put(new ForgeBiomeType(biome), biome); } } - List retBiomes = new ArrayList(); + List retBiomes = new ArrayList(); retBiomes.addAll(biomes.keySet()); return retBiomes; } diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgePlayer.java b/src/forge/java/com/sk89q/worldedit/forge/ForgePlayer.java index 842cd709c..1397e5654 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgePlayer.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgePlayer.java @@ -39,11 +39,11 @@ public class ForgePlayer extends LocalPlayer { } public double getPitch() { - return this.player.cameraPitch; + return this.player.rotationPitch; } public double getYaw() { - return this.player.cameraYaw; + return this.player.rotationYaw; } public void giveItem(int type, int amt) { @@ -62,25 +62,25 @@ public class ForgePlayer extends LocalPlayer { public void printRaw(String msg) { for (String part : msg.split("\n")) { - this.player.sendChatToPlayer(ChatMessageComponent.func_111077_e(msg)); + this.player.sendChatToPlayer(ChatMessageComponent.createFromText(part)); } } public void printDebug(String msg) { for (String part : msg.split("\n")) { - this.player.sendChatToPlayer(ChatMessageComponent.func_111077_e("\u00a77" + part)); + this.player.sendChatToPlayer(ChatMessageComponent.createFromText("\u00a77" + part)); } } public void print(String msg) { for (String part : msg.split("\n")) { - this.player.sendChatToPlayer(ChatMessageComponent.func_111077_e("\u00a7d" + part)); + this.player.sendChatToPlayer(ChatMessageComponent.createFromText("\u00a7d" + part)); } } public void printError(String msg) { for (String part : msg.split("\n")) { - this.player.sendChatToPlayer(ChatMessageComponent.func_111077_e("\u00a7c" + part)); + this.player.sendChatToPlayer(ChatMessageComponent.createFromText("\u00a7c" + part)); } } diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgeServerInterface.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeServerInterface.java index 91297a66b..705899049 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgeServerInterface.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeServerInterface.java @@ -8,8 +8,10 @@ import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.command.ServerCommandManager; import net.minecraft.entity.EntityList; +import net.minecraft.item.Item; import net.minecraft.server.MinecraftServer; import net.minecraft.world.WorldServer; +import net.minecraftforge.common.DimensionManager; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.worldedit.BiomeTypes; @@ -19,17 +21,27 @@ import com.sk89q.worldedit.ServerInterface; import cpw.mods.fml.common.FMLCommonHandler; public class ForgeServerInterface extends ServerInterface { - private WorldEditMod mod; private MinecraftServer server; private ForgeBiomeTypes biomes; public ForgeServerInterface() { - this.mod = WorldEditMod.inst; this.server = FMLCommonHandler.instance().getMinecraftServerInstance(); this.biomes = new ForgeBiomeTypes(); } public int resolveItem(String name) { + if (name == null) return 0; + for (Item item : Item.itemsList) { + if (item == null) continue; + if (item.getUnlocalizedName() == null) continue; + if (item.getUnlocalizedName().startsWith("item.")) { + if (item.getUnlocalizedName().equalsIgnoreCase("item." + name)) return item.itemID; + } + if (item.getUnlocalizedName().startsWith("tile.")) { + if (item.getUnlocalizedName().equalsIgnoreCase("tile." + name)) return item.itemID; + } + if (item.getUnlocalizedName().equalsIgnoreCase(name)) return item.itemID; + } return 0; } @@ -49,8 +61,8 @@ public class ForgeServerInterface extends ServerInterface { } public List getWorlds() { - List worlds = Arrays.asList(this.server.worldServers); - List ret = new ArrayList(worlds.size()); + List worlds = Arrays.asList(DimensionManager.getWorlds()); + List ret = new ArrayList(worlds.size()); for (WorldServer world : worlds) { ret.add(new ForgeWorld(world)); } @@ -61,22 +73,26 @@ public class ForgeServerInterface extends ServerInterface { public void onCommandRegistration(List commands) { if (server == null) return; ServerCommandManager mcMan = (ServerCommandManager) server.getCommandManager(); - for (Command cmd : commands) { - for (int i = 0; i < cmd.aliases().length; i++) { - final String name = cmd.aliases()[i]; - mcMan.registerCommand(new CommandBase() { - public String getCommandName() { - return name; - } + for (final Command cmd : commands) { + mcMan.registerCommand(new CommandBase() { + @Override + public String getCommandName() { + return cmd.aliases()[0]; + } - public void processCommand(ICommandSender var1, String[] var2) { - } + @Override + public List getCommandAliases() { + return Arrays.asList(cmd.aliases()); + } - public String getCommandUsage(ICommandSender icommandsender) { - return null; - } - }); - } + @Override + public void processCommand(ICommandSender var1, String[] var2) {} + + @Override + public String getCommandUsage(ICommandSender icommandsender) { + return "/" + cmd.aliases()[0] + " " + cmd.usage(); + } + }); } } -} \ No newline at end of file +} diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgeUtil.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeUtil.java index 3b3963f8d..fad28d223 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgeUtil.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeUtil.java @@ -13,12 +13,12 @@ public class ForgeUtil { public static boolean hasPermission(EntityPlayerMP player, String perm) { // TODO fix WEPIF - return FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().areCommandsAllowed(player.username); + return FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().isPlayerOpped(player.username); } public static ItemStack toForgeItemStack(BaseItemStack item) { ItemStack ret = new ItemStack(item.getType(), item.getAmount(), item.getData()); - for (Map.Entry entry : item.getEnchantments().entrySet()) { + for (Map.Entry entry : item.getEnchantments().entrySet()) { ret.addEnchantment(net.minecraft.enchantment.Enchantment.enchantmentsList[((Integer)entry.getKey()).intValue()], ((Integer)entry.getValue()).intValue()); } diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java index 162e16356..476400b8c 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -1,6 +1,10 @@ package com.sk89q.worldedit.forge; +import java.lang.ref.WeakReference; +import java.lang.reflect.Field; import java.util.Iterator; +import java.util.List; +import java.util.Set; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityHanging; @@ -20,15 +24,18 @@ import net.minecraft.entity.passive.EntityAmbientCreature; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityTameable; import net.minecraft.entity.passive.EntityVillager; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityMobSpawner; import net.minecraft.tileentity.TileEntityNote; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.tileentity.TileEntitySkull; +import net.minecraft.util.LongHashMap; +import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.ChunkProviderServer; import com.sk89q.worldedit.BiomeType; import com.sk89q.worldedit.EditSession; @@ -47,51 +54,50 @@ import com.sk89q.worldedit.foundation.Block; import com.sk89q.worldedit.regions.Region; public class ForgeWorld extends LocalWorld { - // TODO fix world leaks (see net.minecraftforge.common.getIDs()Z;) - private World world; - + private WeakReference world; + public ForgeWorld(World world) { - this.world = world; + this.world = new WeakReference(world); } public String getName() { - return this.world.provider.getDimensionName(); + return this.world.get().provider.getDimensionName(); } public boolean setBlockType(Vector pt, int type) { - return this.world.setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type, 0, 3); + return this.world.get().setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type, 0, 3); } public boolean setBlockTypeFast(Vector pt, int type) { - return this.world.setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type); + return this.world.get().setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type); } public boolean setTypeIdAndData(Vector pt, int type, int data) { - return this.world.setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type, data, 3); + return this.world.get().setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type, data, 3); } public boolean setTypeIdAndDataFast(Vector pt, int type, int data) { - return this.world.setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type, data, 3); + return this.world.get().setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), type, data, 3); } public int getBlockType(Vector pt) { - return this.world.getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + return this.world.get().getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); } public void setBlockData(Vector pt, int data) { - this.world.setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), data, 0, 3); + this.world.get().setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), data, 0, 3); } public void setBlockDataFast(Vector pt, int data) { - this.world.setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), data, 0, 3); + this.world.get().setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), data, 0, 3); } public int getBlockData(Vector pt) { - return this.world.getBlockMetadata(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + return this.world.get().getBlockMetadata(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); } public int getBlockLightLevel(Vector pt) { - return this.world.getBlockLightValue(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + return this.world.get().getBlockLightValue(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); } public boolean isValidBlockType(int id) { @@ -99,12 +105,12 @@ public class ForgeWorld extends LocalWorld { } public BiomeType getBiome(Vector2D pt) { - return ForgeBiomeTypes.getFromBaseBiome(this.world.getBiomeGenForCoords(pt.getBlockX(), pt.getBlockZ())); + return ForgeBiomeTypes.getFromBaseBiome(this.world.get().getBiomeGenForCoords(pt.getBlockX(), pt.getBlockZ())); } public void setBiome(Vector2D pt, BiomeType biome) { - if (this.world.getChunkProvider().chunkExists(pt.getBlockX(), pt.getBlockZ())) { - Chunk chunk = this.world.getChunkFromBlockCoords(pt.getBlockX(), pt.getBlockZ()); + if (this.world.get().getChunkProvider().chunkExists(pt.getBlockX(), pt.getBlockZ())) { + Chunk chunk = this.world.get().getChunkFromBlockCoords(pt.getBlockX(), pt.getBlockZ()); if ((chunk != null) && (chunk.isChunkLoaded)) { byte[] biomevals = chunk.getBiomeArray(); biomevals[((pt.getBlockZ() & 0xF) << 4 | pt.getBlockX() & 0xF)] = (byte) ForgeBiomeTypes.getFromBiomeType(biome).biomeID; @@ -113,8 +119,6 @@ public class ForgeWorld extends LocalWorld { } public boolean regenerate(Region region, EditSession editSession) { - // TODO fix this - /* BaseBlock[] history = new BaseBlock[256 * (getMaxY() + 1)]; for (Vector2D chunk : region.getChunks()) { @@ -131,31 +135,60 @@ public class ForgeWorld extends LocalWorld { } try { Set chunks = region.getChunks(); - IChunkProvider provider = this.world.getChunkProvider(); + IChunkProvider provider = this.world.get().getChunkProvider(); if (!(provider instanceof ChunkProviderServer)) { return false; } ChunkProviderServer chunkServer = (ChunkProviderServer) provider; - Field u = ChunkProviderServer.class.getDeclaredField("b"); // chunksToUnload + Field u = null; + 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 = ChunkProviderServer.class.getDeclaredField("f"); // loadedChunkHashMap + Set unloadQueue = (Set) u.get(chunkServer); + Field m = null; + 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 p = ChunkProviderServer.class.getDeclaredField("d"); // currentChunkProvider + Field lc = null; + try { + lc = ChunkProviderServer.class.getDeclaredField("field_73245_g"); // loadedChunkHashMap + } catch(NoSuchFieldException e) { + lc = ChunkProviderServer.class.getDeclaredField("loadedChunks"); + } + lc.setAccessible(true); + List loaded = (List) lc.get(chunkServer); + Field p = null; + 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); for (Vector2D coord : chunks) { + long pos = ChunkCoordIntPair.chunkXZ2Int(coord.getBlockX(), coord.getBlockZ()); Chunk mcChunk = null; if (chunkServer.chunkExists(coord.getBlockX(), coord.getBlockZ())) { mcChunk = chunkServer.loadChunk(coord.getBlockX(), coord.getBlockZ()); mcChunk.onChunkUnload(); } - unloadQueue.remove(Long.valueOf((coord.getBlockX() << 32) + coord.getBlockZ() - -2147483648L)); - loadedMap.remove(((long) coord.getBlockX() << 32) + coord.getBlockZ() - Integer.MIN_VALUE); - + unloadQueue.remove(pos); + loadedMap.remove(pos); mcChunk = chunkProvider.provideChunk(coord.getBlockX(), coord.getBlockZ()); + loadedMap.add(pos, mcChunk); + loaded.add(mcChunk); + if (mcChunk != null) { + mcChunk.onChunkLoad(); + } + mcChunk.populateChunk(chunkProvider, chunkProvider, coord.getBlockX(), coord.getBlockZ()); } } catch (Throwable t) { t.printStackTrace(); @@ -178,7 +211,6 @@ public class ForgeWorld extends LocalWorld { } } - */ return false; } @@ -187,21 +219,21 @@ public class ForgeWorld extends LocalWorld { return false; } - boolean successful = this.world.setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), block.getId()); + boolean successful = this.world.get().setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), block.getId()); if (successful) { if (block instanceof TileEntityBlock) { copyToWorld(pt, (BaseBlock) block); } } - this.world.setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), block.getId(), block.getData(), 3); + this.world.get().setBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), block.getId(), block.getData(), 3); return successful; } public BaseBlock getBlock(Vector pt) { int type = getBlockType(pt); int data = getBlockData(pt); - TileEntity tile = this.world.getBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + TileEntity tile = this.world.get().getBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (tile != null) { TileEntityBaseBlock block = new TileEntityBaseBlock(type, data, tile); copyFromWorld(pt, block); @@ -223,25 +255,23 @@ public class ForgeWorld extends LocalWorld { // Signs TileEntitySign sign = new TileEntitySign(); sign.signText = ((SignBlock) block).getText(); - world.setBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), sign); + world.get().setBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), sign); return true; } - /* if (block instanceof MobSpawnerBlock) { // Mob spawners TileEntityMobSpawner spawner = new TileEntityMobSpawner(); spawner.getSpawnerLogic().setMobID(((MobSpawnerBlock) block).getMobType()); - world.setBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), spawner); + world.get().setBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), spawner); return true; } - */ if (block instanceof NoteBlock) { // Note block TileEntityNote note = new TileEntityNote(); note.note = ((NoteBlock) block).getNote(); - world.setBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), note); + world.get().setBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), note); return true; } @@ -250,12 +280,12 @@ public class ForgeWorld extends LocalWorld { TileEntitySkull skull = new TileEntitySkull(); skull.setSkullType(((SkullBlock) block).getSkullType(), ((SkullBlock) block).getOwner()); skull.setSkullRotation(((SkullBlock) block).getRot()); - world.setBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), skull); + world.get().setBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), skull); return true; } if (block instanceof TileEntityBaseBlock) { - TileEntityBaseBlock.set(this.world, pt, (TileEntityBaseBlock) block, hardcopy); + TileEntityBaseBlock.set(this.world.get(), pt, (TileEntityBaseBlock) block, hardcopy); return true; } return false; @@ -265,12 +295,12 @@ public class ForgeWorld extends LocalWorld { if (!(block instanceof TileEntityBaseBlock)) { return false; } - ((TileEntityBaseBlock) block).setTile(this.world.getBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ())); + ((TileEntityBaseBlock) block).setTile(this.world.get().getBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ())); return true; } public boolean clearContainerBlockContents(Vector pt) { - TileEntity tile = this.world.getBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + TileEntity tile = this.world.get().getBlockTileEntity(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if ((tile instanceof IInventory)) { IInventory inv = (IInventory) tile; int size = inv.getSizeInventory(); @@ -286,16 +316,16 @@ public class ForgeWorld extends LocalWorld { if ((item == null) || (item.getType() == 0)) { return; } - EntityItem entity = new EntityItem(this.world, pt.getX(), pt.getY(), pt.getZ(), ForgeUtil.toForgeItemStack(item)); + EntityItem entity = new EntityItem(this.world.get(), pt.getX(), pt.getY(), pt.getZ(), ForgeUtil.toForgeItemStack(item)); entity.delayBeforeCanPickup = 10; - this.world.spawnEntityInWorld(entity); + this.world.get().spawnEntityInWorld(entity); } public int removeEntities(EntityType type, Vector origin, int radius) { int num = 0; double radiusSq = Math.pow(radius, 2.0D); - for (Iterator it = this.world.loadedEntityList.iterator(); it.hasNext();) { + for (Iterator it = this.world.get().loadedEntityList.iterator(); it.hasNext();) { Entity ent = it.next(); if ((radius != -1) && (origin.distanceSq(new Vector(ent.posX, ent.posY, ent.posZ)) > radiusSq)) { continue; @@ -366,7 +396,7 @@ public class ForgeWorld extends LocalWorld { int num = 0; double radiusSq = radius * radius; - for (Iterator it = this.world.loadedEntityList.iterator(); it.hasNext();) { + for (Iterator it = this.world.get().loadedEntityList.iterator(); it.hasNext();) { Entity obj = it.next(); if (!(obj instanceof EntityLiving)) { continue; @@ -404,17 +434,17 @@ public class ForgeWorld extends LocalWorld { } public World getWorld() { - return world; + return world.get(); } public boolean equals(Object other) { if ((other instanceof ForgeWorld)) { - return ((ForgeWorld) other).world.equals(this.world); + return ((ForgeWorld) other).world.get().equals(this.world.get()); } return false; } public int hashCode() { - return this.world.hashCode(); + return this.world.get().hashCode(); } } \ No newline at end of file diff --git a/src/forge/java/com/sk89q/worldedit/forge/TileEntityBaseBlock.java b/src/forge/java/com/sk89q/worldedit/forge/TileEntityBaseBlock.java index e310514fe..c8515dbd4 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/TileEntityBaseBlock.java +++ b/src/forge/java/com/sk89q/worldedit/forge/TileEntityBaseBlock.java @@ -59,7 +59,7 @@ public class TileEntityBaseBlock extends BaseBlock implements TileEntityBlock { private static TileEntity constructTEClass(World world, Vector pt, TileEntityBaseBlock block) { Class clazz = block.tile.getClass(); - Constructor baseConstructor; + Constructor baseConstructor; try { baseConstructor = clazz.getConstructor(); // creates "blank" TE } catch (Throwable e) { @@ -84,7 +84,6 @@ public class TileEntityBaseBlock extends BaseBlock implements TileEntityBlock { } public String getNbtId() { - String id = null; NBTTagCompound tag = new NBTTagCompound(); try { this.tile.writeToNBT(tag); diff --git a/src/forge/java/com/sk89q/worldedit/forge/WECUIPacketHandler.java b/src/forge/java/com/sk89q/worldedit/forge/WECUIPacketHandler.java index f707bf9af..db8fa1e27 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/WECUIPacketHandler.java +++ b/src/forge/java/com/sk89q/worldedit/forge/WECUIPacketHandler.java @@ -15,13 +15,15 @@ public class WECUIPacketHandler implements IPacketHandler { public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8"); public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { - LocalSession session = WorldEditMod.inst.getSession((EntityPlayerMP) player); + if (player instanceof EntityPlayerMP) { + LocalSession session = WorldEditMod.inst.getSession((EntityPlayerMP) player); - if (session.hasCUISupport()) { - return; + if (session.hasCUISupport()) { + return; + } + + String text = new String(packet.data, UTF_8_CHARSET); + session.handleCUIInitializationMessage(text); } - - String text = new String(packet.data, UTF_8_CHARSET); - session.handleCUIInitializationMessage(text); } } \ No newline at end of file diff --git a/src/forge/java/com/sk89q/worldedit/forge/WorldEditMod.java b/src/forge/java/com/sk89q/worldedit/forge/WorldEditMod.java index e6cbbd09d..a160ee38a 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/WorldEditMod.java +++ b/src/forge/java/com/sk89q/worldedit/forge/WorldEditMod.java @@ -18,23 +18,21 @@ import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.ServerInterface; import com.sk89q.worldedit.WorldEdit; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Mod; -import cpw.mods.fml.common.Mod.ServerStarting; -import cpw.mods.fml.common.Mod.ServerStopping; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; -import cpw.mods.fml.common.event.FMLServerStoppingEvent; -import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.common.network.NetworkMod; -@Mod(modid = "WorldEdit", name = "WorldEdit", version = "5.5.2-forge-alpha1") +@Mod(modid = "WorldEdit", name = "WorldEdit", version = "%VERSION%") +@NetworkMod(channels="WECUI", packetHandler=WECUIPacketHandler.class) public class WorldEditMod { - @Mod.Instance("WorldEdit") + @Instance("WorldEdit") public static WorldEditMod inst; protected static Logger logger; @@ -44,11 +42,11 @@ public class WorldEditMod { private ForgeConfiguration config; private File workingDir; - @Mod.PreInit + @EventHandler public void preInit(FMLPreInitializationEvent event) { - logger = Logger.getLogger(((Mod) getClass().getAnnotation(Mod.class)).modid()); + logger = Logger.getLogger(getClass().getAnnotation(Mod.class).modid()); logger.setParent(FMLLog.getLogger()); - String modVersion = ((Mod) WorldEditMod.class.getAnnotation(Mod.class)).version(); + String modVersion = WorldEditMod.class.getAnnotation(Mod.class).version(); String manifestVersion = WorldEdit.getVersion(); if (!manifestVersion.equalsIgnoreCase(modVersion)) { WorldEdit.setVersion(manifestVersion + " (" + modVersion + ")"); @@ -63,23 +61,17 @@ public class WorldEditMod { // PermissionsResolverManager.initialize(this, this.workingDir); } - @Mod.Init + @EventHandler public void init(FMLInitializationEvent event) { - if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { - NetworkRegistry.instance().registerChannel(new WECUIPacketHandler(), "WECUI"); - } /* else { - WE CUI stuff here? - } */ - MinecraftForge.EVENT_BUS.register(new WorldEditForgeListener()); } - @Mod.PostInit + @EventHandler public void postInit(FMLPostInitializationEvent event) { logger.info("WorldEdit " + WorldEdit.getVersion() + " Loaded"); } - @ServerStarting + @EventHandler public void serverStarting(FMLServerStartingEvent event) { this.server = new ForgeServerInterface(); this.controller = new WorldEdit(this.server, this.config); @@ -121,14 +113,19 @@ public class WorldEditMod { File actual = new File(getWorkingDir(), name); if (!actual.exists()) { InputStream input = null; + JarFile file = null; try { - JarFile file = new JarFile(jar); + file = new JarFile(jar); ZipEntry copy = file.getEntry("defaults/" + name); if (copy == null) throw new FileNotFoundException(); input = file.getInputStream(copy); } catch (IOException e) { logger.severe("Unable to read default configuration: " + name); + } finally { + try { + file.close(); + } catch (Exception e) {} } if (input != null) { FileOutputStream output = null; diff --git a/src/forge/java/com/sk89q/worldedit/forge/selections/RegionSelection.java b/src/forge/java/com/sk89q/worldedit/forge/selections/RegionSelection.java index 7b923a781..b04fb416c 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/selections/RegionSelection.java +++ b/src/forge/java/com/sk89q/worldedit/forge/selections/RegionSelection.java @@ -1,5 +1,7 @@ package com.sk89q.worldedit.forge.selections; +import java.lang.ref.WeakReference; + import net.minecraft.world.World; import com.sk89q.worldedit.Location; @@ -9,16 +11,16 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; public abstract class RegionSelection implements Selection { - private World world; + private WeakReference world; private RegionSelector selector; private Region region; public RegionSelection(World world) { - this.world = world; + this.world = new WeakReference(world); } public RegionSelection(World world, RegionSelector selector, Region region) { - this.world = world; + this(world); this.region = region; this.selector = selector; } @@ -40,7 +42,7 @@ public abstract class RegionSelection implements Selection { } public Location getMinimumPoint() { - return new Location(WorldEditMod.inst.getWorld(this.world), this.region.getMinimumPoint()); + return new Location(WorldEditMod.inst.getWorld(this.world.get()), this.region.getMinimumPoint()); } public Vector getNativeMinimumPoint() { @@ -48,7 +50,7 @@ public abstract class RegionSelection implements Selection { } public Location getMaximumPoint() { - return new Location(WorldEditMod.inst.getWorld(this.world), this.region.getMaximumPoint()); + return new Location(WorldEditMod.inst.getWorld(this.world.get()), this.region.getMaximumPoint()); } public Vector getNativeMaximumPoint() { @@ -56,7 +58,7 @@ public abstract class RegionSelection implements Selection { } public World getWorld() { - return this.world; + return this.world.get(); } public int getArea() { @@ -76,7 +78,7 @@ public abstract class RegionSelection implements Selection { } public boolean contains(Location pt) { - if (!pt.getWorld().equals(this.world)) { + if (!pt.getWorld().equals(this.world.get())) { return false; } diff --git a/src/forge/resources/mcmod.info b/src/forge/resources/mcmod.info new file mode 100644 index 000000000..96797d0af --- /dev/null +++ b/src/forge/resources/mcmod.info @@ -0,0 +1,23 @@ +{ + "modinfoversion": 2, + "modlist": [{ + "modid": "WorldEdit", + "name": "WorldEdit", + "description": "WorldEdit is an easy-to-use in-game world editor for Minecraft, supporting both single player and multiplayer.", + "version": "%VERSION%", + "mcversion": "%MCVERSION%", + "url": "http://wiki.sk89q.com/wiki/WorldEdit", + "updateUrl": "", + "authors": [ "sk89q" ], + "credits": "", + "logoFile": "", + "screenshots": [], + "requiredMods": [ + "Forge@[9.10.1.850,)" + ], + "dependencies": [ + "Forge@[9.10.1.850,)" + ], + "dependants": [] + }] +}