Fixed frame wire renderer

This commit is contained in:
Calclavia 2014-09-21 15:29:09 +08:00
parent 89ff64596e
commit 99ecd7e40e
7 changed files with 71 additions and 60 deletions

View file

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

@ -6,14 +6,15 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.common.network.NetworkRegistry import cpw.mods.fml.common.network.NetworkRegistry
import cpw.mods.fml.common.registry.GameRegistry import cpw.mods.fml.common.registry.GameRegistry
import cpw.mods.fml.common.{Mod, ModMetadata, SidedProxy} import cpw.mods.fml.common.{Mod, ModMetadata, SidedProxy}
import net.minecraft.entity.player.EntityPlayer import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.item.{Item, ItemStack} import net.minecraft.item.{Item, ItemStack}
import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.client.event.TextureStitchEvent
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.oredict.OreDictionary import net.minecraftforge.oredict.OreDictionary
import resonant.content.loader.ModManager import resonant.content.loader.ModManager
import resonant.lib.loadable.LoadableHandler import resonant.lib.loadable.LoadableHandler
import resonantinduction.atomic.gate.{PartQuantumGlyph, ItemQuantumGlyph} import resonantinduction.atomic.gate.{ItemQuantumGlyph, PartQuantumGlyph}
import resonantinduction.core.{ResonantPartFactory, Reference, ResonantTab, Settings} import resonantinduction.core.{Reference, ResonantPartFactory, ResonantTab, Settings}
import resonantinduction.electrical.battery.{ItemBlockBattery, TileBattery} import resonantinduction.electrical.battery.{ItemBlockBattery, TileBattery}
import resonantinduction.electrical.generator.{TileMotor, TileSolarPanel, TileThermopile} import resonantinduction.electrical.generator.{TileMotor, TileSolarPanel, TileThermopile}
import resonantinduction.electrical.laser.emitter.{BlockLaserEmitter, TileLaserEmitter} import resonantinduction.electrical.laser.emitter.{BlockLaserEmitter, TileLaserEmitter}
@ -21,25 +22,24 @@ import resonantinduction.electrical.laser.focus.ItemFocusingMatrix
import resonantinduction.electrical.laser.focus.crystal.{BlockFocusCrystal, TileFocusCrystal} import resonantinduction.electrical.laser.focus.crystal.{BlockFocusCrystal, TileFocusCrystal}
import resonantinduction.electrical.laser.focus.mirror.{BlockMirror, TileMirror} import resonantinduction.electrical.laser.focus.mirror.{BlockMirror, TileMirror}
import resonantinduction.electrical.laser.receiver.{BlockLaserReceiver, TileLaserReceiver} import resonantinduction.electrical.laser.receiver.{BlockLaserReceiver, TileLaserReceiver}
import resonantinduction.electrical.levitator.{PartLevitator, ItemLevitator} import resonantinduction.electrical.levitator.{ItemLevitator, PartLevitator}
import resonantinduction.electrical.multimeter.{PartMultimeter, ItemMultimeter} import resonantinduction.electrical.multimeter.{ItemMultimeter, PartMultimeter}
import resonantinduction.electrical.tesla.TileTesla import resonantinduction.electrical.tesla.TileTesla
import resonantinduction.electrical.transformer.{PartElectricTransformer, ItemElectricTransformer} import resonantinduction.electrical.transformer.{ItemElectricTransformer, PartElectricTransformer}
import resonantinduction.electrical.wire.ItemWire import resonantinduction.electrical.wire.ItemWire
import resonantinduction.electrical.wire.base.WireMaterial import resonantinduction.electrical.wire.flat.{PartFlatWire, RenderFlatWire}
import resonantinduction.electrical.wire.flat.PartFlatWire import resonantinduction.electrical.wire.framed.{PartFramedWire, RenderFramedWire}
import resonantinduction.electrical.wire.framed.PartFramedWire
/** Resonant Induction Electrical Module /** Resonant Induction Electrical Module
* *
* @author Calclavia */ * @author Calclavia
*/
@Mod(modid = "ResonantInduction|Electrical", name = "Resonant Induction Electrical", version = Reference.version, dependencies = "before:ThermalExpansion;before:Mekanism;after:ResonantInduction|Mechanical;required-after:" + Reference.coreID, modLanguage = "scala") @Mod(modid = "ResonantInduction|Electrical", name = "Resonant Induction Electrical", version = Reference.version, dependencies = "before:ThermalExpansion;before:Mekanism;after:ResonantInduction|Mechanical;required-after:" + Reference.coreID, modLanguage = "scala")
object Electrical object Electrical
{ {
/** Mod Information */ /** Mod Information */
final val ID: String = "ResonantInduction|Electrical" final val ID = "ResonantInduction|Electrical"
final val NAME: String = Reference.name + " Electrical" final val NAME = Reference.name + " Electrical"
var INSTANCE = this var INSTANCE = this
@ -49,17 +49,18 @@ object Electrical
@Mod.Metadata("ResonantInduction|Electrical") @Mod.Metadata("ResonantInduction|Electrical")
var metadata: ModMetadata = null var metadata: ModMetadata = null
final val contentRegistry: ModManager = new ModManager().setPrefix(Reference.prefix).setTab(ResonantTab.tab) @deprecated
val contentRegistry: ModManager = new ModManager().setPrefix(Reference.prefix).setTab(ResonantTab.tab)
var modproxies: LoadableHandler = null val loadable = new LoadableHandler()
@EventHandler @EventHandler
def preInit(evt: FMLPreInitializationEvent) def preInit(evt: FMLPreInitializationEvent)
{ {
modproxies = new LoadableHandler
NetworkRegistry.INSTANCE.registerGuiHandler(this, Electrical.proxy) NetworkRegistry.INSTANCE.registerGuiHandler(this, Electrical.proxy)
Settings.config.load MinecraftForge.EVENT_BUS.register(this)
//ElectromagneticCoherence content TODO convert
Settings.config.load()
ElectricalContent.blockLaserEmitter = new BlockLaserEmitter() ElectricalContent.blockLaserEmitter = new BlockLaserEmitter()
ElectricalContent.blockLaserReceiver = new BlockLaserReceiver() ElectricalContent.blockLaserReceiver = new BlockLaserReceiver()
ElectricalContent.blockMirror = new BlockMirror() ElectricalContent.blockMirror = new BlockMirror()
@ -98,7 +99,6 @@ object Electrical
OreDictionary.registerOre("batteryBox", ItemBlockBattery.setTier(new ItemStack(ElectricalContent.blockBattery, 1, 0), 0.asInstanceOf[Byte])) OreDictionary.registerOre("batteryBox", ItemBlockBattery.setTier(new ItemStack(ElectricalContent.blockBattery, 1, 0), 0.asInstanceOf[Byte]))
ResonantTab.itemStack(new ItemStack(ElectricalContent.itemTransformer)) ResonantTab.itemStack(new ItemStack(ElectricalContent.itemTransformer))
/** /**
* Register all parts * Register all parts
*/ */
@ -110,19 +110,35 @@ object Electrical
ResonantPartFactory.register(classOf[PartQuantumGlyph]) ResonantPartFactory.register(classOf[PartQuantumGlyph])
Electrical.proxy.preInit Electrical.proxy.preInit
modproxies.preInit() loadable.preInit()
} }
@EventHandler @EventHandler
def init(evt: FMLInitializationEvent) def init(evt: FMLInitializationEvent)
{ {
Electrical.proxy.init Electrical.proxy.init
modproxies.init() loadable.init()
} }
@EventHandler def postInit(evt: FMLPostInitializationEvent) @EventHandler
def postInit(evt: FMLPostInitializationEvent)
{ {
Electrical.proxy.postInit Electrical.proxy.postInit
modproxies.postInit() loadable.postInit()
}
/**
* Handle wire texture
*/
@SubscribeEvent
@SideOnly(Side.CLIENT)
def preTextureHook(event: TextureStitchEvent.Pre)
{
if (event.map.getTextureType() == 0)
{
RenderFlatWire.wireIcon = event.map.registerIcon(Reference.prefix + "models/flatWire")
RenderFramedWire.wireIcon = event.map.registerIcon(Reference.prefix + "models/wire")
RenderFramedWire.insulationIcon = event.map.registerIcon(Reference.prefix + "models/insulation")
}
} }
} }

