From 6757b04d24f8920d863b0685aa76310ece3a1dc3 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 7 Feb 2016 10:14:33 -0800 Subject: [PATCH 1/4] Add FMP as a dependency at compile --- worldedit-forge/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 6c4e6c3a4..015e0f88d 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -15,7 +15,8 @@ apply plugin: 'forge' dependencies { compile project(':worldedit-core') - testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1' + compile group: 'codechicken', name: 'ForgeMultipart', version: '1.2.0.345', classifier: 'dev' + testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.0-rc1' } minecraft { From 10776f27a8c7b4840c7b02b51d5947131a693b27 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 7 Feb 2016 10:42:13 -0800 Subject: [PATCH 2/4] Fix dependency --- worldedit-forge/build.gradle | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 015e0f88d..a5857ecb8 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -13,9 +13,16 @@ buildscript { apply plugin: 'forge' +repositories { + maven { + name 'forge' + url 'http://files.minecraftforge.net/maven/' + } +} + dependencies { compile project(':worldedit-core') - compile group: 'codechicken', name: 'ForgeMultipart', version: '1.2.0.345', classifier: 'dev' + compile group: 'codechicken', name: 'ForgeMultipart', version: '1.7.10-1.2.0.345', classifier: 'dev' testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.0-rc1' } From 7271cca89ff5ff0621dcf4ef8d4e0ac7383045ea Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 7 Feb 2016 14:07:41 -0800 Subject: [PATCH 3/4] Implement FMP compatibility --- .../sk89q/worldedit/forge/ForgeWorldEdit.java | 13 ++++++++ .../worldedit/forge/TileEntityUtils.java | 24 +++++++++++--- .../forge/compat/ForgeMultipartCompat.java | 15 +++++++++ .../compat/ForgeMultipartExistsCompat.java | 33 +++++++++++++++++++ .../forge/compat/NoForgeMultipartCompat.java | 19 +++++++++++ worldedit-forge/src/main/resources/mcmod.info | 3 +- 6 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java create mode 100644 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java create mode 100644 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java index 7284796e6..989865815 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java @@ -26,8 +26,12 @@ import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.forge.compat.ForgeMultipartCompat; +import com.sk89q.worldedit.forge.compat.ForgeMultipartExistsCompat; +import com.sk89q.worldedit.forge.compat.NoForgeMultipartCompat; import com.sk89q.worldedit.internal.LocalWorldAdapter; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; @@ -76,6 +80,7 @@ public class ForgeWorldEdit { private ForgePlatform platform; private ForgeConfiguration config; private File workingDir; + private ForgeMultipartCompat compat = new NoForgeMultipartCompat(); @EventHandler public void preInit(FMLPreInitializationEvent event) { @@ -87,6 +92,10 @@ public class ForgeWorldEdit { config = new ForgeConfiguration(this); config.load(); + if (Loader.isModLoaded("ForgeMultipart")) { + compat = new ForgeMultipartExistsCompat(); + } + FMLCommonHandler.instance().bus().register(ThreadSafeCache.getInstance()); } @@ -260,6 +269,10 @@ public class ForgeWorldEdit { return this.workingDir; } + public ForgeMultipartCompat getFMPCompat() { + return compat; + } + /** * Get the version of the WorldEdit-for-Forge implementation. * diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java index fd8d6e5fe..b3706f349 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java @@ -81,9 +81,10 @@ final class TileEntityUtils { tileEntity.readFromNBT(tag); } - world.setTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ(), tileEntity); - } + tileEntity = ForgeWorldEdit.inst.getFMPCompat().overrideTileEntity(world, tag, tileEntity); + setTileEntity(world, position, tileEntity); + } /** * Set a tile entity at the given location using the tile entity ID from * the tag. @@ -95,12 +96,26 @@ final class TileEntityUtils { static void setTileEntity(World world, Vector position, @Nullable NBTTagCompound tag) { if (tag != null) { updateForSet(tag, position); - TileEntity tileEntity = TileEntity.createAndLoadEntity(tag); + TileEntity tileEntity = makeTileEntity(world, position, tag); if (tileEntity != null) { - world.setTileEntity(position.getBlockX(), position.getBlockY(), position.getBlockZ(), tileEntity); + setTileEntity(world, position, tileEntity); } } } + + private static TileEntity makeTileEntity(World world, Vector position, + NBTTagCompound tag) { + TileEntity normal = TileEntity.createAndLoadEntity(tag); + return ForgeWorldEdit.inst.getFMPCompat().overrideTileEntity(world, tag, + normal); + } + + private static void setTileEntity(World world, Vector position, + TileEntity tileEntity) { + world.setTileEntity(position.getBlockX(), position.getBlockY(), + position.getBlockZ(), tileEntity); + ForgeWorldEdit.inst.getFMPCompat().sendDescPacket(world, tileEntity); + } /** * Construct a tile entity from the given class. @@ -139,5 +154,4 @@ final class TileEntityUtils { return genericTE; } - } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java new file mode 100644 index 000000000..a9e8bd0de --- /dev/null +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java @@ -0,0 +1,15 @@ +package com.sk89q.worldedit.forge.compat; + +import javax.annotation.Nullable; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public interface ForgeMultipartCompat { + + TileEntity overrideTileEntity(World world, @Nullable NBTTagCompound tag, + TileEntity normal); + + void sendDescPacket(World world, TileEntity entity); + +} diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java new file mode 100644 index 000000000..1f5c82f30 --- /dev/null +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java @@ -0,0 +1,33 @@ +package com.sk89q.worldedit.forge.compat; + +import codechicken.multipart.MultipartHelper; +import codechicken.multipart.TileMultipart; +import javax.annotation.Nullable; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class ForgeMultipartExistsCompat implements ForgeMultipartCompat { + + @Override + public TileEntity overrideTileEntity(World world, + @Nullable NBTTagCompound tag, TileEntity normal) { + if (tag == null) { + return normal; + } + TileEntity tile = MultipartHelper.createTileFromNBT(world, tag); + if (tile == null) { + return normal; + } + return tile; + } + + @Override + public void sendDescPacket(World world, TileEntity entity) { + if (entity instanceof TileMultipart) { + TileMultipart multi = (TileMultipart) entity; + MultipartHelper.sendDescPacket(world, multi); + } + } + +} diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java new file mode 100644 index 000000000..229a9ba40 --- /dev/null +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java @@ -0,0 +1,19 @@ +package com.sk89q.worldedit.forge.compat; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class NoForgeMultipartCompat implements ForgeMultipartCompat { + + @Override + public TileEntity overrideTileEntity(World world, NBTTagCompound tag, + TileEntity normal) { + return normal; + } + + @Override + public void sendDescPacket(World world, TileEntity entity) { + } + +} diff --git a/worldedit-forge/src/main/resources/mcmod.info b/worldedit-forge/src/main/resources/mcmod.info index df47ddfac..f3f2f5b98 100644 --- a/worldedit-forge/src/main/resources/mcmod.info +++ b/worldedit-forge/src/main/resources/mcmod.info @@ -14,7 +14,8 @@ "Forge@[${forgeVersion},)" ], "dependencies": [ - "Forge@[${forgeVersion},)" + "Forge@[${forgeVersion},)", + "ForgeMultipart" ], "dependants": [] }] From 4088f26d198ba48ed4fbdfd63748bf45455a01dc Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 7 Feb 2016 14:21:24 -0800 Subject: [PATCH 4/4] Fix checkstyle errors --- config/checkstyle/import-control.xml | 1 + .../forge/compat/ForgeMultipartCompat.java | 19 +++++++++++++++++++ .../compat/ForgeMultipartExistsCompat.java | 18 ++++++++++++++++++ .../forge/compat/NoForgeMultipartCompat.java | 19 +++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index 7a5600470..1209aa71d 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -48,6 +48,7 @@ + diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java index a9e8bd0de..00d1615e1 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartCompat.java @@ -1,3 +1,22 @@ +/* + * 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.forge.compat; import javax.annotation.Nullable; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java index 1f5c82f30..d1b4752e4 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/ForgeMultipartExistsCompat.java @@ -1,3 +1,21 @@ +/* + * 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.forge.compat; import codechicken.multipart.MultipartHelper; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java index 229a9ba40..316509689 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/compat/NoForgeMultipartCompat.java @@ -1,3 +1,22 @@ +/* + * 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.forge.compat; import net.minecraft.nbt.NBTTagCompound;