Made Chamelium edible, closes #1001.

This commit is contained in:
Florian Nücke 2015-04-03 18:16:26 +02:00
parent 02b9c48603
commit 2ebced30eb
5 changed files with 53 additions and 1 deletions

View File

@ -1041,6 +1041,10 @@ opencomputers {
# cost is multiplied with, so 1 is a full refund, 0 disables the
# functionality (won't be able to put prints into the material input).
printRecycleRate: 0.75
# Whether Chamelium is edible or not. When eaten, it gives a (short)
# invisibility buff, and (slightly longer) blindness debuff.
chameliumEdible: true
}
# Settings for mod integration (the mod previously known as OpenComponents).

View File

@ -295,6 +295,7 @@ class Settings(val config: Config) {
val threadPriority = config.getInt("misc.threadPriority")
val maxPrintComplexity = config.getInt("misc.maxPrinterShapes")
val printRecycleRate = config.getDouble("misc.printRecycleRate")
val chameliumEdible = config.getBoolean("misc.chameliumEdible")
// ----------------------------------------------------------------------- //
// integration

View File

@ -1,3 +1,32 @@
package li.cil.oc.common.item
class Chamelium(val parent: Delegator) extends Delegate
import li.cil.oc.Settings
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.EnumAction
import net.minecraft.item.ItemStack
import net.minecraft.potion.Potion
import net.minecraft.potion.PotionEffect
import net.minecraft.world.World
class Chamelium(val parent: Delegator) extends Delegate {
override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = {
if (Settings.get.chameliumEdible) {
player.setItemInUse(stack, getMaxItemUseDuration(stack))
}
stack
}
override def getItemUseAction(stack: ItemStack): EnumAction = EnumAction.eat
override def getMaxItemUseDuration(stack: ItemStack): Int = 32
override def onEaten(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = {
if (!world.isRemote) {
player.addPotionEffect(new PotionEffect(Potion.invisibility.id, 100, 0))
player.addPotionEffect(new PotionEffect(Potion.blindness.id, 200, 0))
}
stack.stackSize -= 1
if (stack.stackSize > 0) stack
else null
}
}

View File

@ -14,6 +14,7 @@ import li.cil.oc.util.Rarity
import li.cil.oc.util.Tooltip
import net.minecraft.entity.Entity
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.EnumAction
import net.minecraft.item.ItemStack
import net.minecraft.world.World
@ -55,8 +56,12 @@ trait Delegate {
stack
}
def getItemUseAction(stack: ItemStack): EnumAction = EnumAction.none
def getMaxItemUseDuration(stack: ItemStack) = 0
def onEaten(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = stack
def onPlayerStoppedUsing(stack: ItemStack, player: EntityPlayer, duration: Int) {}
def update(stack: ItemStack, world: World, player: Entity, slot: Int, selected: Boolean) {}

View File

@ -14,6 +14,7 @@ import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.entity.Entity
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.EnumAction
import net.minecraft.item.EnumRarity
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
@ -124,6 +125,18 @@ class Delegator extends Item {
// ----------------------------------------------------------------------- //
override def onEaten(stack: ItemStack, world: World, player: EntityPlayer): ItemStack =
subItem(stack) match {
case Some(subItem) => subItem.onEaten(stack, world, player)
case _ => super.onEaten(stack, world, player)
}
override def getItemUseAction(stack: ItemStack): EnumAction =
subItem(stack) match {
case Some(subItem) => subItem.getItemUseAction(stack)
case _ => super.getItemUseAction(stack)
}
override def getMaxItemUseDuration(stack: ItemStack): Int =
subItem(stack) match {
case Some(subItem) => subItem.getMaxItemUseDuration(stack)