Implement FMP compatibility

This commit is contained in:
Kenzie Togami 2016-02-07 14:07:41 -08:00
parent 10776f27a8
commit 7271cca89f
6 changed files with 101 additions and 6 deletions

View File

@ -26,8 +26,12 @@
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 void preInit(FMLPreInitializationEvent event) {
config = new ForgeConfiguration(this);
config.load();
if (Loader.isModLoaded("ForgeMultipart")) {
compat = new ForgeMultipartExistsCompat();
}
FMLCommonHandler.instance().bus().register(ThreadSafeCache.getInstance());
}
@ -260,6 +269,10 @@ public File getWorkingDir() {
return this.workingDir;
}
public ForgeMultipartCompat getFMPCompat() {
return compat;
}
/**
* Get the version of the WorldEdit-for-Forge implementation.
*

View File

@ -81,9 +81,10 @@ static void setTileEntity(World world, Vector position, Class<? extends TileEnti
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,13 +96,27 @@ static void setTileEntity(World world, Vector position, Class<? extends TileEnti
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 @@ static TileEntity constructTileEntity(World world, Vector position, Class<? exte
return genericTE;
}
}

View File

@ -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);
}

View File

@ -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);
}
}
}

View File

@ -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) {
}
}

View File

@ -14,7 +14,8 @@
"Forge@[${forgeVersion},)"
],
"dependencies": [
"Forge@[${forgeVersion},)"
"Forge@[${forgeVersion},)",
"ForgeMultipart"
],
"dependants": []
}]