From 23c2d86c27a12a85b33e08eaf74470c3d4ff3142 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 14 Jul 2022 17:07:59 +0900 Subject: [PATCH] fixed a bug where blocks are still consumend even if there is a block already under the cursor --- .../basegame/sprites/fixtures/door_test.tga | 3 +++ .../gameactors/ActorInventory.kt | 2 +- .../modulebasegame/gameitems/BlockBase.kt | 21 ++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 assets/mods/basegame/sprites/fixtures/door_test.tga diff --git a/assets/mods/basegame/sprites/fixtures/door_test.tga b/assets/mods/basegame/sprites/fixtures/door_test.tga new file mode 100644 index 000000000..304645d88 --- /dev/null +++ b/assets/mods/basegame/sprites/fixtures/door_test.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ec28ce05a936af7a33fe5bc81b619cc753dcdeb3c4932c7ae6384fab436cf6d +size 27666 diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt index 145e04e6d..4684b5bee 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt @@ -69,7 +69,7 @@ class ActorInventory() : FixtureInventory() { fun consumeItem(item: GameItem, amount: Long = 1L) { val actor = this.actor as Actor - if (item.isDynamic && amount != 1L) throw IllegalArgumentException("Dynamic item must be consumed 'once' (expected 1, got $amount)") + if (amount < 0) throw IllegalArgumentException("Consuming negative amount of an item (expected >=0, got $amount)") if (item.stackable && !item.isDynamic) { remove(item, amount) diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt index 02647059c..8d932a50a 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt @@ -29,7 +29,7 @@ object BlockBase { // FIXME actually it's this code: not recognising hitbox's starting point correctly. Use F9 for visualisation // FIXME the above issue is resolved by using intTilewise instead of hInt, but the hitbox itself is still // FIXME badly defined - + if (gameItem.inventoryCategory == GameItem.Category.BLOCK) { var ret1 = true ingame.actorContainerActive.forEach { @@ -39,20 +39,17 @@ object BlockBase { if (!ret1) return@mouseInInteractableRange -1L } - // return false if the tile underneath is: - // 0. same tile - // 1. actorblock - if (gameItem.inventoryCategory == GameItem.Category.BLOCK && - gameItem.dynamicID == ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y) || - gameItem.inventoryCategory == GameItem.Category.WALL && - gameItem.dynamicID == "wall@" + ingame.world.getTileFromWall(mouseTile.x, mouseTile.y) || - BlockCodex[ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y)].nameKey.contains("ACTORBLOCK_") - ) - return@mouseInInteractableRange 1L + val isWall = itemID.startsWith("wall@") + val terrainUnderCursor = ingame.world.getTileFromTerrain(mouseTile.x, mouseTile.y) + val wallUnderCursor = ingame.world.getTileFromWall(mouseTile.x, mouseTile.y) + + // return false if there is a tile already + if (isWall && BlockCodex[wallUnderCursor].isSolid || !isWall && BlockCodex[terrainUnderCursor].isSolid) + return@mouseInInteractableRange -1L // filter passed, do the job // FIXME this is only useful for Player - if (itemID.startsWith("wall@")) { + if (isWall) { ingame.world.setTileWall( mouseTile.x, mouseTile.y,