From 06ef46d369f3336bb4f61e2fb5c96bc1aa8af04c Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 19 Jul 2022 18:32:21 +0900 Subject: [PATCH] some changes regarding actorblocks --- assets/mods/basegame/blocks/4091.tga | 4 +- assets/mods/basegame/blocks/4092.tga | 4 +- assets/mods/basegame/blocks/4093.tga | 4 +- assets/mods/basegame/blocks/4094.tga | 4 +- assets/mods/basegame/blocks/4095.tga | 4 +- assets/mods/basegame/blocks/blocks.csv | 23 +++- src/module-info.java | 1 + .../torvald/terrarum/blockproperties/Block.kt | 8 -- src/net/torvald/terrarum/console/Batch.kt | 7 +- .../terrarum/modulebasegame/TerrarumIngame.kt | 2 +- .../modulebasegame/gameactors/FixtureBase.kt | 6 +- .../gameactors/FixtureSwingingDoorBase.kt | 108 ++++++++++++++---- .../gameitems/PickaxeGeneric.kt | 4 +- 13 files changed, 128 insertions(+), 51 deletions(-) diff --git a/assets/mods/basegame/blocks/4091.tga b/assets/mods/basegame/blocks/4091.tga index c5033e14a..beac83a10 100644 --- a/assets/mods/basegame/blocks/4091.tga +++ b/assets/mods/basegame/blocks/4091.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fffb3b9a233fbd27a58c411e8eb2cb6828f21b0041cd514dd97ed2a9cdaff122 -size 1068 +oid sha256:66236ef85ac5e1a190df935348379be2c9f0e5a975ad7be6dc7f42313eb195b8 +size 1042 diff --git a/assets/mods/basegame/blocks/4092.tga b/assets/mods/basegame/blocks/4092.tga index c5033e14a..f64cb62f1 100644 --- a/assets/mods/basegame/blocks/4092.tga +++ b/assets/mods/basegame/blocks/4092.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fffb3b9a233fbd27a58c411e8eb2cb6828f21b0041cd514dd97ed2a9cdaff122 -size 1068 +oid sha256:3ba8564b6cf1176b94d86f5403612d74c46ad4d62dd230afca661b1bcdb5d868 +size 1042 diff --git a/assets/mods/basegame/blocks/4093.tga b/assets/mods/basegame/blocks/4093.tga index c5033e14a..1081094a3 100644 --- a/assets/mods/basegame/blocks/4093.tga +++ b/assets/mods/basegame/blocks/4093.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fffb3b9a233fbd27a58c411e8eb2cb6828f21b0041cd514dd97ed2a9cdaff122 -size 1068 +oid sha256:6c8423284b9aad5290803c0b464649d9951bbe80fb40ddf0f08f0d5449a9c1a2 +size 1042 diff --git a/assets/mods/basegame/blocks/4094.tga b/assets/mods/basegame/blocks/4094.tga index c5033e14a..b2a6cf619 100644 --- a/assets/mods/basegame/blocks/4094.tga +++ b/assets/mods/basegame/blocks/4094.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fffb3b9a233fbd27a58c411e8eb2cb6828f21b0041cd514dd97ed2a9cdaff122 -size 1068 +oid sha256:5fe2eef5c302f2314c26e663ba111d3dbe187f60150259c1d58fd473c5d8929f +size 1042 diff --git a/assets/mods/basegame/blocks/4095.tga b/assets/mods/basegame/blocks/4095.tga index c5033e14a..150d3f7ea 100644 --- a/assets/mods/basegame/blocks/4095.tga +++ b/assets/mods/basegame/blocks/4095.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fffb3b9a233fbd27a58c411e8eb2cb6828f21b0041cd514dd97ed2a9cdaff122 -size 1068 +oid sha256:54ebfa1b859e3c1a813089fc96fb52f8594c28b6c66b3b308a8a9259453e4400 +size 1042 diff --git a/assets/mods/basegame/blocks/blocks.csv b/assets/mods/basegame/blocks/blocks.csv index 8bc4894df..083c638fb 100644 --- a/assets/mods/basegame/blocks/blocks.csv +++ b/assets/mods/basegame/blocks/blocks.csv @@ -104,7 +104,7 @@ id;drop;world;name;shdr;shdg;shdb;shduv;str;dsty;mate;solid;plat;wall;grav;dlfn; 273;273;273;BLOCK_SCAFFOLDING_EBONY;0.0312;0.0312;0.0312;0.0312;1;1400;WOOD;0;1;0;6;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;PLATFORM 274;274;274;BLOCK_SCAFFOLDING_BIRCH;0.0312;0.0312;0.0312;0.0312;1;670;WOOD;0;1;0;6;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;PLATFORM 275;275;275;BLOCK_SCAFFOLDING_BLOODROSE;0.0312;0.0312;0.0312;0.0312;1;900;WOOD;0;1;0;6;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;PLATFORM -4090;N/A;N/A;ACTORBLOCK_TILING_PLACEHOLDER;0.1252;0.1252;0.1252;0.1252;48;2400;ROCK;1;0;1;N/A;0;4;16;0.0000;0.0000;0.0000;0.0000;N/A;N/A;0.0;INTERNAL +4090;N/A;N/A;ACTORBLOCK_TILING_PLACEHOLDER;0.1252;0.1252;0.1252;0.1252;48;2400;ROCK;1;0;1;N/A;0;4;16;0.0000;0.0000;0.0000;0.0000;N/A;N/A;0.0;INTERNAL,DORENDER 4091;N/A;N/A;ACTORBLOCK_NO_COLLISION;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;4;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL 4092;N/A;N/A;ACTORBLOCK_FULL_COLLISION;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;0;0;N/A;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL 4093;N/A;N/A;ACTORBLOCK_ALLOW_MOVE_DOWN;0.0312;0.0312;0.0312;0.0312;1;1;NULL;0;1;0;N/A;0;0;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0;INTERNAL @@ -117,6 +117,7 @@ id;drop;world;name;shdr;shdg;shdb;shduv;str;dsty;mate;solid;plat;wall;grav;dlfn; #5000;5000;BLOCK_SIGNAL_POWER_SOURCE;0.1252;0.1252;0.1252;0.1252;24;1400;NULL;0;0;0;N/A;0;4;16;0.0;0.0;0.0;0.0;N/A;N/A;0.0 ## Notes ## +# # Every block must have a shade value that is at least as dark as the air block's # # Lava/Water props are left for future references, do not delete them until FluidCodex is built # @@ -154,7 +155,6 @@ id;drop;world;name;shdr;shdg;shdb;shduv;str;dsty;mate;solid;plat;wall;grav;dlfn; # grav: Whether the block should fall through the empty space. N/A to not make it fall; # 0 to fall immediately (e.g. Sand), nonzero to indicate that number of floating blocks can be supported (e.g. Scaffolding) # -# tags: tag(s) to the item which is used by the crafting system. Multiple tags are separated using commas. Each tag must be all uppercase and only [0-9A-Z] chars are supported. # ## Illuminators ## # @@ -175,6 +175,25 @@ id;drop;world;name;shdr;shdg;shdb;shduv;str;dsty;mate;solid;plat;wall;grav;dlfn; # Magical ice: theoretical __metallic__ ice that might form under super-high pressure (> 5 TPa). Its density is a wild guess. # # +## Actorblocks ## +# +# Actorblocks are virtual/placeholder blocks that accompanies actors (usually fixtures). +# Any tile that contains "ACTORBLOCK" in its "name" will be recognised as one, so avoid having the particular string on +# the name if your tile is not Actorblock! +# +# +## Tags ## +# +# Tag(s) to the item which is used by the crafting system. Multiple tags are separated using commas. Each tag must be all +# uppercase and only [0-9A-Z] chars are supported. +# +### Internal Tags ## +## +## Some tags are reserved for internal use, which are: +## - INTERNAL: denotes that the tile is internal-use. Will not be rendered unless debug window is on. +## - DORENDER: this internal tile must go through the standard-issue tile drawing routine. +# +# ## References ## # # * Density of various woods : http://www.engineeringtoolbox.com/wood-density-d_40.html diff --git a/src/module-info.java b/src/module-info.java index ad93f8437..bf4663bb5 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -31,6 +31,7 @@ module Terrarum { requires com.ibm.icu; requires org.lwjgl.opengl; requires prtree; + requires kotlin.stdlib.jdk7; exports net.torvald.colourutil; diff --git a/src/net/torvald/terrarum/blockproperties/Block.kt b/src/net/torvald/terrarum/blockproperties/Block.kt index 17ea34209..266c3280f 100644 --- a/src/net/torvald/terrarum/blockproperties/Block.kt +++ b/src/net/torvald/terrarum/blockproperties/Block.kt @@ -131,12 +131,4 @@ object Block { const val NULL = "basegame:-1" - val actorblocks = listOf( - ACTORBLOCK_TILING_PLACEHOLDER, - ACTORBLOCK_NO_COLLISION, - ACTORBLOCK_FULL_COLLISION, - ACTORBLOCK_ALLOW_MOVE_DOWN, - ACTORBLOCK_NO_PASS_RIGHT, - ACTORBLOCK_NO_PASS_LEFT - ) } diff --git a/src/net/torvald/terrarum/console/Batch.kt b/src/net/torvald/terrarum/console/Batch.kt index c33d4424a..c74a3d146 100644 --- a/src/net/torvald/terrarum/console/Batch.kt +++ b/src/net/torvald/terrarum/console/Batch.kt @@ -1,7 +1,8 @@ package net.torvald.terrarum.console -import java.nio.file.FileSystems +import net.torvald.terrarum.App import java.nio.file.Files +import kotlin.io.path.Path /** * Created by minjaesong on 2016-03-07. @@ -10,7 +11,7 @@ internal object Batch : ConsoleCommand { @Throws(Exception::class) override fun execute(args: Array) { if (args.size == 2) { - Files.lines(FileSystems.getDefault().getPath(args[1])).forEach( + Files.lines(Path(App.defaultDir, args[1])).forEach( { CommandInterpreter.execute(it) }) } else { @@ -19,6 +20,6 @@ internal object Batch : ConsoleCommand { } override fun printUsage() { - Echo("Usage: batch path/to/batch.txt") + Echo("Usage: batch path/to/batch.txt relative to the app data folder") } } diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index c2ad6a6aa..93a3123d8 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -1281,7 +1281,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { else if (canAttackOrDig) { val punchBlockSize = punchSize.div(TILE_SIZED).floorInt() if (punchBlockSize > 0) { - PickaxeCore.startPrimaryUse(actor, delta, null, Terrarum.mouseTileX, Terrarum.mouseTileY, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize, false) + PickaxeCore.startPrimaryUse(actor, delta, null, Terrarum.mouseTileX, Terrarum.mouseTileY, 1.0 / punchBlockSize, punchBlockSize, punchBlockSize) } } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 6a31e4869..d0a4de594 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -32,7 +32,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { /** Real time, in nanoseconds */ @Transient var spawnRequestedTime: Long = 0L - private set + protected set lateinit var blockBox: BlockBox // something like TapestryObject will want to redefine this fun blockBoxIndexToPoint2i(it: BlockBoxIndex): Point2i = this.blockBox.width.let { w -> Point2i(it % w, it / w) } @@ -74,7 +74,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { * Tile-wise position of this fixture when it's placed on the world, top-left origin. Null if it's not on the world */ var worldBlockPos: Point2i? = null - private set + protected set // something like TapestryObject will want to redefine this /** @@ -138,7 +138,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { for (y in posY until posY + blockBox.height) { for (x in posX until posX + blockBox.width) { val tile = world!!.getTileFromTerrain(x, y) - if (BlockCodex[tile].isSolid || tile in Block.actorblocks) { + if (BlockCodex[tile].isSolid || BlockCodex[tile].isActorBlock) { hasCollision = true break@checkForCollision } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt index 6e6993482..87063ce71 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureSwingingDoorBase.kt @@ -10,6 +10,7 @@ import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameactors.Lightbox import net.torvald.terrarum.gameactors.Luminous +import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** @@ -37,14 +38,89 @@ class FixtureSwingingDoorBase : FixtureBase, Luminous { protected var doorState = 0 // -1: open toward left, 0: closed, 1: open toward right - @Transient private var placeActorBlockLatch = false +// @Transient private var placeActorBlockLatch = false constructor() : super( BlockBox(BlockBox.FULL_COLLISION, 1, 3), // temporary value, will be overwritten by reload() nameFun = { "item not loaded properly, alas!" } ) { + val hbw = TILE_SIZE * (tw * 2 - twClosed) + val hbh = TILE_SIZE * th + + nameFun = customNameFun + + density = 1200.0 + actorValue[AVKey.BASEMASS] = 10.0 + + // loading textures + CommonResourcePool.addToLoadingList("$moduleName-$textureIdentifier") { + TextureRegionPack(ModMgr.getGdxFile(moduleName, texturePath), hbw, hbh) + } + CommonResourcePool.loadAll() + makeNewSprite(FixtureBase.getSpritesheet(moduleName, texturePath, hbw, hbh)).let { + it.setRowsAndFrames(3,1) + } + + // define light/shadebox + (if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList).add( + Lightbox(Hitbox(0.0, 0.0, TILE_SIZED, th * TILE_SIZED), opacity)) + reload() - placeActorBlockLatch = true + } + + override fun spawn(posX: Int, posY: Int) = spawn(posX, posY, TILE_SIZE * (tw * 2 - twClosed), TILE_SIZE * th) + + // TODO move this function over FixtureBase once it's done and perfected + protected fun spawn(posX: Int, posY: Int, hbw: Int, hbh: Int): Boolean { + // wrap x-position + val posX = posX fmod world!!.width + + // define physical size + setHitboxDimension(hbw, hbh, 0, 0) + /*this.hitbox.setFromWidthHeight( + posX * TILE_SIZED, + posY * TILE_SIZED, + blockBox.width * TILE_SIZED, + blockBox.height * TILE_SIZED + )*/ + blockBox = BlockBox(BlockBox.FULL_COLLISION, tw * 2 - twClosed, th) + + // check for existing blocks (and fixtures) + var hasCollision = false + checkForCollision@ + for (y in posY until posY + blockBox.height) { + for (x in posX until posX + blockBox.width) { + val tile = world!!.getTileFromTerrain(x, y) + if (BlockCodex[tile].isSolid || BlockCodex[tile].isActorBlock) { + hasCollision = true + break@checkForCollision + } + } + } + + if (hasCollision) { + printdbg(this, "cannot spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, has tile collision; tilewise dim: (${blockBox.width}, ${blockBox.height}) ") + return false + } + + printdbg(this, "spawn fixture ${nameFun()} at F${INGAME.WORLD_UPDATE_TIMER}, tilewise dim: (${blockBox.width}, ${blockBox.height})") + + // set the position of this actor + worldBlockPos = Point2i(posX - (hbw - 1) / 2, posY) + + // fill the area with the filler blocks + placeActorBlocks() + + + this.isVisible = true + + + // actually add this actor into the world + INGAME.queueActorAddition(this) + spawnRequestedTime = System.nanoTime() + + + return true } override fun reload() { @@ -55,28 +131,16 @@ class FixtureSwingingDoorBase : FixtureBase, Luminous { val hbw = TILE_SIZE * (tw * 2 - twClosed) val hbh = TILE_SIZE * th - blockBox = BlockBox(BlockBox.FULL_COLLISION, tw * 2 - twClosed, th) + // redefined things that are affected by sprite size +// blockBox = BlockBox(BlockBox.FULL_COLLISION, tw * 2 - twClosed, th) // loading textures - CommonResourcePool.addToLoadingList("$moduleName-$textureIdentifier") { - TextureRegionPack(ModMgr.getGdxFile(moduleName, texturePath), hbw, hbh) - } - CommonResourcePool.loadAll() - - density = 1200.0 - actorValue[AVKey.BASEMASS] = 10.0 // setHitboxDimension(hbw, hbh, TILE_SIZE * (tw * 2 - twClosed), 0) - setHitboxDimension(hbw, hbh, TILE_SIZE * ((tw * 2 - twClosed - 1) / 2), 0) +// setHitboxDimension(hbw, hbh, TILE_SIZE * ((tw * 2 - twClosed - 1) / 2), 0) - (if (isOpacityActuallyLuminosity) lightBoxList else shadeBoxList).add( - Lightbox(Hitbox(0.0, 0.0, TILE_SIZED, th * TILE_SIZED), opacity)) - makeNewSprite(FixtureBase.getSpritesheet(moduleName, texturePath, hbw, hbh)).let { - it.setRowsAndFrames(3,1) - } - - placeActorBlockLatch = false +// placeActorBlockLatch = false } open protected fun closeDoor() { @@ -94,14 +158,14 @@ class FixtureSwingingDoorBase : FixtureBase, Luminous { doorState = -1 } - override fun forEachBlockbox(action: (Int, Int, Int, Int) -> Unit) { + /*override fun forEachBlockbox(action: (Int, Int, Int, Int) -> Unit) { val xStart = worldBlockPos!!.x - ((tw * 2 - twClosed - 1) / 2) // worldBlockPos.x is where the mouse was, of when the tilewise width was 1. for (y in worldBlockPos!!.y until worldBlockPos!!.y + blockBox.height) { for (x in xStart until xStart + blockBox.width) { action(x, y, x - xStart, y - worldBlockPos!!.y) } } - } + }*/ override fun placeActorBlocks() { forEachBlockbox { x, y, ox, oy -> @@ -131,10 +195,10 @@ class FixtureSwingingDoorBase : FixtureBase, Luminous { } override fun update(delta: Float) { - if (placeActorBlockLatch) { + /*if (placeActorBlockLatch) { placeActorBlockLatch = false placeActorBlocks() - } + }*/ super.update(delta) diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt index d474e1d56..02fdaf7e5 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/PickaxeGeneric.kt @@ -28,7 +28,7 @@ object PickaxeCore { */ fun startPrimaryUse( actor: ActorWithBody, delta: Float, item: GameItem?, mx: Int, my: Int, - dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1, attackActorBlocks: Boolean = true + dropProbability: Double = 1.0, mw: Int = 1, mh: Int = 1 ) = mouseInInteractableRangeTools(actor, item) { // un-round the mx val ww = INGAME.world.width @@ -67,7 +67,7 @@ object PickaxeCore { if (!ret1) return ret1*/ // return false if here's no tile - if (Block.AIR == tile || (!attackActorBlocks && tile in Block.actorblocks)) { + if (Block.AIR == tile || BlockCodex[tile].isActorBlock) { usageStatus = usageStatus or false continue }