View file

@ -40,7 +40,7 @@ class ItemWire extends TItemMultiPart
return null return null
} }
val wire = if (ControlKeyHandler.isPressed) ResonantPartFactory.create(classOf[PartFramedWire]) else ResonantPartFactory.create(classOf[PartFlatWire]) val wire = if (player.isSneaking) ResonantPartFactory.create(classOf[PartFramedWire]) else ResonantPartFactory.create(classOf[PartFlatWire])
if (wire != null) if (wire != null)
{ {
@ -50,17 +50,15 @@ class ItemWire extends TItemMultiPart
return wire return wire
} }
override def getMetadata(damage: Int): Int = override def getMetadata(damage: Int): Int = damage
{
return damage
}
override def getUnlocalizedName(itemStack: ItemStack): String = override def getUnlocalizedName(itemStack: ItemStack): String =
{ {
return super.getUnlocalizedName(itemStack) + "." + WireMaterial.values()(itemStack.getItemDamage).name.toLowerCase return super.getUnlocalizedName(itemStack) + "." + WireMaterial.values()(itemStack.getItemDamage).name.toLowerCase
} }
@SuppressWarnings(Array("unchecked")) override def addInformation(itemStack: ItemStack, player: EntityPlayer, list: List[_], par4: Boolean) @SuppressWarnings(Array("unchecked"))
override def addInformation(itemStack: ItemStack, player: EntityPlayer, list: List[_], par4: Boolean)
{ {
if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
{ {
@ -75,18 +73,8 @@ class ItemWire extends TItemMultiPart
} }
} }
@SideOnly(Side.CLIENT) override def getSpriteNumber: Int = @SideOnly(Side.CLIENT)
{ override def getColorFromItemStack(itemStack: ItemStack, par2: Int): Int =
return 0
}
@SideOnly(Side.CLIENT) override def registerIcons(register: IIconRegister)
{
RenderFlatWire.flatWireTexture = register.registerIcon(Reference.prefix + "models/flatWire")
super.registerIcons(register)
}
@SideOnly(Side.CLIENT) override def getColorFromItemStack(itemStack: ItemStack, par2: Int): Int =
{ {
return new Color(WireMaterial.values()(itemStack.getItemDamage).color).darker.getRGB return new Color(WireMaterial.values()(itemStack.getItemDamage).color).darker.getRGB
} }

