From fab417906847fd9b03d4fe9caea949e3faee24c9 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 14 Aug 2023 18:16:05 +0900 Subject: [PATCH] fixing issue #47 using new tag on blocks.csv --- assets/mods/basegame/blocks/blocks.csv | 3 ++- src/net/torvald/terrarum/blockproperties/BlockCodex.kt | 4 ++-- src/net/torvald/terrarum/blockproperties/BlockProp.kt | 2 ++ src/net/torvald/terrarum/gameitems/GameItem.kt | 2 ++ .../terrarum/modulebasegame/gameactors/FixtureBase.kt | 4 ++-- .../terrarum/modulebasegame/gameitems/BlockBase.kt | 2 +- .../terrarum/modulebasegame/ui/ControlPanelCommon.kt | 2 +- src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt | 8 ++++---- .../modulebasegame/ui/UIPerformanceControlPanel.kt | 2 +- 9 files changed, 17 insertions(+), 12 deletions(-) diff --git a/assets/mods/basegame/blocks/blocks.csv b/assets/mods/basegame/blocks/blocks.csv index 12c94c25f..d31206b89 100644 --- a/assets/mods/basegame/blocks/blocks.csv +++ b/assets/mods/basegame/blocks/blocks.csv @@ -1,5 +1,5 @@ "id";"drop";"spawn";"name";"shdr";"shdg";"shdb";"shduv";"str";"dsty";"mate";"solid";"wall";"grav";"dlfn";"fv";"fr";"lumr";"lumg";"lumb";"lumuv";"colour";"vscs";"refl";"tags" -"0";"0";"0";"BLOCK_AIR";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"1";"N/A";"0";"0";"4";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"" +"0";"0";"0";"BLOCK_AIR";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1";"NULL";"0";"1";"N/A";"0";"0";"4";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"INCONSEQUENTIAL" "16";"17";"17";"BLOCK_STONE";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK,NATURAL" "17";"17";"17";"BLOCK_STONE_QUARRIED";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"ROCK" "18";"18";"18";"BLOCK_STONE_TILE_WHITE";"0.1252";"0.1252";"0.1252";"0.1252";"48";"2400";"ROCK";"1";"1";"N/A";"0";"4";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.18";"STONE" @@ -188,6 +188,7 @@ ## 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. +## - INCONSEQUENTIAL: denotes that this tile can be overwritten without dropping it. Usually used with flower tiles. # # ## References ## diff --git a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt index e50a8bca8..2110d28df 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockCodex.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockCodex.kt @@ -209,8 +209,8 @@ class BlockCodex { prop.isSolid = record.boolVal("solid") //prop.isClear = record.boolVal("clear") - prop.isPlatform = prop.tags.contains("PLATFORM") - prop.isActorBlock = prop.tags.contains("ACTORBLOCK") + prop.isPlatform = prop.hasTag("PLATFORM") + prop.isActorBlock = prop.hasTag("ACTORBLOCK") prop.isWallable = record.boolVal("wall") prop.maxSupport = record.intVal("grav") diff --git a/src/net/torvald/terrarum/blockproperties/BlockProp.kt b/src/net/torvald/terrarum/blockproperties/BlockProp.kt index ee2eefc45..ac75be5d0 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockProp.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockProp.kt @@ -75,6 +75,8 @@ class BlockProp { BlockCodex[BlockCodex.tileToVirtual[id]!![offset]]._lumCol.lane(channel) } + fun hasTag(s: String) = tags.contains(s) + /** * @param luminosity */ diff --git a/src/net/torvald/terrarum/gameitems/GameItem.kt b/src/net/torvald/terrarum/gameitems/GameItem.kt index b2e30fad5..8d788e0a5 100644 --- a/src/net/torvald/terrarum/gameitems/GameItem.kt +++ b/src/net/torvald/terrarum/gameitems/GameItem.kt @@ -359,6 +359,8 @@ abstract class GameItem(val originalID: ItemID) : Comparable, Cloneabl return this } + fun hasTag(s: String) = tags.contains(s) + companion object { diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 8e59d7410..9c6724d8f 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -248,7 +248,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { forEachBlockbox { x, y, _, _ -> if (!hasCollision) { val tile = world!!.getTileFromTerrain(x, y) - if (BlockCodex[tile].isSolid || BlockCodex[tile].isActorBlock) { + if (!BlockCodex[tile].hasTag("INCONSEQUENTIAL")) { hasCollision = true } } @@ -311,7 +311,7 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange { forEachBlockbox { x, y, _, _ -> if (!hasCollision) { val tile = world!!.getTileFromTerrain(x, y) - if (BlockCodex[tile].isSolid || BlockCodex[tile].isActorBlock) { + if (!BlockCodex[tile].hasTag("INCONSEQUENTIAL")) { hasCollision = true } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt index 17b159475..d52a09944 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/BlockBase.kt @@ -51,7 +51,7 @@ object BlockBase { // return false if there is a "solid" tile already if (isWall && BlockCodex[wallUnderCursor].isSolid || - !isWall && (BlockCodex[terrainUnderCursor].isSolid || BlockCodex[terrainUnderCursor].isActorBlock)) + !isWall && !BlockCodex[terrainUnderCursor].hasTag("INCONSEQUENTIAL")) return@mouseInInteractableRange -1L // filter passed, do the job diff --git a/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt b/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt index df79f886d..9bd420fed 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/ControlPanelCommon.kt @@ -74,7 +74,7 @@ object ControlPanelCommon { val optionsList = arg.subList(1, arg.size).map { it.toInt() } val initialSel = optionsList.indexOf(App.getConfigInt(optionName)) - if (initialSel < 0) throw IllegalArgumentException("config value '${App.getConfigString(optionName)}' for option '$optionName' is not found on the options list") + if (initialSel < 0) throw IllegalArgumentException("config value '${App.getConfigInt(optionName)}' for option '$optionName' is not found on the options list") UIItemTextSelector(parent, x, y, labelFuns, initialSel, CONFIG_SPINNER_WIDTH, clickToShowPalette = false, useSpinnerButtons = true) to { it: UIItem, optionStr: String -> (it as UIItemTextSelector).selectionChangeListener = { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt index 8245087d4..565db0ea6 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt @@ -125,7 +125,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory { // If the player has the required item, use it; otherwise, will take an item from the ItemCodex player.itemList.filter { (itm, qty) -> ItemCodex[itm]?.tags?.contains(ingredient.key) == true && qty >= ingredient.qty - }.maxByOrNull { it.qty }?.itm ?: ((ItemCodex.itemCodex.firstNotNullOfOrNull { if (it.value.tags.contains(ingredient.key)) it.key else null }) ?: throw NullPointerException("Item with tag '${ingredient.key}' not found. Possible cause: game or a module not updated or installed")) + }.maxByOrNull { it.qty }?.itm ?: ((ItemCodex.itemCodex.firstNotNullOfOrNull { if (it.value.hasTag(ingredient.key)) it.key else null }) ?: throw NullPointerException("Item with tag '${ingredient.key}' not found. Possible cause: game or a module not updated or installed")) } else { ingredient.key @@ -234,7 +234,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory { // don't rely on highlightedness of the button to determine the item on the button is the selected // ingredient (because I don't fully trust my code lol) val targetItemToAlter = recipe.ingredients.filter { // altering recipe doesn't make sense if player selected a recipe that requires no tag-ingredients - (it.keyMode == CraftingCodex.CraftingItemKeyMode.TAG && gameItem.tags.contains(it.key)) + (it.keyMode == CraftingCodex.CraftingItemKeyMode.TAG && gameItem.hasTag(it.key)) }.let { if (it.size > 1) println("[UICrafting] Your recipe seems to have two similar ingredients defined\n" + @@ -245,7 +245,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory { targetItemToAlter?.let { val oldItem = _getItemListIngredients().getInventory().itemList.first { itemPair -> - (it.keyMode == CraftingCodex.CraftingItemKeyMode.TAG && ItemCodex[itemPair.itm]!!.tags.contains(it.key)) + (it.keyMode == CraftingCodex.CraftingItemKeyMode.TAG && ItemCodex[itemPair.itm]!!.hasTag(it.key)) } changeIngredient(oldItem, itemID) refreshCraftButtonStatus() @@ -279,7 +279,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory { // If the player has the required item, use it; otherwise, will take an item from the ItemCodex val selectedItem = playerInventory.itemList.filter { (itm, qty) -> ItemCodex[itm]?.tags?.contains(ingredient.key) == true && qty >= ingredient.qty - }.maxByOrNull { it.qty }?.itm ?: ((ItemCodex.itemCodex.firstNotNullOfOrNull { if (it.value.tags.contains(ingredient.key)) it.key else null }) ?: throw NullPointerException("Item with tag '${ingredient.key}' not found. Possible cause: game or a module not updated or installed")) + }.maxByOrNull { it.qty }?.itm ?: ((ItemCodex.itemCodex.firstNotNullOfOrNull { if (it.value.hasTag(ingredient.key)) it.key else null }) ?: throw NullPointerException("Item with tag '${ingredient.key}' not found. Possible cause: game or a module not updated or installed")) // printdbg(this, "Adding ingredients by tag ${selectedItem} (${ingredient.qty})") selectedItem diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt index bb3d2b80d..cb6abb8ba 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIPerformanceControlPanel.kt @@ -27,7 +27,7 @@ class UIPerformanceControlPanel(remoCon: UIRemoCon?) : UICanvas() { arrayOf("autosaveinterval", { Lang["MENU_OPTIONS_AUTOSAVE"] + " (${Lang["CONTEXT_TIME_MINUTE_PLURAL"]})" }, "spinnerimul,1,120,1,60000"), arrayOf("notificationshowuptime", { Lang["MENU_OPTIONS_NOTIFICATION_DISPLAY_DURATION"] + " (${Lang["CONTEXT_TIME_SECOND_PLURAL"]})" }, "spinnerimul,2,10,1,1000"), arrayOf("", { Lang["MENU_LABEL_GRAPHICS"] }, "h1"), - arrayOf("atlastexsize", { Lang["MENU_OPTIONS_ATLAS_TEXTURE_SIZE"] }, "spinnersel,2048,4096,8192"), + arrayOf("atlastexsize", { Lang["MENU_OPTIONS_ATLAS_TEXTURE_SIZE"] }, "spinnersel,1024,2048,4096,8192"), arrayOf("", { Lang["MENU_LABEL_JVM_DNT"] }, "h1"), arrayOf("jvm_xmx", { Lang["MENU_OPTIONS_JVM_HEAP_MAX"] + " (GB)" }, "spinner,2,32,1"), arrayOf("jvm_extra_cmd", { Lang["MENU_LABEL_EXTRA_JVM_ARGUMENTS"] }, "typein"),