From 7b390601f751675aff0c05b0e55e98e748364a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Thu, 14 Aug 2014 15:55:26 +0200 Subject: [PATCH] Slightly reworked hologram.fill(), now may take an additional param, the lower end of the interval to fill, and won't "autoclear" (will now only overwrite in that interval), which *may* break some programs. I'm so sorry. A little. --- .../cil/oc/common/tileentity/Hologram.scala | 19 ++++--- .../cil/oc/server/component/DebugCard.scala | 54 ++++++++++++------- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala b/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala index a8d26f730..1889ca8a0 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala @@ -123,18 +123,23 @@ class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment w null } - @Callback(direct = true, limit = 128, doc = """function(x:number, z:number, height:number, value:number or boolean) -- Fills a column to the specified height.""") + @Callback(direct = true, limit = 128, doc = """function(x:number, z:number[, minY:number], maxY:number, value:number or boolean) -- Fills an interval of a column with the specified value.""") def fill(computer: Context, args: Arguments): Array[AnyRef] = this.synchronized { val (x, _, z) = checkCoordinates(args, 0, -1, 1) - val height = math.min(32, math.max(0, args.checkInteger(2))) - val value = checkColor(args, 3) + val (minY, maxY, value) = + if (args.count > 4) + (math.min(32, math.max(1, args.checkInteger(2))), math.min(32, math.max(1, args.checkInteger(3))), checkColor(args, 4)) + else + (1, math.min(32, math.max(1, args.checkInteger(2))), checkColor(args, 3)) + if (minY > maxY) throw new IllegalArgumentException("interval is empty") + val mask = (0xFFFFFFFF >>> (31 - (maxY - minY))) << (minY - 1) val lbit = value & 1 val hbit = (value >>> 1) & 1 - if (lbit == 0 || height == 0) volume(x + z * width) = 0 - else volume(x + z * width) = 0xFFFFFFFF >>> (32 - height) - if (hbit == 0 || height == 0) volume(x + z * width + width * width) = 0 - else volume(x + z * width + width * width) = 0xFFFFFFFF >>> (32 - height) + if (lbit == 0 || height == 0) volume(x + z * width) &= ~mask + else volume(x + z * width) |= mask + if (hbit == 0 || height == 0) volume(x + z * width + width * width) &= ~mask + else volume(x + z * width + width * width) |= mask setDirty(x, z) null 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 dddd0ac0e..17ee2ae41 100644 --- a/src/main/scala/li/cil/oc/server/component/DebugCard.scala +++ b/src/main/scala/li/cil/oc/server/component/DebugCard.scala @@ -42,53 +42,53 @@ object DebugCard { // ----------------------------------------------------------------------- // - @Callback + @Callback(doc = """function():number -- Gets the numeric id of the current dimension.""") def getDimensionId(context: Context, args: Arguments): Array[AnyRef] = result(world.provider.dimensionId) - @Callback + @Callback(doc = """function():string -- Gets the name of the current dimension.""") def getDimensionName(context: Context, args: Arguments): Array[AnyRef] = result(world.provider.getDimensionName) - @Callback + @Callback(doc = """function():number -- Gets the seed of the world.""") def getSeed(context: Context, args: Arguments): Array[AnyRef] = result(world.getSeed) - @Callback + @Callback(doc = """function():boolean -- Returns whether it is currently raining.""") def isRaining(context: Context, args: Arguments): Array[AnyRef] = result(world.isRaining) - @Callback + @Callback(doc = """function(value:boolean) -- Sets whether it is currently raining.""") def setRaining(context: Context, args: Arguments): Array[AnyRef] = { world.getWorldInfo.setRaining(args.checkBoolean(0)) null } - @Callback + @Callback(doc = """function():boolean -- Returns whether it is currently thundering.""") def isThundering(context: Context, args: Arguments): Array[AnyRef] = result(world.isThundering) - @Callback + @Callback(doc = """function(value:boolean) -- Sets whether it is currently thundering.""") def setThundering(context: Context, args: Arguments): Array[AnyRef] = { world.getWorldInfo.setThundering(args.checkBoolean(0)) null } - @Callback + @Callback(doc = """function():number -- Get the current world time.""") def getTime(context: Context, args: Arguments): Array[AnyRef] = result(world.getWorldTime) - @Callback + @Callback(doc = """function(value:number) -- Set the current world time.""") def setTime(context: Context, args: Arguments): Array[AnyRef] = { world.setWorldTime(args.checkDouble(0).toLong) null } - @Callback + @Callback(doc = """function():number, number, number -- Get the current spawn point coordinates.""") def getSpawnPoint(context: Context, args: Arguments): Array[AnyRef] = result(world.getWorldInfo.getSpawnX, world.getWorldInfo.getSpawnY, world.getWorldInfo.getSpawnZ) - @Callback + @Callback(doc = """function(x:number, y:number, z:number) -- Set the spawn point coordinates.""") def setSpawnPoint(context: Context, args: Arguments): Array[AnyRef] = { world.getWorldInfo.setSpawnPosition(args.checkInteger(0), args.checkInteger(1), args.checkInteger(2)) null @@ -96,38 +96,53 @@ object DebugCard { // ----------------------------------------------------------------------- // - @Callback + @Callback(doc = """function(x:number, y:number, z:number):number -- Get the ID of the block at the specified coordinates.""") def getBlockId(context: Context, args: Arguments): Array[AnyRef] = result(world.getBlockId(args.checkInteger(0), args.checkInteger(1), args.checkInteger(2))) - @Callback + @Callback(doc = """function(x:number, y:number, z:number):number -- Get the metadata of the block at the specified coordinates.""") def getMetadata(context: Context, args: Arguments): Array[AnyRef] = result(world.getBlockMetadata(args.checkInteger(0), args.checkInteger(1), args.checkInteger(2))) - @Callback + @Callback(doc = """function(x:number, y:number, z:number):number -- Check whether the block at the specified coordinates is loaded.""") def isLoaded(context: Context, args: Arguments): Array[AnyRef] = result(world.blockExists(args.checkInteger(0), args.checkInteger(1), args.checkInteger(2))) - @Callback + @Callback(doc = """function(x:number, y:number, z:number):number -- Check whether the block at the specified coordinates has a tile entity.""") def hasTileEntity(context: Context, args: Arguments): Array[AnyRef] = result(world.blockHasTileEntity(args.checkInteger(0), args.checkInteger(1), args.checkInteger(2))) - @Callback + @Callback(doc = """function(x:number, y:number, z:number):number -- Get the light opacity of the block at the specified coordinates.""") def getLightOpacity(context: Context, args: Arguments): Array[AnyRef] = result(world.getBlockLightOpacity(args.checkInteger(0), args.checkInteger(1), args.checkInteger(2))) - @Callback + @Callback(doc = """function(x:number, y:number, z:number):number -- Get the light value (emission) of the block at the specified coordinates.""") def getLightValue(context: Context, args: Arguments): Array[AnyRef] = result(world.getBlockLightValue(args.checkInteger(0), args.checkInteger(1), args.checkInteger(2))) - @Callback + @Callback(doc = """function(x:number, y:number, z:number):number -- Get whether the block at the specified coordinates is directly under the sky.""") def canSeeSky(context: Context, args: Arguments): Array[AnyRef] = result(world.canBlockSeeTheSky(args.checkInteger(0), args.checkInteger(1), args.checkInteger(2))) - @Callback + @Callback(doc = """function(x:number, y:number, z:number, id:number, meta:number):number -- Set the block at the specified coordinates.""") def setBlock(context: Context, args: Arguments): Array[AnyRef] = result(world.setBlock(args.checkInteger(0), args.checkInteger(1), args.checkInteger(2), args.checkInteger(3), args.checkInteger(4), 3)) + @Callback(doc = """function(x1:number, y1:number, z1:number, x2:number, y2:number, z2:number, id:number, meta:number):number -- Set all blocks in the area defined by the two corner points (x1, y1, z1) and (x2, y2, z2).""") + def setBlocks(context: Context, args: Arguments): Array[AnyRef] = { + val (xMin, yMin, zMin) = (args.checkInteger(0), args.checkInteger(1), args.checkInteger(2)) + val (xMax, yMax, zMax) = (args.checkInteger(3), args.checkInteger(4), args.checkInteger(5)) + val (blockId, metadata) = (args.checkInteger(6), args.checkInteger(7)) + for (x <- math.min(xMin, xMax) to math.max(xMin, xMax)) { + for (y <- math.min(yMin, yMax) to math.max(yMin, yMax)) { + for (z <- math.min(zMin, zMax) to math.max(zMin, zMax)) { + world.setBlock(x, y, z, blockId, metadata, 3) + } + } + } + null + } + // ----------------------------------------------------------------------- // override def load(nbt: NBTTagCompound) { @@ -150,4 +165,5 @@ object DebugCard { Array(args map unwrap: _*) } } + } \ No newline at end of file