View file

@ -24,7 +24,7 @@ trait TWire extends PartAbstract with TNodePartConnector with TMaterial[WireMate
{ {
override protected val insulationItem: Item = ElectricalContent.itemInsulation override protected val insulationItem: Item = ElectricalContent.itemInsulation
material = WireMaterial.COPPER material = WireMaterial.COPPER
def preparePlacement(side: Int, meta: Int) def preparePlacement(side: Int, meta: Int)
override def setMaterial(i: Int) override def setMaterial(i: Int)

View file

@ -279,7 +279,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
def getIcon: IIcon = def getIcon: IIcon =
{ {
return RenderFlatWire.flatWireTexture return RenderFlatWire.wireIcon
} }
def useStaticRenderer: Boolean = true def useStaticRenderer: Boolean = true

View file

@ -12,7 +12,7 @@ import resonantinduction.core.util.ResonantUtil
object RenderFlatWire object RenderFlatWire
{ {
var flatWireTexture: IIcon = null var wireIcon: IIcon = null
var reorientSide: Array[Int] = Array[Int](0, 3, 3, 0, 0, 3) var reorientSide: Array[Int] = Array[Int](0, 3, 3, 0, 0, 3)
/** /**
* Array of all built models. These will be generated on demand. * Array of all built models. These will be generated on demand.

View file

@ -1,17 +1,20 @@
package resonantinduction.electrical.wire.framed package resonantinduction.electrical.wire.framed
import java.nio.FloatBuffer import codechicken.lib.lighting.LightModel
import java.util.Map
import codechicken.lib.render.uv.IconTransformation import codechicken.lib.render.uv.IconTransformation
import codechicken.lib.render.{CCModel, CCRenderState, ColourMultiplier, TextureUtils} import codechicken.lib.render.{CCModel, CCRenderState, ColourMultiplier, TextureUtils}
import codechicken.lib.vec.{Rotation, Translation} import codechicken.lib.vec.{Rotation, Translation}
import cpw.mods.fml.relauncher.{Side, SideOnly} import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.util.IIcon import net.minecraft.util.{IIcon, ResourceLocation}
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.wrapper.BitmaskWrapper._ import resonant.lib.wrapper.BitmaskWrapper._
import resonantinduction.core.Reference
import resonantinduction.core.render.InvertX
import resonantinduction.core.util.ResonantUtil import resonantinduction.core.util.ResonantUtil
import scala.collection.convert.wrapAll._
import scala.collection.mutable
/** /**
* Renderer for framed wires * Renderer for framed wires
* @author Calclavia * @author Calclavia
@ -19,17 +22,18 @@ import resonantinduction.core.util.ResonantUtil
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
object RenderFramedWire object RenderFramedWire
{ {
val models: Map[String, CCModel] = null var models = mutable.Map.empty[String, CCModel]
var wireIIcon: IIcon = null var wireIcon: IIcon = null
var insulationIIcon: IIcon = null var insulationIcon: IIcon = null
var breakIIcon: IIcon = null var breakIIcon: IIcon = null
def loadBuffer(buffer: FloatBuffer, src: Float*) models = CCModel.parseObjModels(new ResourceLocation(Reference.domain, "models/wire.obj"), 7, new InvertX())
models.values.foreach(c =>
{ {
buffer.clear c.apply(new Translation(.5, 0, .5))
buffer.put(src.toArray) c.computeLighting(LightModel.standardLightModel)
buffer.flip c.shrinkUVs(0.0005)
} })
def renderStatic(wire: PartFramedWire) def renderStatic(wire: PartFramedWire)
{ {
@ -47,14 +51,17 @@ object RenderFramedWire
var name: String = side.name.toLowerCase var name: String = side.name.toLowerCase
name = if (name == "unknown") "center" else name name = if (name == "unknown") "center" else name
renderPart(wireIIcon, models.get(name), wire.x, wire.y, wire.z, wire.material.color) renderPart(wireIcon, models(name), wire.x, wire.y, wire.z, RGBColorToRGBA(wire.material.color))
if (wire.insulated) if (wire.insulated)
renderPart(insulationIIcon, models.get(name + "Insulation"), wire.x, wire.y, wire.z, ResonantUtil.getColorHex(wire.getColor)) renderPart(insulationIcon, models(name + "Insulation"), wire.x, wire.y, wire.z, RGBColorToRGBA(ResonantUtil.getColorHex(wire.getColor)))
} }
def renderPart(icon: IIcon, cc: CCModel, x: Double, y: Double, z: Double, color: Int) def renderPart(icon: IIcon, cc: CCModel, x: Double, y: Double, z: Double, color: Int)
{ {
cc.render(0, cc.verts.length, Rotation.sideOrientation(0, Rotation.rotationTo(0, 2)).at(codechicken.lib.vec.Vector3.center).`with`(new Translation(x, y, z)), new IconTransformation(icon), new ColourMultiplier(color)) val transform = Rotation.sideOrientation(0, Rotation.rotationTo(0, 2)).at(codechicken.lib.vec.Vector3.center).`with`(new Translation(x, y, z))
cc.render(0, cc.verts.length, transform, new IconTransformation(icon), new ColourMultiplier(color))
} }
def RGBColorToRGBA(color: Int): Int = color << 8 | (255 & 0xFF)
} }