From 31f1ee119700cf73b283c5514881447a6df401af Mon Sep 17 00:00:00 2001 From: Chicken-Bones Date: Sun, 26 Jan 2014 17:36:27 +1000 Subject: [PATCH] Added compatibility for MCPC placement protection overrides --- codechicken/multipart/TileMultipart.scala | 18 +++++----- .../handler/MultipartCompatiblity.scala | 33 +++++++++++++++++++ codechicken/multipart/handler/proxies.scala | 2 ++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 codechicken/multipart/handler/MultipartCompatiblity.scala diff --git a/codechicken/multipart/TileMultipart.scala b/codechicken/multipart/TileMultipart.scala index a04c4c0..b15a18f 100644 --- a/codechicken/multipart/TileMultipart.scala +++ b/codechicken/multipart/TileMultipart.scala @@ -8,13 +8,12 @@ import net.minecraft.world.World import java.util.List import net.minecraft.nbt.NBTTagCompound import codechicken.lib.data.MCDataOutput -import codechicken.multipart.handler.MultipartProxy +import codechicken.multipart.handler.{MultipartCompatiblity, MultipartProxy, MultipartSPH} import net.minecraft.block.Block import net.minecraft.item.ItemStack import codechicken.lib.vec.Vector3 import net.minecraft.nbt.NBTTagList import java.util.Random -import codechicken.multipart.handler.MultipartSPH import codechicken.lib.lighting.LazyLightMatrix import net.minecraft.entity.item.EntityItem import net.minecraft.entity.player.EntityPlayer @@ -225,14 +224,11 @@ class TileMultipart extends TileEntity /** * Returns true if part can be added to this space */ - def canAddPart(part:TMultiPart):Boolean = - { - if(partList.contains(part)) - return false - - return occlusionTest(partList, part) - } - + def canAddPart(part:TMultiPart) = + MultipartCompatiblity.canAddPart(worldObj, xCoord, yCoord, zCoord) && + !partList.contains(part) && + occlusionTest(partList, part) + /** * Returns true if opart can be replaced with npart (note opart and npart may be the exact same object) * @@ -583,6 +579,8 @@ object TileMultipart val t = getOrConvertTile(world, pos) if(t != null) return t.canAddPart(part) + else if(!MultipartCompatiblity.canAddPart(world, pos.x, pos.y, pos.z)) + return false if(!replaceable(world, pos)) return false diff --git a/codechicken/multipart/handler/MultipartCompatiblity.scala b/codechicken/multipart/handler/MultipartCompatiblity.scala new file mode 100644 index 0000000..85b84d4 --- /dev/null +++ b/codechicken/multipart/handler/MultipartCompatiblity.scala @@ -0,0 +1,33 @@ +package codechicken.multipart.handler + +import net.minecraft.world.World +import cpw.mods.fml.common.FMLCommonHandler +import net.minecraft.block.Block + +object MultipartCompatiblity +{ + var canAddPart = (world:World, x:Int, y:Int, z:Int) => true + + def load() { + if(FMLCommonHandler.instance().getModName.contains("mcpc")) + MCPCCompatModule.load() + } +} + +object MCPCCompatModule +{ + def load() { + try { + val m_canPlacePart = classOf[World].getDeclaredMethod("canPlaceMultipart", classOf[World], classOf[Block], classOf[Int], classOf[Int], classOf[Int]) + MultipartCompatiblity.canAddPart = (world:World, x:Int, y:Int, z:Int) => { + m_canPlacePart.invoke(world, MultipartProxy.block, x:Integer, y:Integer, z:Integer).asInstanceOf[Boolean].booleanValue() + } + } catch { + case e:Exception => + System.err.println("Failed to integrate MCPC placement hooks") + e.printStackTrace() + } + } +} + + diff --git a/codechicken/multipart/handler/proxies.scala b/codechicken/multipart/handler/proxies.scala index aeb2860..87021ef 100644 --- a/codechicken/multipart/handler/proxies.scala +++ b/codechicken/multipart/handler/proxies.scala @@ -56,6 +56,8 @@ class MultipartProxy_serverImpl TickRegistry.registerTickHandler(MultipartEventHandler, Side.SERVER) WorldExtensionManager.registerWorldExtension(TickScheduler) + + MultipartCompatiblity.load() } def getFreeBlockID(preferred:Int):Int =