From 99ecd7e40e881800f226f3fb0729758e2935676a Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 21 Sep 2014 15:29:09 +0800 Subject: [PATCH] Fixed frame wire renderer --- .../textures/{blocks => items}/wire.png | Bin .../electrical/Electrical.scala | 64 +++++++++++------- .../electrical/wire/ItemWire.scala | 24 ++----- .../electrical/wire/base/TWire.scala | 2 +- .../electrical/wire/flat/PartFlatWire.scala | 2 +- .../electrical/wire/flat/RenderFlatWire.scala | 2 +- .../wire/framed/RenderFramedWire.scala | 37 ++++++---- 7 files changed, 71 insertions(+), 60 deletions(-) rename src/main/resources/assets/resonantinduction/textures/{blocks => items}/wire.png (100%) diff --git a/src/main/resources/assets/resonantinduction/textures/blocks/wire.png b/src/main/resources/assets/resonantinduction/textures/items/wire.png similarity index 100% rename from src/main/resources/assets/resonantinduction/textures/blocks/wire.png rename to src/main/resources/assets/resonantinduction/textures/items/wire.png diff --git a/src/main/scala/resonantinduction/electrical/Electrical.scala b/src/main/scala/resonantinduction/electrical/Electrical.scala index 3a7f29b2e..d52b11ad0 100644 --- a/src/main/scala/resonantinduction/electrical/Electrical.scala +++ b/src/main/scala/resonantinduction/electrical/Electrical.scala @@ -6,14 +6,15 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent import cpw.mods.fml.common.network.NetworkRegistry import cpw.mods.fml.common.registry.GameRegistry 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.minecraftforge.event.entity.EntityJoinWorldEvent +import net.minecraftforge.client.event.TextureStitchEvent +import net.minecraftforge.common.MinecraftForge import net.minecraftforge.oredict.OreDictionary import resonant.content.loader.ModManager import resonant.lib.loadable.LoadableHandler -import resonantinduction.atomic.gate.{PartQuantumGlyph, ItemQuantumGlyph} -import resonantinduction.core.{ResonantPartFactory, Reference, ResonantTab, Settings} +import resonantinduction.atomic.gate.{ItemQuantumGlyph, PartQuantumGlyph} +import resonantinduction.core.{Reference, ResonantPartFactory, ResonantTab, Settings} import resonantinduction.electrical.battery.{ItemBlockBattery, TileBattery} import resonantinduction.electrical.generator.{TileMotor, TileSolarPanel, TileThermopile} 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.mirror.{BlockMirror, TileMirror} import resonantinduction.electrical.laser.receiver.{BlockLaserReceiver, TileLaserReceiver} -import resonantinduction.electrical.levitator.{PartLevitator, ItemLevitator} -import resonantinduction.electrical.multimeter.{PartMultimeter, ItemMultimeter} +import resonantinduction.electrical.levitator.{ItemLevitator, PartLevitator} +import resonantinduction.electrical.multimeter.{ItemMultimeter, PartMultimeter} 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.base.WireMaterial -import resonantinduction.electrical.wire.flat.PartFlatWire -import resonantinduction.electrical.wire.framed.PartFramedWire +import resonantinduction.electrical.wire.flat.{PartFlatWire, RenderFlatWire} +import resonantinduction.electrical.wire.framed.{PartFramedWire, RenderFramedWire} /** 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") object Electrical { /** Mod Information */ - final val ID: String = "ResonantInduction|Electrical" - final val NAME: String = Reference.name + " Electrical" + final val ID = "ResonantInduction|Electrical" + final val NAME = Reference.name + " Electrical" var INSTANCE = this @@ -49,17 +49,18 @@ object Electrical @Mod.Metadata("ResonantInduction|Electrical") 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 def preInit(evt: FMLPreInitializationEvent) { - modproxies = new LoadableHandler NetworkRegistry.INSTANCE.registerGuiHandler(this, Electrical.proxy) - Settings.config.load - //ElectromagneticCoherence content TODO convert + MinecraftForge.EVENT_BUS.register(this) + + Settings.config.load() ElectricalContent.blockLaserEmitter = new BlockLaserEmitter() ElectricalContent.blockLaserReceiver = new BlockLaserReceiver() ElectricalContent.blockMirror = new BlockMirror() @@ -98,7 +99,6 @@ object Electrical OreDictionary.registerOre("batteryBox", ItemBlockBattery.setTier(new ItemStack(ElectricalContent.blockBattery, 1, 0), 0.asInstanceOf[Byte])) ResonantTab.itemStack(new ItemStack(ElectricalContent.itemTransformer)) - /** * Register all parts */ @@ -110,19 +110,35 @@ object Electrical ResonantPartFactory.register(classOf[PartQuantumGlyph]) Electrical.proxy.preInit - modproxies.preInit() + loadable.preInit() } @EventHandler def init(evt: FMLInitializationEvent) { Electrical.proxy.init - modproxies.init() + loadable.init() } - @EventHandler def postInit(evt: FMLPostInitializationEvent) + @EventHandler + def postInit(evt: FMLPostInitializationEvent) { 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") + } } } \ No newline at end of file diff --git a/src/main/scala/resonantinduction/electrical/wire/ItemWire.scala b/src/main/scala/resonantinduction/electrical/wire/ItemWire.scala index a1ff41d87..50db99ef9 100644 --- a/src/main/scala/resonantinduction/electrical/wire/ItemWire.scala +++ b/src/main/scala/resonantinduction/electrical/wire/ItemWire.scala @@ -40,7 +40,7 @@ class ItemWire extends TItemMultiPart 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) { @@ -50,17 +50,15 @@ class ItemWire extends TItemMultiPart return wire } - override def getMetadata(damage: Int): Int = - { - return damage - } + override def getMetadata(damage: Int): Int = damage override def getUnlocalizedName(itemStack: ItemStack): String = { 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)) { @@ -75,18 +73,8 @@ class ItemWire extends TItemMultiPart } } - @SideOnly(Side.CLIENT) override def getSpriteNumber: 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 = + @SideOnly(Side.CLIENT) + override def getColorFromItemStack(itemStack: ItemStack, par2: Int): Int = { return new Color(WireMaterial.values()(itemStack.getItemDamage).color).darker.getRGB } diff --git a/src/main/scala/resonantinduction/electrical/wire/base/TWire.scala b/src/main/scala/resonantinduction/electrical/wire/base/TWire.scala index dc80598e4..fc71a3849 100644 --- a/src/main/scala/resonantinduction/electrical/wire/base/TWire.scala +++ b/src/main/scala/resonantinduction/electrical/wire/base/TWire.scala @@ -24,7 +24,7 @@ trait TWire extends PartAbstract with TNodePartConnector with TMaterial[WireMate { override protected val insulationItem: Item = ElectricalContent.itemInsulation material = WireMaterial.COPPER - + def preparePlacement(side: Int, meta: Int) override def setMaterial(i: Int) diff --git a/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.scala b/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.scala index 9875f0baa..12195427b 100644 --- a/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.scala +++ b/src/main/scala/resonantinduction/electrical/wire/flat/PartFlatWire.scala @@ -279,7 +279,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc @SideOnly(Side.CLIENT) def getIcon: IIcon = { - return RenderFlatWire.flatWireTexture + return RenderFlatWire.wireIcon } def useStaticRenderer: Boolean = true diff --git a/src/main/scala/resonantinduction/electrical/wire/flat/RenderFlatWire.scala b/src/main/scala/resonantinduction/electrical/wire/flat/RenderFlatWire.scala index b362b64a9..5da3cb8aa 100644 --- a/src/main/scala/resonantinduction/electrical/wire/flat/RenderFlatWire.scala +++ b/src/main/scala/resonantinduction/electrical/wire/flat/RenderFlatWire.scala @@ -12,7 +12,7 @@ import resonantinduction.core.util.ResonantUtil object RenderFlatWire { - var flatWireTexture: IIcon = null + var wireIcon: IIcon = null var reorientSide: Array[Int] = Array[Int](0, 3, 3, 0, 0, 3) /** * Array of all built models. These will be generated on demand. diff --git a/src/main/scala/resonantinduction/electrical/wire/framed/RenderFramedWire.scala b/src/main/scala/resonantinduction/electrical/wire/framed/RenderFramedWire.scala index b1a2063a1..726be4797 100644 --- a/src/main/scala/resonantinduction/electrical/wire/framed/RenderFramedWire.scala +++ b/src/main/scala/resonantinduction/electrical/wire/framed/RenderFramedWire.scala @@ -1,17 +1,20 @@ package resonantinduction.electrical.wire.framed -import java.nio.FloatBuffer -import java.util.Map - +import codechicken.lib.lighting.LightModel import codechicken.lib.render.uv.IconTransformation import codechicken.lib.render.{CCModel, CCRenderState, ColourMultiplier, TextureUtils} import codechicken.lib.vec.{Rotation, Translation} 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 resonant.lib.wrapper.BitmaskWrapper._ +import resonantinduction.core.Reference +import resonantinduction.core.render.InvertX import resonantinduction.core.util.ResonantUtil +import scala.collection.convert.wrapAll._ +import scala.collection.mutable + /** * Renderer for framed wires * @author Calclavia @@ -19,17 +22,18 @@ import resonantinduction.core.util.ResonantUtil @SideOnly(Side.CLIENT) object RenderFramedWire { - val models: Map[String, CCModel] = null - var wireIIcon: IIcon = null - var insulationIIcon: IIcon = null + var models = mutable.Map.empty[String, CCModel] + var wireIcon: IIcon = null + var insulationIcon: 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 - buffer.put(src.toArray) - buffer.flip - } + c.apply(new Translation(.5, 0, .5)) + c.computeLighting(LightModel.standardLightModel) + c.shrinkUVs(0.0005) + }) def renderStatic(wire: PartFramedWire) { @@ -47,14 +51,17 @@ object RenderFramedWire var name: String = side.name.toLowerCase 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) - 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) { - 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) } \ No newline at end of file