diff --git a/README.md b/README.md index cbd0e6763..59d3b541c 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Alternatively, leave out the `api` classifier and you can build against the dev If you have any questions, please do not hesitate to ask, either in the [forums][] or in the [IRC][irc]! ### OpenComputers -Want to tinker with the mod itself? Here is how - for IntelliJ IDEA users. For eclipse I assume the process will be similar. +Want to tinker with the mod itself? Here is how - for IntelliJ IDEA users. **Important** - Make sure you have the Gradle plugin enabled in IDEA (File->Settings->Plugins). @@ -84,6 +84,8 @@ to create an IntellJ IDEA project. Open the project and you will be asked to *import the Gradle project* (check your Event Log if you missed the pop-up). **Do so**. This will configure additionally referenced libraries. +In the case you wish to use Eclipse rather than IDEA, the process is mostly the same, except you must run `gradlew eclipse` rather than `gradlew idea`. + [api]: https://github.com/MightyPirates/OpenComputers/tree/master-MC1.7.10/src/main/java/li/cil/oc/api diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 20c4c98d9..db5fecc34 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -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). diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index 79a4a2f59..07a2b2759 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -296,6 +296,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 diff --git a/src/main/scala/li/cil/oc/common/item/Chamelium.scala b/src/main/scala/li/cil/oc/common/item/Chamelium.scala index 0bcb54cbc..281d258e7 100644 --- a/src/main/scala/li/cil/oc/common/item/Chamelium.scala +++ b/src/main/scala/li/cil/oc/common/item/Chamelium.scala @@ -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 + } +} diff --git a/src/main/scala/li/cil/oc/common/item/Delegate.scala b/src/main/scala/li/cil/oc/common/item/Delegate.scala index 2675300a1..8aaa03c5a 100644 --- a/src/main/scala/li/cil/oc/common/item/Delegate.scala +++ b/src/main/scala/li/cil/oc/common/item/Delegate.scala @@ -13,6 +13,7 @@ import li.cil.oc.util.Tooltip import net.minecraft.client.resources.model.ModelResourceLocation import net.minecraft.entity.Entity import net.minecraft.entity.player.EntityPlayer +import net.minecraft.item.EnumAction import net.minecraft.item.ItemStack import net.minecraft.util.EnumFacing import net.minecraft.world.World @@ -52,8 +53,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) {} diff --git a/src/main/scala/li/cil/oc/common/item/Delegator.scala b/src/main/scala/li/cil/oc/common/item/Delegator.scala index 09fbd27f4..1867c1fa8 100644 --- a/src/main/scala/li/cil/oc/common/item/Delegator.scala +++ b/src/main/scala/li/cil/oc/common/item/Delegator.scala @@ -11,6 +11,7 @@ import net.minecraft.client.resources.model.ModelResourceLocation 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 @@ -125,6 +126,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 = Delegator.subItem(stack) match { case Some(subItem) => subItem.getMaxItemUseDuration(stack)