mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
Made Hover Boots dyeable.
This commit is contained in:
parent
54de3fe89d
commit
726ceae91f
Binary file not shown.
Before Width: | Height: | Size: 461 B After Width: | Height: | Size: 420 B |
Binary file not shown.
After Width: | Height: | Size: 198 B |
@ -92,6 +92,8 @@ object HoverBootRenderer extends ModelBiped {
|
||||
bipedEars.isHidden = true
|
||||
bipedCloak.isHidden = true
|
||||
|
||||
var lightColor = 0x66DD55
|
||||
|
||||
override def render(entity: Entity, f0: Float, f1: Float, f2: Float, f3: Float, f4: Float, f5: Float): Unit = {
|
||||
// Because Forge is being a dummy...
|
||||
isSneak = entity.isSneaking
|
||||
@ -104,7 +106,10 @@ object HoverBootRenderer extends ModelBiped {
|
||||
RenderState.disableLighting()
|
||||
GL11.glDepthFunc(GL11.GL_LEQUAL)
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE)
|
||||
GL11.glColor3ub(0x66.toByte, 0xDD.toByte, 0x55.toByte)
|
||||
val r = ((lightColor >>> 16) & 0xFF).toByte
|
||||
val g = ((lightColor >>> 8) & 0xFF).toByte
|
||||
val b = ((lightColor >>> 0) & 0xFF).toByte
|
||||
GL11.glColor3ub(r, g, b)
|
||||
|
||||
super.render(dt)
|
||||
|
||||
|
@ -1,19 +1,17 @@
|
||||
package li.cil.oc.common.item
|
||||
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.client.renderer.item.HoverBootRenderer
|
||||
import li.cil.oc.common.item.data.HoverBootsData
|
||||
import li.cil.oc.util.ItemColorizer
|
||||
import net.minecraft.client.model.ModelBiped
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.entity.EntityLivingBase
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.EnumRarity
|
||||
import net.minecraft.item.ItemArmor
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.potion.Potion
|
||||
import net.minecraft.potion.PotionEffect
|
||||
import net.minecraft.entity.{Entity, EntityLivingBase}
|
||||
import net.minecraft.item.{EnumRarity, ItemArmor, ItemStack}
|
||||
import net.minecraft.potion.{Potion, PotionEffect}
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.world.World
|
||||
|
||||
class HoverBoots extends ItemArmor(ItemArmor.ArmorMaterial.DIAMOND, 0, 3) with traits.SimpleItem with traits.Chargeable {
|
||||
@ -56,7 +54,10 @@ class HoverBoots extends ItemArmor(ItemArmor.ArmorMaterial.DIAMOND, 0, 3) with t
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def getArmorModel(entityLiving: EntityLivingBase, itemStack: ItemStack, armorSlot: Int): ModelBiped = {
|
||||
if (armorSlot == armorType) HoverBootRenderer
|
||||
if (armorSlot == armorType) {
|
||||
HoverBootRenderer.lightColor = if (ItemColorizer.hasColor(itemStack)) ItemColorizer.getColor(itemStack) else 0x66DD55
|
||||
HoverBootRenderer
|
||||
}
|
||||
else super.getArmorModel(entityLiving, itemStack, armorSlot)
|
||||
}
|
||||
|
||||
@ -72,6 +73,28 @@ class HoverBoots extends ItemArmor(ItemArmor.ArmorMaterial.DIAMOND, 0, 3) with t
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
var lightOverlay: IIcon = null
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def registerIcons(ir: IIconRegister): Unit = {
|
||||
this.itemIcon = ir.registerIcon(this.getIconString)
|
||||
this.lightOverlay = ir.registerIcon(this.getIconString + "Light")
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def requiresMultipleRenderPasses(): Boolean = true
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def getIconFromDamageForRenderPass(meta : Int, pass : Int): IIcon = if (pass == 1 ) lightOverlay else super.getIconFromDamageForRenderPass(meta, pass)
|
||||
|
||||
override def getColorFromItemStack(itemStack: ItemStack, pass: Int): Int = {
|
||||
if (pass == 1) {
|
||||
return if (ItemColorizer.hasColor(itemStack)) ItemColorizer.getColor(itemStack) else 0x66DD55
|
||||
}
|
||||
super.getColorFromItemStack(itemStack, pass)
|
||||
}
|
||||
|
||||
override def getDisplayDamage(stack: ItemStack): Int = {
|
||||
val data = new HoverBootsData(stack)
|
||||
(Settings.get.bufferHoverBoots * (1 - data.charge / Settings.get.bufferHoverBoots)).toInt
|
||||
|
85
src/main/scala/li/cil/oc/common/recipe/ColorizeRecipe.scala
Normal file
85
src/main/scala/li/cil/oc/common/recipe/ColorizeRecipe.scala
Normal file
@ -0,0 +1,85 @@
|
||||
package li.cil.oc.common.recipe
|
||||
|
||||
import li.cil.oc.util.{Color, ItemColorizer}
|
||||
import net.minecraft.entity.passive.EntitySheep
|
||||
import net.minecraft.inventory.InventoryCrafting
|
||||
import net.minecraft.item.crafting.IRecipe
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.world.World
|
||||
|
||||
/**
|
||||
* @author asie, Vexatos
|
||||
*/
|
||||
class ColorizeRecipe(target: Item, source: Array[Item] = null) extends IRecipe {
|
||||
val targetItem = target
|
||||
val sourceItems = if (source != null) source else Array(targetItem)
|
||||
|
||||
override def matches(crafting: InventoryCrafting, world: World): Boolean = {
|
||||
val stacks = (0 until crafting.getSizeInventory).flatMap(i => Option(crafting.getStackInSlot(i)))
|
||||
val targets = stacks.filter(stack => sourceItems.contains(stack.getItem) || stack.getItem == targetItem)
|
||||
val other = stacks.filterNot(targets.contains)
|
||||
targets.size == 1 && other.nonEmpty && other.forall(Color.isDye)
|
||||
}
|
||||
|
||||
override def getCraftingResult(crafting: InventoryCrafting): ItemStack = {
|
||||
var targetStack: ItemStack = null
|
||||
val color = Array[Int](0, 0, 0)
|
||||
var colorCount = 0
|
||||
var maximum = 0
|
||||
|
||||
(0 until crafting.getSizeInventory).flatMap(i => Option(crafting.getStackInSlot(i))).foreach { stack =>
|
||||
if (sourceItems.contains(stack.getItem)
|
||||
|| stack.getItem == targetItem) {
|
||||
targetStack = stack.copy()
|
||||
targetStack.stackSize = 1
|
||||
} else {
|
||||
val dye = Color.findDye(stack)
|
||||
if (dye.isEmpty)
|
||||
return null
|
||||
|
||||
val itemColor = EntitySheep.fleeceColorTable(15 - Color.dyes.indexOf(dye.get))
|
||||
val red = (itemColor(0) * 255.0F).toInt
|
||||
val green = (itemColor(1) * 255.0F).toInt
|
||||
val blue = (itemColor(2) * 255.0F).toInt
|
||||
maximum += Math.max(red, Math.max(green, blue))
|
||||
color(0) += red
|
||||
color(1) += green
|
||||
color(2) += blue
|
||||
colorCount = colorCount + 1
|
||||
}
|
||||
}
|
||||
|
||||
if (targetStack == null) return null
|
||||
|
||||
if (targetItem == targetStack.getItem) {
|
||||
if (ItemColorizer.hasColor(targetStack)) {
|
||||
val itemColor = ItemColorizer.getColor(targetStack)
|
||||
val red = (itemColor >> 16 & 255).toFloat / 255.0F
|
||||
val green = (itemColor >> 8 & 255).toFloat / 255.0F
|
||||
val blue = (itemColor & 255).toFloat / 255.0F
|
||||
maximum = (maximum.toFloat + Math.max(red, Math.max(green, blue)) * 255.0F).toInt
|
||||
color(0) = (color(0).toFloat + red * 255.0F).toInt
|
||||
color(1) = (color(1).toFloat + green * 255.0F).toInt
|
||||
color(2) = (color(2).toFloat + blue * 255.0F).toInt
|
||||
colorCount = colorCount + 1
|
||||
}
|
||||
} else if (sourceItems.contains(targetStack.getItem)) {
|
||||
targetStack = new ItemStack(targetItem, targetStack.stackSize, targetStack.getItemDamage)
|
||||
}
|
||||
|
||||
var red = color(0) / colorCount
|
||||
var green = color(1) / colorCount
|
||||
var blue = color(2) / colorCount
|
||||
val max = maximum.toFloat / colorCount.toFloat
|
||||
val div = Math.max(red, Math.max(green, blue)).toFloat
|
||||
red = (red.toFloat * max / div).toInt
|
||||
green = (green.toFloat * max / div).toInt
|
||||
blue = (blue.toFloat * max / div).toInt
|
||||
ItemColorizer.setColor(targetStack, (red << 16) | (green << 8) | blue)
|
||||
targetStack
|
||||
}
|
||||
|
||||
override def getRecipeSize = 10
|
||||
|
||||
override def getRecipeOutput = null
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package li.cil.oc.common.recipe
|
||||
|
||||
import li.cil.oc.util.ItemColorizer
|
||||
import net.minecraft.init.Items
|
||||
import net.minecraft.inventory.InventoryCrafting
|
||||
import net.minecraft.item.crafting.IRecipe
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.world.World
|
||||
|
||||
/**
|
||||
* @author Vexatos
|
||||
*/
|
||||
class DecolorizeRecipe(target: Item) extends IRecipe {
|
||||
val targetItem = target
|
||||
|
||||
override def matches(crafting: InventoryCrafting, world: World): Boolean = {
|
||||
val stacks = (0 until crafting.getSizeInventory).flatMap(i => Option(crafting.getStackInSlot(i)))
|
||||
val targets = stacks.filter(stack => stack.getItem == targetItem)
|
||||
val other = stacks.filterNot(targets.contains)
|
||||
targets.size == 1 && other.size == 1 && other.forall(_.getItem == Items.water_bucket)
|
||||
}
|
||||
|
||||
override def getCraftingResult(crafting: InventoryCrafting): ItemStack = {
|
||||
var targetStack: ItemStack = null
|
||||
|
||||
(0 until crafting.getSizeInventory).flatMap(i => Option(crafting.getStackInSlot(i))).foreach { stack =>
|
||||
if (stack.getItem == targetItem) {
|
||||
targetStack = stack.copy()
|
||||
targetStack.stackSize = 1
|
||||
} else if (stack.getItem != Items.water_bucket) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
if (targetStack == null) return null
|
||||
|
||||
ItemColorizer.removeColor(targetStack)
|
||||
targetStack
|
||||
}
|
||||
|
||||
override def getRecipeSize = 10
|
||||
|
||||
override def getRecipeOutput = null
|
||||
}
|
@ -89,6 +89,8 @@ object Recipes {
|
||||
def init() {
|
||||
RecipeSorter.register(Settings.namespace + "extshaped", classOf[ExtendedShapedOreRecipe], Category.SHAPED, "after:forge:shapedore")
|
||||
RecipeSorter.register(Settings.namespace + "extshapeless", classOf[ExtendedShapelessOreRecipe], Category.SHAPELESS, "after:forge:shapelessore")
|
||||
RecipeSorter.register(Settings.namespace + "colorizer", classOf[ColorizeRecipe], Category.SHAPELESS, "after:forge:shapelessore")
|
||||
RecipeSorter.register(Settings.namespace + "decolorizer", classOf[DecolorizeRecipe], Category.SHAPELESS, "after:oc:decolorizer")
|
||||
|
||||
for ((name, stack) <- oreDictEntries) {
|
||||
if (!OreDictionary.getOres(name).contains(stack)) {
|
||||
@ -322,6 +324,10 @@ object Recipes {
|
||||
api.Items.get(Constants.BlockName.AccessPoint).createItemStack(1))
|
||||
GameRegistry.addShapelessRecipe(api.Items.get(Constants.BlockName.Relay).createItemStack(1),
|
||||
api.Items.get(Constants.BlockName.Switch).createItemStack(1))
|
||||
|
||||
// Hover Boot dyeing
|
||||
GameRegistry.addRecipe(new ColorizeRecipe(api.Items.get(Constants.ItemName.HoverBoots).item()))
|
||||
GameRegistry.addRecipe(new DecolorizeRecipe(api.Items.get(Constants.ItemName.HoverBoots).item()))
|
||||
}
|
||||
catch {
|
||||
case e: Throwable => OpenComputers.log.error("Error parsing recipes, you may not be able to craft any items from this mod!", e)
|
||||
|
47
src/main/scala/li/cil/oc/util/ItemColorizer.scala
Normal file
47
src/main/scala/li/cil/oc/util/ItemColorizer.scala
Normal file
@ -0,0 +1,47 @@
|
||||
package li.cil.oc.util
|
||||
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
/**
|
||||
* @author asie, Vexatos
|
||||
*/
|
||||
object ItemColorizer {
|
||||
/**
|
||||
* Return whether the specified armor ItemStack has a color.
|
||||
*/
|
||||
def hasColor(stack: ItemStack): Boolean = stack.hasTagCompound && stack.getTagCompound.hasKey("display") && stack.getTagCompound.getCompoundTag("display").hasKey("color")
|
||||
|
||||
/**
|
||||
* Return the color for the specified armor ItemStack.
|
||||
*/
|
||||
def getColor(stack: ItemStack): Int = {
|
||||
val tag = stack.getTagCompound
|
||||
if (tag != null) {
|
||||
val displayTag = tag.getCompoundTag("display")
|
||||
if (displayTag == null) -1 else if (displayTag.hasKey("color")) displayTag.getInteger("color") else -1
|
||||
}
|
||||
else -1
|
||||
}
|
||||
|
||||
def removeColor(stack: ItemStack) {
|
||||
val tag = stack.getTagCompound
|
||||
if (tag != null) {
|
||||
val displayTag = tag.getCompoundTag("display")
|
||||
if (displayTag.hasKey("color")) displayTag.removeTag("color")
|
||||
}
|
||||
}
|
||||
|
||||
def setColor(stack: ItemStack, color: Int) {
|
||||
var tag = stack.getTagCompound
|
||||
if (tag == null) {
|
||||
tag = new NBTTagCompound
|
||||
stack.setTagCompound(tag)
|
||||
}
|
||||
val displayTag = tag.getCompoundTag("display")
|
||||
if (!tag.hasKey("display")) {
|
||||
tag.setTag("display", displayTag)
|
||||
}
|
||||
displayTag.setInteger("color", color)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user