From 4b354551a095f63d9bcc0b09255a21ecae9e1d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 30 Mar 2015 16:45:45 +0200 Subject: [PATCH 1/7] Fixed wrong UV mapping on 3D prints (in particular the item renderer). --- .../client/renderer/block/BlockRenderer.scala | 3 +- .../client/renderer/item/ItemRenderer.scala | 32 +++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/scala/li/cil/oc/client/renderer/block/BlockRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/block/BlockRenderer.scala index cfc0394d7..092561ab4 100644 --- a/src/main/scala/li/cil/oc/client/renderer/block/BlockRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/block/BlockRenderer.scala @@ -141,7 +141,8 @@ object BlockRenderer extends ISimpleBlockRenderingHandler { } // The texture flip this works around only seems to occur for blocks with custom block renderers? - def patchedRenderer(renderer: RenderBlocks, block: Block) = if (block.isInstanceOf[Hologram] || block.isInstanceOf[Printer]) { + def patchedRenderer(renderer: RenderBlocks, block: Block) = + if (block.isInstanceOf[Hologram] || block.isInstanceOf[Printer] || block.isInstanceOf[Print]) { PatchedRenderBlocks.blockAccess = renderer.blockAccess PatchedRenderBlocks.overrideBlockTexture = renderer.overrideBlockTexture PatchedRenderBlocks.flipTexture = renderer.flipTexture diff --git a/src/main/scala/li/cil/oc/client/renderer/item/ItemRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/item/ItemRenderer.scala index d39ee1675..b1e497b0b 100644 --- a/src/main/scala/li/cil/oc/client/renderer/item/ItemRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/item/ItemRenderer.scala @@ -258,24 +258,24 @@ object ItemRenderer extends IItemRenderer { // Front. GL11.glNormal3f(0, 0, 1) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minX * 16), texture.getInterpolatedV(bounds.minY * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minX * 16), texture.getInterpolatedV(16 - bounds.minY * 16)) GL11.glVertex3d(bounds.minX, bounds.minY, bounds.maxZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxX * 16), texture.getInterpolatedV(bounds.minY * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxX * 16), texture.getInterpolatedV(16 - bounds.minY * 16)) GL11.glVertex3d(bounds.maxX, bounds.minY, bounds.maxZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxX * 16), texture.getInterpolatedV(bounds.maxY * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxX * 16), texture.getInterpolatedV(16 - bounds.maxY * 16)) GL11.glVertex3d(bounds.maxX, bounds.maxY, bounds.maxZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minX * 16), texture.getInterpolatedV(bounds.maxY * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minX * 16), texture.getInterpolatedV(16 - bounds.maxY * 16)) GL11.glVertex3d(bounds.minX, bounds.maxY, bounds.maxZ) // Back. GL11.glNormal3f(0, 0, -1) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxX * 16), texture.getInterpolatedV(bounds.minY * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxX * 16), texture.getInterpolatedV(16 - bounds.minY * 16)) GL11.glVertex3d(bounds.maxX, bounds.minY, bounds.minZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minX * 16), texture.getInterpolatedV(bounds.minY * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minX * 16), texture.getInterpolatedV(16 - bounds.minY * 16)) GL11.glVertex3d(bounds.minX, bounds.minY, bounds.minZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minX * 16), texture.getInterpolatedV(bounds.maxY * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minX * 16), texture.getInterpolatedV(16 - bounds.maxY * 16)) GL11.glVertex3d(bounds.minX, bounds.maxY, bounds.minZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxX * 16), texture.getInterpolatedV(bounds.maxY * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxX * 16), texture.getInterpolatedV(16 - bounds.maxY * 16)) GL11.glVertex3d(bounds.maxX, bounds.maxY, bounds.minZ) // Top. @@ -302,24 +302,24 @@ object ItemRenderer extends IItemRenderer { // Left. GL11.glNormal3f(1, 0, 0) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxY * 16), texture.getInterpolatedV(bounds.maxZ * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxZ * 16), texture.getInterpolatedV(16 - bounds.maxY * 16)) GL11.glVertex3d(bounds.maxX, bounds.maxY, bounds.maxZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minY * 16), texture.getInterpolatedV(bounds.maxZ * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxZ * 16), texture.getInterpolatedV(16 - bounds.minY * 16)) GL11.glVertex3d(bounds.maxX, bounds.minY, bounds.maxZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minY * 16), texture.getInterpolatedV(bounds.minZ * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minZ * 16), texture.getInterpolatedV(16 - bounds.minY * 16)) GL11.glVertex3d(bounds.maxX, bounds.minY, bounds.minZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxY * 16), texture.getInterpolatedV(bounds.minZ * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minZ * 16), texture.getInterpolatedV(16 - bounds.maxY * 16)) GL11.glVertex3d(bounds.maxX, bounds.maxY, bounds.minZ) // Right. GL11.glNormal3f(-1, 0, 0) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minY * 16), texture.getInterpolatedV(bounds.maxZ * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxZ * 16), texture.getInterpolatedV(16 - bounds.minY * 16)) GL11.glVertex3d(bounds.minX, bounds.minY, bounds.maxZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxY * 16), texture.getInterpolatedV(bounds.maxZ * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxZ * 16), texture.getInterpolatedV(16 - bounds.maxY * 16)) GL11.glVertex3d(bounds.minX, bounds.maxY, bounds.maxZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.maxY * 16), texture.getInterpolatedV(bounds.minZ * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minZ * 16), texture.getInterpolatedV(16 - bounds.maxY * 16)) GL11.glVertex3d(bounds.minX, bounds.maxY, bounds.minZ) - GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minY * 16), texture.getInterpolatedV(bounds.minZ * 16)) + GL11.glTexCoord2f(texture.getInterpolatedU(bounds.minZ * 16), texture.getInterpolatedV(16 - bounds.minY * 16)) GL11.glVertex3d(bounds.minX, bounds.minY, bounds.minZ) GL11.glEnd() From 6afc31b62427cfb2def1ed709cf7d2b4e42729e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 30 Mar 2015 17:34:15 +0200 Subject: [PATCH 2/7] Updated some dependencies, should close #984. Also updated Forge to allow running mods in dev env that depend on it (such as AE2). --- build.gradle | 14 +++++++------- build.properties | 14 +++++++------- .../oc/integration/appeng/DriverController.scala | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 7adcd9391..553ff73ac 100644 --- a/build.gradle +++ b/build.gradle @@ -118,27 +118,27 @@ repositories { ivy { name 'CoFHLib' - artifactPattern "http://addons.cursecdn.com/files/${config.cofhlib.cf}/[module]-[revision].[ext]" + artifactPattern "http://addons-origin.cursecdn.com/files/${config.cofhlib.cf}/[module]-[revision].[ext]" } ivy { name 'MineFactoryReloaded' - artifactPattern "http://addons.cursecdn.com/files/${config.mfr.cf}/[module]-[revision].[ext]" + artifactPattern "http://addons-origin.cursecdn.com/files/${config.mfr.cf}/[module]-[revision].[ext]" } ivy { name 'ComputerCraft' - artifactPattern "http://addons.cursecdn.com/files/${config.cc.cf}/[module][revision].[ext]" + artifactPattern "http://addons-origin.cursecdn.com/files/${config.cc.cf}/[module][revision].[ext]" } ivy { name 'EnderIO' - artifactPattern "http://addons.cursecdn.com/files/${config.eio.cf}/[module]-[revision].[ext]" + artifactPattern "http://addons-origin.cursecdn.com/files/${config.eio.cf}/[module]-[revision].[ext]" } ivy { name 'Railcraft' - artifactPattern "http://addons.cursecdn.com/files/${config.rc.cf}/[module]_[revision].[ext]" + artifactPattern "http://addons-origin.cursecdn.com/files/${config.rc.cf}/[module]_[revision].[ext]" } ivy { name 'BloodMagic' - artifactPattern "http://addons.cursecdn.com/files/${config.bloodmagic.cf}/[module]-${config.minecraft.version}-[revision].[ext]" + artifactPattern "http://addons-origin.cursecdn.com/files/${config.bloodmagic.cf}/[module]-${config.minecraft.version}-[revision].[ext]" } } @@ -149,7 +149,7 @@ configurations { } dependencies { - provided "api:rotarycraft:${config.rotc.version}" + provided "appeng:RotaryCraft:${config.rotc.version}:api" provided "appeng:appliedenergistics2:${config.ae2.version}:dev" provided "codechicken:CodeChickenLib:${config.minecraft.version}-${config.ccl.version}:dev" provided "codechicken:EnderStorage:${config.minecraft.version}-${config.es.version}:dev" diff --git a/build.properties b/build.properties index 0708e5f16..4db53329a 100644 --- a/build.properties +++ b/build.properties @@ -1,18 +1,18 @@ minecraft.version=1.7.10 -forge.version=10.13.2.1236 +forge.version=10.13.2.1291 oc.version=1.5.4 oc.subversion=dev -ae2.version=rv1-stable-1 +ae2.version=rv2-beta-22 bc.version=6.2.6 bloodmagic.cf=2223/203 bloodmagic.version=1.3.0a-1 cc.cf=2216/236 cc.version=1.65 ccl.version=1.1.1.104 -cofhlib.cf=2218/257 -cofhlib.version=[1.7.10]1.0.0B7-dev-29 +cofhlib.cf=2230/207 +cofhlib.version=[1.7.10]1.0.0RC7-127 eio.cf=2219/296 eio.version=1.7.10-2.2.1.276 es.version=1.4.5.24 @@ -24,14 +24,14 @@ gt.version=5.04.06 ic2.version=2.2.654-experimental mekanism.build=5 mekanism.version=7.1.2 -mfr.cf=2213/46 -mfr.version=[1.7.10]2.8.0RC3-dev-591 +mfr.cf=2229/626 +mfr.version=[1.7.10]2.8.0RC8-86 nei.version=1.0.3.57 projred.version=4.5.8.59 rc.cf=2219/321 rc.version=1.7.10-9.4.0.0 redlogic.version=59.0.3 -rotc.version=1 +rotc.version=V5c tmech.version=75.0afb56c re.version=3.0.0.342 waila.version=1.5.8a diff --git a/src/main/scala/li/cil/oc/integration/appeng/DriverController.scala b/src/main/scala/li/cil/oc/integration/appeng/DriverController.scala index e6b5bb58c..3b60ab7f0 100644 --- a/src/main/scala/li/cil/oc/integration/appeng/DriverController.scala +++ b/src/main/scala/li/cil/oc/integration/appeng/DriverController.scala @@ -9,7 +9,6 @@ import appeng.api.networking.security.MachineSource import appeng.api.storage.data.IAEItemStack import appeng.me.helpers.IGridProxyable import appeng.tile.misc.TileInterface -import appeng.tile.networking.TileController import appeng.util.item.AEItemStack import com.google.common.collect.ImmutableSet import li.cil.oc.OpenComputers @@ -44,10 +43,11 @@ import scala.language.existentials object DriverController extends DriverTileEntity with EnvironmentAware { private type AETile = TileEntity with IGridProxyable with IActionHost - def getTileEntityClass = { + def getTileEntityClass: Class[_] = { if (AEApi.instance != null && AEApi.instance.blocks != null) { if (AEApi.instance.blocks.blockController != null && AEApi.instance.blocks.blockController.item != null) - classOf[TileController] + // Not classOf[TileController] because that derps the compiler when it tries to resolve the class (says can't find API classes from RotaryCraft). + Class.forName("appeng.tile.networking.TileController") else classOf[TileInterface] } From 20715298e07f8d4bedd9fa0690901e1505c7d145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 30 Mar 2015 17:57:27 +0200 Subject: [PATCH 3/7] Re-enabling AE2 integration for newer version, because issue seems to be fixed as of version rv2-beta-22. --- src/main/scala/li/cil/oc/integration/Mods.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/li/cil/oc/integration/Mods.scala b/src/main/scala/li/cil/oc/integration/Mods.scala index db071c751..72be050af 100644 --- a/src/main/scala/li/cil/oc/integration/Mods.scala +++ b/src/main/scala/li/cil/oc/integration/Mods.scala @@ -19,7 +19,7 @@ object Mods { def All = knownMods.clone() - val AppliedEnergistics2 = new SimpleMod(IDs.AppliedEnergistics2, version = "@[rv1,rv2-beta-19)", providesPower = true) + val AppliedEnergistics2 = new SimpleMod(IDs.AppliedEnergistics2, version = "@[rv1,)", providesPower = true) val BattleGear2 = new SimpleMod(IDs.BattleGear2) val BloodMagic = new SimpleMod(IDs.BloodMagic) val BuildCraft = new SimpleMod(IDs.BuildCraft) From b2a0a8d90c755f467a6780c97527c3808c35315a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 30 Mar 2015 18:33:19 +0200 Subject: [PATCH 4/7] Updated BuildCraft dependency. --- build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.properties b/build.properties index 4db53329a..9877f81e3 100644 --- a/build.properties +++ b/build.properties @@ -5,7 +5,7 @@ oc.version=1.5.4 oc.subversion=dev ae2.version=rv2-beta-22 -bc.version=6.2.6 +bc.version=6.4.5 bloodmagic.cf=2223/203 bloodmagic.version=1.3.0a-1 cc.cf=2216/236 From 4d5c923c42a9a4f42489acd8a8b1367fd667a3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 30 Mar 2015 23:36:27 +0200 Subject: [PATCH 5/7] Allow recycling prints by using them as material input for printers, closes #986. --- src/main/resources/application.conf | 6 ++ src/main/scala/li/cil/oc/Settings.scala | 1 + .../li/cil/oc/common/tileentity/Printer.scala | 75 ++++++++++++------- 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index e92ac11e8..20c4c98d9 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -1035,6 +1035,12 @@ opencomputers { # this many shapes *per state* (the reasoning being that only one state # will ever be visible at a time). maxPrinterShapes: 24 + + # How much of the material used to print a model is refunded when using + # the model to refuel a printer. This the value the original material + # 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 } # 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 2b4f54715..e83c479c6 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -294,6 +294,7 @@ class Settings(val config: Config) { val assemblerBlacklist = config.getStringList("misc.assemblerBlacklist") val threadPriority = config.getInt("misc.threadPriority") val maxPrintComplexity = config.getInt("misc.maxPrinterShapes") + val printRecycleRate = config.getDouble("misc.printRecycleRate") // ----------------------------------------------------------------------- // // integration diff --git a/src/main/scala/li/cil/oc/common/tileentity/Printer.scala b/src/main/scala/li/cil/oc/common/tileentity/Printer.scala index 1e2ff9394..7e6016d50 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Printer.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Printer.scala @@ -188,10 +188,36 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat // ----------------------------------------------------------------------- // - override def canUpdate = isServer + def computeCosts(data: PrintData) = { + val totalVolume = data.stateOn.foldLeft(0)((acc, shape) => acc + shape.bounds.volume) + data.stateOff.foldLeft(0)((acc, shape) => acc + shape.bounds.volume) + val totalSurface = data.stateOn.foldLeft(0)((acc, shape) => acc + shape.bounds.surface) + data.stateOff.foldLeft(0)((acc, shape) => acc + shape.bounds.surface) + + if (totalVolume > 0) { + val materialRequired = (totalVolume / 2) max 1 + val inkRequired = (totalSurface / 6) max 1 + + Option((materialRequired, inkRequired)) + } + else None + } + + def materialValue(stack: ItemStack) = { + if (api.Items.get(stack) == api.Items.get("chamelium")) + materialPerItem + else if (api.Items.get(stack) == api.Items.get("print")) { + val data = new PrintData(stack) + computeCosts(data) match { + case Some((materialRequired, inkRequired)) => (materialRequired * Settings.get.printRecycleRate).toInt + case _ => 0 + } + } + else 0 + } // ----------------------------------------------------------------------- // + override def canUpdate = isServer + override def updateEntity() { super.updateEntity() @@ -202,28 +228,22 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat } if (isActive && output.isEmpty && canMergeOutput) { - val totalVolume = data.stateOn.foldLeft(0)((acc, shape) => acc + shape.bounds.volume) + data.stateOff.foldLeft(0)((acc, shape) => acc + shape.bounds.volume) - val totalSurface = data.stateOn.foldLeft(0)((acc, shape) => acc + shape.bounds.surface) + data.stateOff.foldLeft(0)((acc, shape) => acc + shape.bounds.surface) + computeCosts(data) match { + case Some((materialRequired, inkRequired)) => + totalRequiredEnergy = Settings.get.printCost + requiredEnergy = totalRequiredEnergy - if (totalVolume == 0) { - isActive = false - data = new PrintData() - } - else { - val materialRequired = (totalVolume / 2) max 1 - val inkRequired = (totalSurface / 6) max 1 - - totalRequiredEnergy = Settings.get.printCost - requiredEnergy = totalRequiredEnergy - - if (amountMaterial >= materialRequired && amountInk >= inkRequired) { - amountMaterial -= materialRequired - amountInk -= inkRequired - limit -= 1 - output = Option(data.createItemStack()) - if (limit < 1) isActive = false - ServerPacketSender.sendPrinting(this, printing = true) - } + if (amountMaterial >= materialRequired && amountInk >= inkRequired) { + amountMaterial -= materialRequired + amountInk -= inkRequired + limit -= 1 + output = Option(data.createItemStack()) + if (limit < 1) isActive = false + ServerPacketSender.sendPrinting(this, printing = true) + } + case _ => + isActive = false + data = new PrintData() } } @@ -249,10 +269,11 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat ServerPacketSender.sendPrinting(this, have > 0.5 && output.isDefined) } - if (maxAmountMaterial - amountMaterial >= materialPerItem) { + val inputValue = materialValue(getStackInSlot(slotMaterial)) + if (inputValue > 0 && maxAmountMaterial - amountMaterial >= inputValue) { val material = decrStackSize(slotMaterial, 1) if (material != null) { - amountMaterial += materialPerItem + amountMaterial += inputValue } } @@ -310,9 +331,9 @@ class Printer extends traits.Environment with traits.Inventory with traits.Rotat override def getInventoryStackLimit = 64 override def isItemValidForSlot(slot: Int, stack: ItemStack) = - if (slot == 0) - api.Items.get(stack) == api.Items.get("chamelium") - else if (slot == 1) + if (slot == slotMaterial) + materialValue(stack) > 0 + else if (slot == slotInk) api.Items.get(stack) == api.Items.get("inkCartridge") else false From f4bcb0718e9e74760ee9b35c3b2414a33fc96162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 30 Mar 2015 23:50:58 +0200 Subject: [PATCH 6/7] Populate `tablet_use` info with sign text if sign upgrade is installed, closes #988. --- .../cil/oc/server/component/UpgradeSign.scala | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeSign.scala b/src/main/scala/li/cil/oc/server/component/UpgradeSign.scala index 3ac32ff77..8f181c6fa 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeSign.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeSign.scala @@ -2,12 +2,16 @@ package li.cil.oc.server.component import cpw.mods.fml.common.eventhandler.Event import li.cil.oc.Settings +import li.cil.oc.api import li.cil.oc.api.driver.EnvironmentHost import li.cil.oc.api.internal +import li.cil.oc.api.network.Message import li.cil.oc.api.prefab import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedWorld._ import net.minecraft.entity.player.EntityPlayer +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NBTTagCompound import net.minecraft.tileentity.TileEntitySign import net.minecraft.world.WorldServer import net.minecraftforge.common.MinecraftForge @@ -62,4 +66,20 @@ abstract class UpgradeSign extends prefab.ManagedEnvironment { MinecraftForge.EVENT_BUS.post(event) !(event.isCanceled || event.getResult == Event.Result.DENY) } + + override def onMessage(message: Message): Unit = { + super.onMessage(message) + if (message.name == "tablet.use") message.source.host match { + case machine: api.machine.Machine => (machine.host, message.data) match { + case (tablet: internal.Tablet, Array(nbt: NBTTagCompound, stack: ItemStack, player: EntityPlayer, blockPos: BlockPosition, side: ForgeDirection, hitX: java.lang.Float, hitY: java.lang.Float, hitZ: java.lang.Float)) => + host.world.getTileEntity(blockPos) match { + case sign: TileEntitySign => + nbt.setString("signText", sign.signText.mkString("\n")) + case _ => + } + case _ => // Ignore. + } + case _ => // Ignore. + } + } } From b021641efe2769a2b7f0eccf1fcdbbb0772c983d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Tue, 31 Mar 2015 00:30:07 +0200 Subject: [PATCH 7/7] Allow filtering items when querying lists from AE2 networks, closes #856. `me_controller.getCraftables` and `me_controller.getItemsInNetwork` now take an optional table argument. This table is a filter applied to the result. Its format is the same as item stack representations. For example, a full filter could be: ``` { damage = 0, maxDamage = 0, size = 12, maxSize = 64, hasTag = false, name = "minecraft:stick, label = "Stick" } ``` --- .../integration/appeng/DriverController.scala | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/scala/li/cil/oc/integration/appeng/DriverController.scala b/src/main/scala/li/cil/oc/integration/appeng/DriverController.scala index 3b60ab7f0..95908d166 100644 --- a/src/main/scala/li/cil/oc/integration/appeng/DriverController.scala +++ b/src/main/scala/li/cil/oc/integration/appeng/DriverController.scala @@ -25,6 +25,7 @@ import li.cil.oc.integration.ManagedTileEntityEnvironment import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.ResultWrapper._ import net.minecraft.block.Block +import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraft.tileentity.TileEntity @@ -78,10 +79,13 @@ object DriverController extends DriverTileEntity with EnvironmentAware { "coprocessors" -> cpu.getCoProcessors, "busy" -> cpu.isBusy))) - @Callback(doc = "function():table -- Get a list of known item recipes. These can be used to issue crafting requests.") + @Callback(doc = "function([filter:table]):table -- Get a list of known item recipes. These can be used to issue crafting requests.") def getCraftables(context: Context, args: Arguments): Array[AnyRef] = { + val filter = args.optTable(0, Map.empty[AnyRef, AnyRef]).collect { + case (key: String, value: AnyRef) => (key, value) + } result(tileEntity.getProxy.getStorage.getItemInventory.getStorageList. - filter(_.isCraftable).map(stack => { + filter(_.isCraftable).filter(stack => matches(stack, filter)).map(stack => { val patterns = tileEntity.getProxy.getCrafting.getCraftingFor(stack, null, 0, tileEntity.getWorldObj) val result = patterns.find(pattern => pattern.getOutputs.exists(_.isSameType(stack))) match { case Some(pattern) => pattern.getOutputs.find(_.isSameType(stack)).get @@ -91,9 +95,13 @@ object DriverController extends DriverTileEntity with EnvironmentAware { }).toArray) } - @Callback(doc = "function():table -- Get a list of the stored items in the network.") - def getItemsInNetwork(context: Context, args: Arguments): Array[AnyRef] = - result(tileEntity.getProxy.getStorage.getItemInventory.getStorageList.map(_.getItemStack).toArray) + @Callback(doc = "function([filter:table]):table -- Get a list of the stored items in the network.") + def getItemsInNetwork(context: Context, args: Arguments): Array[AnyRef] = { + val filter = args.optTable(0, Map.empty[AnyRef, AnyRef]).collect { + case (key: String, value: AnyRef) => (key, value) + } + result(tileEntity.getProxy.getStorage.getItemInventory.getStorageList.filter(stack => matches(stack, filter)).map(_.getItemStack).toArray) + } @Callback(doc = "function():table -- Get a list of the stored fluids in the network.") def getFluidsInNetwork(context: Context, args: Arguments): Array[AnyRef] = @@ -118,6 +126,17 @@ object DriverController extends DriverTileEntity with EnvironmentAware { @Callback(doc = "function():number -- Get the stored power in the network. ") def getStoredPower(context: Context, args: Arguments): Array[AnyRef] = result(tileEntity.getProxy.getEnergy.getStoredPower) + + private def matches(stack: IAEItemStack, filter: scala.collection.mutable.Map[String, AnyRef]) = { + stack != null && + filter.get("damage").forall(_.equals(stack.getItemDamage.toDouble)) && + filter.get("maxDamage").forall(_.equals(stack.getItemStack.getMaxDamage.toDouble)) && + filter.get("size").forall(_.equals(stack.getStackSize.toDouble)) && + filter.get("maxSize").forall(_.equals(stack.getItemStack.getMaxStackSize.toDouble)) && + filter.get("hasTag").forall(_.equals(stack.hasTagCompound)) && + filter.get("name").forall(_.equals(Item.itemRegistry.getNameForObject(stack.getItem))) && + filter.get("label").forall(_.equals(stack.getItemStack.getDisplayName)) + } } class Craftable(var controller: AETile, var stack: IAEItemStack) extends AbstractValue with ICraftingRequester {