diff --git a/src/main/scala/net/bdew/ae2stuff/items/AdvWirelessKit.scala b/src/main/scala/net/bdew/ae2stuff/items/AdvWirelessKit.scala index db318e8..6037788 100644 --- a/src/main/scala/net/bdew/ae2stuff/items/AdvWirelessKit.scala +++ b/src/main/scala/net/bdew/ae2stuff/items/AdvWirelessKit.scala @@ -29,6 +29,9 @@ object AdvWirelessKit with AdvItemLocationStore { setMaxStackSize(1) + val MODE_QUEUING = 0; + val MODE_BINDING = 1; + def checkSecurity(t1: TileWireless, t2: TileWireless, p: EntityPlayer) = { val pid = Security.getPlayerId(p) Security.playerHasPermission( @@ -51,7 +54,7 @@ object AdvWirelessKit import net.bdew.lib.helpers.ChatHelper._ if (!world.isRemote && player.isSneaking) { toggleMode(stack) - if (getMode(stack) == 0) { + if (getMode(stack) == MODE_QUEUING) { player.addChatMessage( L("ae2stuff.wireless.advtool.queueing.activated").setColor( Color.GREEN @@ -84,13 +87,13 @@ object AdvWirelessKit if (!world.isRemote) { if (player.isSneaking) { toggleMode(stack) - if (getMode(stack) == 0) { + if (getMode(stack) == MODE_QUEUING) { player.addChatMessage( L("ae2stuff.wireless.advtool.queueing.activated").setColor( Color.GREEN ) ) - } else { + } else if (getMode(stack) == MODE_BINDING) { player.addChatMessage( L("ae2stuff.wireless.advtool.binding.activated").setColor( Color.GREEN @@ -112,7 +115,7 @@ object AdvWirelessKit player.addChatMessage( L("ae2stuff.wireless.tool.security.player").setColor(Color.RED) ) - } else if (getMode(stack) == 0) { + } else if (getMode(stack) == MODE_QUEUING) { addLocation(stack, pos, world.provider.dimensionId) player.addChatMessage( L( @@ -122,7 +125,7 @@ object AdvWirelessKit pos.z.toString ).setColor(Color.GREEN) ) - } else if (getMode(stack) == 1) { + } else if (getMode(stack) == MODE_BINDING) { if (hasLocation(stack)) { // Have other location - start connecting val otherPos = getNextLocation(stack) @@ -183,6 +186,7 @@ object AdvWirelessKit ) & ": " & e.getMessage).setColor(Color.RED) ) tile.doUnlink() + print("Failed to link wireless connector: " + e) } } popLocation(stack) @@ -224,7 +228,7 @@ object AdvWirelessKit ) ) } - if (getMode(stack) == 0) { + if (getMode(stack) == MODE_QUEUING) { list.add(Misc.toLocal("ae2stuff.wireless.advtool.queueing")) if (getLocations(stack).tagCount() == 0) { list.add(Misc.toLocal("ae2stuff.wireless.advtool.queueing.empty")) @@ -235,7 +239,7 @@ object AdvWirelessKit list.add(loc.x + "," + loc.y + "," + loc.z) } } - } else { + } else if (getMode(stack) == MODE_BINDING) { list.add(Misc.toLocal("ae2stuff.wireless.advtool.binding")) if (getLocations(stack).tagCount() == 0) { list.add(Misc.toLocal("ae2stuff.wireless.advtool.binding.empty")) diff --git a/src/main/scala/net/bdew/ae2stuff/items/ItemWirelessKit.scala b/src/main/scala/net/bdew/ae2stuff/items/ItemWirelessKit.scala index 4819ee5..bedfc32 100644 --- a/src/main/scala/net/bdew/ae2stuff/items/ItemWirelessKit.scala +++ b/src/main/scala/net/bdew/ae2stuff/items/ItemWirelessKit.scala @@ -131,6 +131,7 @@ object ItemWirelessKit ) & ": " & e.getMessage).setColor(Color.RED) ) tile.doUnlink() + print("Failed to link wireless connector: " + e) } } clearLocation(stack) diff --git a/src/main/scala/net/bdew/ae2stuff/misc/AdvItemLocationStore.scala b/src/main/scala/net/bdew/ae2stuff/misc/AdvItemLocationStore.scala index 6b64fb9..1d5683a 100644 --- a/src/main/scala/net/bdew/ae2stuff/misc/AdvItemLocationStore.scala +++ b/src/main/scala/net/bdew/ae2stuff/misc/AdvItemLocationStore.scala @@ -12,17 +12,21 @@ package net.bdew.ae2stuff.misc import net.bdew.lib.block.BlockRef import net.bdew.lib.nbt.NBT import net.minecraft.item.{Item, ItemStack} -import net.minecraft.nbt.NBTTagCompound +import net.minecraft.nbt.{NBTBase, NBTTagCompound} trait AdvItemLocationStore extends Item { + import net.bdew.ae2stuff.items.AdvWirelessKit.MODE_QUEUING + + private val COMPOUND_TAG = NBTBase.NBTTypes.indexOf("COMPOUND") + def addLocation(stack: ItemStack, loc: BlockRef, dimension: Int): Boolean = { if (!stack.hasTagCompound) stack.setTagCompound(new NBTTagCompound) val tag = stack.getTagCompound if (tag.hasKey("dim") && tag.getInteger("dim") != dimension) { false } - val locList = tag.getTagList("loc", 10) + val locList = tag.getTagList("loc", COMPOUND_TAG) for (i <- 0 until locList.tagCount()) { val tag = locList.getCompoundTagAt(i) val pos = BlockRef.fromNBT(tag) @@ -33,8 +37,6 @@ trait AdvItemLocationStore extends Item { locList.appendTag(NBT.from(loc.writeToNBT _)) tag.setTag("loc", locList) tag.setInteger("dim", dimension) - print("Added location") - print("locations: " + locList.tagCount()) true } @@ -42,11 +44,11 @@ trait AdvItemLocationStore extends Item { if (!stack.hasTagCompound) stack.setTagCompound(new NBTTagCompound) val tag = stack.getTagCompound if (tag.hasKey("loc")) { - val locList = tag.getTagList("loc", 10) + val locList = tag.getTagList("loc", COMPOUND_TAG) locList } else { tag.setTag("loc", new NBTTagCompound) - tag.getTagList("loc", 10) + tag.getTagList("loc", COMPOUND_TAG) } } @@ -58,7 +60,7 @@ trait AdvItemLocationStore extends Item { .hasKey("loc") ) { // check if list is not empty - val loc = stack.getTagCompound.getTagList("loc", 10) + val loc = stack.getTagCompound.getTagList("loc", COMPOUND_TAG) if (loc.tagCount() > 0) { return true } @@ -68,7 +70,7 @@ trait AdvItemLocationStore extends Item { def getNextLocation(stack: ItemStack): BlockRef = BlockRef.fromNBT( - stack.getTagCompound.getTagList("loc", 10).getCompoundTagAt(0) + stack.getTagCompound.getTagList("loc", COMPOUND_TAG).getCompoundTagAt(0) ) def getDimension(stack: ItemStack): Int = @@ -77,7 +79,7 @@ trait AdvItemLocationStore extends Item { def setLocation(stack: ItemStack, loc: BlockRef, dimension: Int): Unit = { if (!stack.hasTagCompound) stack.setTagCompound(new NBTTagCompound) val tag = stack.getTagCompound - val locList = tag.getTagList("loc", 10) + val locList = tag.getTagList("loc", COMPOUND_TAG) locList.appendTag(NBT.from(loc.writeToNBT _)) tag.setTag("loc", locList) tag.setInteger("dim", dimension) @@ -85,7 +87,7 @@ trait AdvItemLocationStore extends Item { def popLocation(stack: ItemStack): BlockRef = { if (stack.hasTagCompound) { - val locList = stack.getTagCompound.getTagList("loc", 10) + val locList = stack.getTagCompound.getTagList("loc", COMPOUND_TAG) if (locList.tagCount() > 0) { val tag = locList.getCompoundTagAt(0) locList.removeTag(0) @@ -107,8 +109,8 @@ trait AdvItemLocationStore extends Item { if (tag.hasKey("mode")) { tag.getInteger("mode") } else { - tag.setInteger("mode", 0) - 0 + tag.setInteger("mode", MODE_QUEUING) + MODE_QUEUING } } @@ -120,8 +122,8 @@ trait AdvItemLocationStore extends Item { tag.setInteger("mode", (mode + 1) % 2) tag.getInteger("mode") } else { - tag.setInteger("mode", 0) - 0 + tag.setInteger("mode", MODE_QUEUING) + MODE_QUEUING } } }