diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index ec5211626..dbb7c3e1d 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -1039,6 +1039,11 @@ opencomputers { # an adapter has pretty much the same effect. enableTankDriver: false + # Whether to enable the command block driver. Enabling this allows + # computers to set and execute commands via command blocks next to + # adapter blocks. The commands are run using OC's general fake player. + enableCommandBlockDriver: false + # Whether to allow the item stack converter to push NBT data in # compressed format (GZIP'ed). This can be useful for pushing this # data back to other callbacks. However, given a sophisticated diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index 6d88581cc..6b796232a 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -298,6 +298,7 @@ class Settings(val config: Config) { // integration.vanilla val enableInventoryDriver = config.getBoolean("integration.vanilla.enableInventoryDriver") val enableTankDriver = config.getBoolean("integration.vanilla.enableTankDriver") + val enableCommandBlockDriver = config.getBoolean("integration.vanilla.enableCommandBlockDriver") val allowItemStackNBTTags = config.getBoolean("integration.vanilla.allowItemStackNBTTags") // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/integration/vanilla/DriverRecordPlayer.java b/src/main/scala/li/cil/oc/integration/vanilla/DriverRecordPlayer.java index c93796c2e..fb32bd7a2 100644 --- a/src/main/scala/li/cil/oc/integration/vanilla/DriverRecordPlayer.java +++ b/src/main/scala/li/cil/oc/integration/vanilla/DriverRecordPlayer.java @@ -11,6 +11,7 @@ import li.cil.oc.integration.ManagedTileEntityEnvironment; import net.minecraft.block.Block; import net.minecraft.block.BlockJukebox; import net.minecraft.init.Blocks; +import net.minecraft.item.Item; import net.minecraft.item.ItemRecord; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; @@ -57,5 +58,22 @@ public final class DriverRecordPlayer extends DriverTileEntity implements Enviro } return new Object[]{((ItemRecord) record.getItem()).getRecordNameLocal()}; } + + @Callback(doc = "function() -- Start playing the record currently in the jukebox.") + public Object[] play(final Context context, final Arguments args) { + final ItemStack record = tileEntity.func_145856_a(); + if (record == null || !(record.getItem() instanceof ItemRecord)) { + return null; + } + tileEntity.getWorldObj().playAuxSFXAtEntity(null, 1005, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, Item.getIdFromItem(record.getItem())); + return new Object[]{true}; + } + + @Callback(doc = "function() -- Stop playing the record currently in the jukebox.") + public Object[] stop(final Context context, final Arguments args) { + tileEntity.getWorldObj().playAuxSFX(1005, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, 0); + tileEntity.getWorldObj().playRecord(null, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); + return null; + } } } diff --git a/src/main/scala/li/cil/oc/integration/vanilla/ModVanilla.scala b/src/main/scala/li/cil/oc/integration/vanilla/ModVanilla.scala index 27550d357..cf98113bf 100644 --- a/src/main/scala/li/cil/oc/integration/vanilla/ModVanilla.scala +++ b/src/main/scala/li/cil/oc/integration/vanilla/ModVanilla.scala @@ -11,7 +11,6 @@ object ModVanilla extends ModProxy { def initialize() { Driver.add(new DriverBeacon) Driver.add(new DriverBrewingStand) - Driver.add(new DriverCommandBlock) Driver.add(new DriverComparator) Driver.add(new DriverFurnace) Driver.add(new DriverMobSpawner) @@ -25,6 +24,9 @@ object ModVanilla extends ModProxy { Driver.add(new DriverFluidHandler) Driver.add(new DriverFluidTank) } + if (Settings.get.enableCommandBlockDriver) { + Driver.add(new DriverCommandBlock) + } Driver.add(ConverterFluidStack) Driver.add(ConverterFluidTankInfo) diff --git a/src/main/scala/li/cil/oc/server/component/DebugCard.scala b/src/main/scala/li/cil/oc/server/component/DebugCard.scala index fdfc7e6be..da2e68985 100644 --- a/src/main/scala/li/cil/oc/server/component/DebugCard.scala +++ b/src/main/scala/li/cil/oc/server/component/DebugCard.scala @@ -424,6 +424,20 @@ object DebugCard { } } + @Callback(doc = """function(x:number, y:number, z:number, slot:number[, count:number]):number - Reduce the size of an item stack in the inventory at the specified location.""") + def removeItem(context: Context, args: Arguments): Array[AnyRef] = { + val position = BlockPosition(args.checkDouble(0), args.checkDouble(1), args.checkDouble(2), world) + InventoryUtils.inventoryAt(position) match { + case Some(inventory) => + val slot = args.checkSlot(inventory, 3) + val count = args.optInteger(4, inventory.getInventoryStackLimit) + val removed = inventory.decrStackSize(slot, count) + if (removed == null) result(0) + else result(removed.stackSize) + case _ => result(null, "no inventory") + } + } + // ----------------------------------------------------------------------- // override def load(nbt: NBTTagCompound) {