Added the ability to override the microblock highlight render.

This commit is contained in:
Chicken Bones committed 2013-08-18 15:13:33 +10:00
1 parent f9eb162770
commit a34f178f86
2 files changed
+28 -2

No files matched your search

+2 -2
View File
@@ -164,7 +164,7 @@ object ItemMicroPartRenderer extends IItemRenderer
val size = stack.getItemDamage&0xFF
if(material < 0 || mcrClass == null)
return false
return mcrClass.renderHighlight(world, player, hit, size, material)
return MicroMaterialRegistry.renderHighlight(world, player, hit, mcrClass, size, material)
}
}
@@ -18,6 +18,8 @@ import codechicken.lib.render.Vertex5
import net.minecraft.item.ItemStack
import scala.collection.mutable.ListBuffer
import net.minecraft.block.StepSound
import net.minecraft.util.MovingObjectPosition
import net.minecraft.world.World
object MicroMaterialRegistry
{
@@ -53,11 +55,21 @@ object MicroMaterialRegistry
//todo, get material properties
}
trait IMicroHighlightRenderer
{
/**
* Return true if a custom highlight was rendered and the default should be skipped
*/
def renderHighlight(world:World, player:EntityPlayer, hit:MovingObjectPosition, mcrClass:MicroblockClass, size:Int, material:Int):Boolean
}
private val typeMap:HashMap[String, IMicroMaterial] = new HashMap
private val nameMap:HashMap[String, Int] = new HashMap
private var idMap:Array[(String, IMicroMaterial)] = _
private val idWriter = IDWriter()
private val highlightRenderers = ListBuffer[IMicroHighlightRenderer]()
def registerMaterial(material:IMicroMaterial, name:String)
{
if(MultiPartRegistry.loaded)
@@ -71,6 +83,11 @@ object MicroMaterialRegistry
typeMap.put(name, material)
}
def registerHighlightRenderer(handler:IMicroHighlightRenderer)
{
highlightRenderers+=handler
}
def setupIDMap()
{
idMap = typeMap.toList.sortBy(_._1).toArray
@@ -130,4 +147,13 @@ object MicroMaterialRegistry
def getMaterial(id:Int) = idMap(id)._2
def getIdMap = idMap
def renderHighlight(world:World, player:EntityPlayer, hit:MovingObjectPosition, mcrClass:MicroblockClass, size:Int, material:Int):Boolean =
{
val overriden = highlightRenderers.find(_.renderHighlight(world, player, hit, mcrClass, size, material))
if(overriden.isDefined)
return true
return mcrClass.renderHighlight(world, player, hit, size, material)
}
}