Added workaround for lack of TileEntityLoadEvent

Fixed bug in part generator duplicating the base tile class
Updated readme to reflect removal of recent forge dependency
This commit is contained in:
Chicken Bones committed 2013-05-21 00:19:56 +10:00
1 parent 92b0dd1f5d
commit b067a08b34
6 files changed
+78 -14

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ An API for dynamically handling different functional parts in the one block spac
Requirements:
The latest version of CCC-Public
Forge 7.8.0.706 (or latest git)
Forge
scala-compiler.jar (part of a standard scala installation, will need to be moved to /libs/ and linked in your IDE)
A scala compatible IDE and project (For eclipse, download the scala eclipse plugin and right click on the project -> Add Scala Nature)
@@ -75,6 +75,7 @@ object MultipartGenerator
import SuperSet._
val set = baseType+:types.sortWith(_.toString < _.toString)
def interfaces = set
def baseType = if(client) TileMultipartClientType else TileMultipartType
override def equals(obj:Any) = obj match
@@ -99,7 +100,7 @@ object MultipartGenerator
})
}
private def generator():Generator =
def generator():Generator =
{
val s = System.currentTimeMillis
val defClass =
@@ -139,7 +140,7 @@ object MultipartGenerator
val v = tb.eval(Block(defClass, defGenClass, constructGenClass)).asInstanceOf[Generator]
val dummy = v.generate
tileTraitMap=tileTraitMap+(dummy.getClass->set.toSet)
tileTraitMap=tileTraitMap+(dummy.getClass->types.toSet)
MultipartProxy.onTileClassBuilt(dummy.getClass)
println("Generation ["+types.mkString(", ")+"] took: "+(System.currentTimeMillis-s))
return v.asInstanceOf[Generator]
+1 -1
View File
@@ -514,7 +514,7 @@ object TileMultipartObj
def createFromNBT(tag:NBTTagCompound):TileMultipart =
{
val superID = tag.getString("superID")
val superClass = TileEntity.nameToClassMap.get(superID)
//val superClass = TileEntity.nameToClassMap.get(superID)
val partList = tag.getTagList("parts")
val parts = ListBuffer[TMultiPart]()
@@ -1,6 +1,5 @@
package codechicken.multipart.handler
import net.minecraftforge.event.tileentity.TileEntityLoadEvent
import net.minecraft.nbt.NBTTagCompound
import codechicken.multipart.TileMultipart
import net.minecraftforge.event.ForgeSubscribe
@@ -14,19 +13,14 @@ import net.minecraft.network.NetLoginHandler
import net.minecraft.server.MinecraftServer
import codechicken.core.packet.PacketCustom
import codechicken.multipart.MultiPartRegistry
import net.minecraftforge.event.world._
object MultipartEventHandler extends IConnectionHandler
{
@ForgeSubscribe
def tileEntityLoad(event:TileEntityLoadEvent)
def tileEntityLoad(event:ChunkDataEvent.Load)
{
val id = event.tag.getString("id");
if(!id.equals("savedMultipart"))
return
val t = TileMultipartObj.createFromNBT(event.tag)
if(t != null)
event.setResult(t)
MultipartSaveLoad.loadTiles(event.getChunk())
}
def connectionReceived(loginHandler:NetLoginHandler, netManager:INetworkManager):String =
@@ -0,0 +1,69 @@
package codechicken.multipart.handler
import net.minecraft.tileentity.TileEntity
import net.minecraft.nbt.NBTTagCompound
import java.util.Map
import net.minecraft.world.chunk.Chunk
import net.minecraft.world.ChunkPosition
import codechicken.multipart.TileMultipartObj
/**
* Hack due to lack of TileEntityLoadEvent in forge
*/
object MultipartSaveLoad
{
class TileNBTContainer extends TileEntity
{
var tag:NBTTagCompound = _
override def readFromNBT(t:NBTTagCompound)
{
super.readFromNBT(t)
tag = t
}
}
hookLoader()
def hookLoader()
{
val field = classOf[TileEntity].getDeclaredFields()(0)
field.setAccessible(true)
val map = field.get(null).asInstanceOf[Map[String, Class[_ <: TileEntity]]]
map.put("savedMultipart", classOf[TileNBTContainer])
}
private val classToNameMap = getClassToNameMap
def registerTileClass(t:Class[_ <: TileEntity])
{
classToNameMap.put(t, "savedMultipart")
}
def getClassToNameMap() =
{
val field = classOf[TileEntity].getDeclaredFields()(1)
field.setAccessible(true)
field.get(null).asInstanceOf[Map[Class[_ <: TileEntity], String]]
}
def loadTiles(chunk:Chunk)
{
val iterator = chunk.chunkTileEntityMap.asInstanceOf[Map[ChunkPosition, TileEntity]].entrySet.iterator
while(iterator.hasNext)
{
val e = iterator.next
if(e.getValue.isInstanceOf[TileNBTContainer])
{
val t = TileMultipartObj.createFromNBT(e.getValue.asInstanceOf[TileNBTContainer].tag)
if(t != null)
{
t.setWorldObj(e.getValue.worldObj)
t.validate
e.setValue(t)
}
else
iterator.remove
}
}
}
}
+1 -1
View File
@@ -47,7 +47,7 @@ class MultipartProxy_serverImpl
def onTileClassBuilt(t:Class[_ <: TileEntity])
{
TileEntity.classToNameMap.asInstanceOf[HashMap[Class[_ <: TileEntity], String]].put(t, "savedMultipart")
MultipartSaveLoad.registerTileClass(t)
}
}