From 9ea070d07547c78f1682e848a7d2d386e5a82033 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 9 Sep 2023 23:58:53 +0900 Subject: [PATCH] sledgehammer: don't punch the cave wall! --- .../modulebasegame/gameitems/SledgehammerCore.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt index b069cd9ec..0d4b9f8ea 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/SledgehammerCore.kt @@ -3,7 +3,6 @@ package net.torvald.terrarum.modulebasegame.gameitems import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.* import net.torvald.terrarum.blockproperties.Block -import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gameitems.GameItem @@ -45,15 +44,24 @@ object SledgehammerCore { var usageStatus = false + + for (oy in 0 until mh) for (ox in 0 until mw) { val x = mx + xoff + ox val y = my + yoff + oy val mousePoint = Point2d(x.toDouble(), y.toDouble()) val actorvalue = actor.actorValue - val tile = INGAME.world.getTileFromWall(x, y) + val wall = INGAME.world.getTileFromWall(x, y) val tileTerrain = INGAME.world.getTileFromTerrain(x, y) + val wallNear = listOf( + INGAME.world.getTileFromWall(x, (y - 1).coerceAtLeast(0)), + INGAME.world.getTileFromWall(x, (y + 1).coerceAtMost(INGAME.world.height - 1)), + INGAME.world.getTileFromWall(x - 1, y), + INGAME.world.getTileFromWall(x + 1, y) + ) + item?.using = true // linear search filter (check for intersection with tilewise mouse point and tilewise hitbox) @@ -66,8 +74,9 @@ object SledgehammerCore { } if (!ret1) return ret1*/ + // return false if there is no open tile nearby (to prevent making hole on deep underground) // return false if here's no tile, or if the wall is covered by a solid tile - if (Block.AIR == tile || BlockCodex[tile].isActorBlock || BlockCodex[tileTerrain].isSolid) { + if (wallNear.none { BlockCodex[it].hasTag("INCONSEQUENTIAL") } || Block.AIR == wall || BlockCodex[wall].isActorBlock || BlockCodex[tileTerrain].isSolid) { usageStatus = usageStatus or false continue }