mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 18:30:27 -04:00
Added new command, /oc_preventDisassembling (alias: /oc_nodis), which will mark the currently held item so that the disassembler will not work for it. Closes #875.
This commit is contained in:
parent
d870d376aa
commit
4edeb0a1b8
@ -93,7 +93,7 @@ class Disassembler extends traits.Environment with traits.PowerAcceptor with tra
|
||||
|
||||
def disassemble(stack: ItemStack, instant: Boolean = false) {
|
||||
// Validate the item, never trust Minecraft / other Mods on anything!
|
||||
if (stack != null && isItemValidForSlot(0, stack)) {
|
||||
if (isItemValidForSlot(0, stack)) {
|
||||
val ingredients = ItemUtils.getIngredients(stack)
|
||||
DisassemblerTemplates.select(stack) match {
|
||||
case Some(template) =>
|
||||
@ -158,8 +158,11 @@ class Disassembler extends traits.Environment with traits.PowerAcceptor with tra
|
||||
override def getInventoryStackLimit = 64
|
||||
|
||||
override def isItemValidForSlot(i: Int, stack: ItemStack) =
|
||||
((Settings.get.disassembleAllTheThings || api.Items.get(stack) != null) && ItemUtils.getIngredients(stack).nonEmpty) ||
|
||||
DisassemblerTemplates.select(stack) != None
|
||||
allowDisassembling(stack) &&
|
||||
(((Settings.get.disassembleAllTheThings || api.Items.get(stack) != null) && ItemUtils.getIngredients(stack).nonEmpty) ||
|
||||
DisassemblerTemplates.select(stack) != None)
|
||||
|
||||
private def allowDisassembling(stack: ItemStack) = stack != null && (!stack.hasTagCompound || !stack.getTagCompound.getBoolean(Settings.namespace + "undisassemblable"))
|
||||
|
||||
override def setInventorySlotContents(slot: Int, stack: ItemStack): Unit = {
|
||||
super.setInventorySlotContents(slot, stack)
|
||||
|
@ -4,6 +4,9 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent
|
||||
import li.cil.oc.Settings
|
||||
import net.minecraft.command.CommandBase
|
||||
import net.minecraft.command.ICommandSender
|
||||
import net.minecraft.command.WrongUsageException
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
import scala.collection.convert.wrapAsJava._
|
||||
import scala.collection.mutable
|
||||
@ -11,6 +14,7 @@ import scala.collection.mutable
|
||||
object CommandHandler {
|
||||
def register(e: FMLServerStartingEvent) {
|
||||
e.registerServerCommand(WirelessRenderingCommand)
|
||||
e.registerServerCommand(NonDisassemblyAgreementCommand)
|
||||
}
|
||||
|
||||
// OP levels for reference:
|
||||
@ -35,6 +39,39 @@ object CommandHandler {
|
||||
override def getRequiredPermissionLevel = 2
|
||||
}
|
||||
|
||||
object NonDisassemblyAgreementCommand extends SimpleCommand("oc_preventDisassembling") {
|
||||
aliases += "oc_nodis"
|
||||
aliases += "oc_prevdis"
|
||||
|
||||
override def getCommandUsage(source: ICommandSender) = name + " <boolean>"
|
||||
|
||||
override def processCommand(source: ICommandSender, command: Array[String]) {
|
||||
source match {
|
||||
case player: EntityPlayer =>
|
||||
val stack = player.getHeldItem
|
||||
if (stack != null) {
|
||||
if (!stack.hasTagCompound) {
|
||||
stack.setTagCompound(new NBTTagCompound())
|
||||
}
|
||||
val nbt = stack.getTagCompound
|
||||
val preventDisassembly =
|
||||
if (command != null && command.length > 0)
|
||||
CommandBase.parseBoolean(source, command(0))
|
||||
else
|
||||
!nbt.getBoolean(Settings.namespace + "undisassemblable")
|
||||
if (preventDisassembly)
|
||||
nbt.setBoolean(Settings.namespace + "undisassemblable", true)
|
||||
else
|
||||
nbt.removeTag(Settings.namespace + "undisassemblable")
|
||||
if (nbt.hasNoTags) stack.setTagCompound(null)
|
||||
}
|
||||
case _ => throw new WrongUsageException("Can only be used by players.")
|
||||
}
|
||||
}
|
||||
|
||||
override def getRequiredPermissionLevel = 2
|
||||
}
|
||||
|
||||
abstract class SimpleCommand(val name: String) extends CommandBase {
|
||||
protected var aliases = mutable.ListBuffer.empty[String]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user