From 795f0ab8536a204d555bf2308eae7de47bbf6334 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 25 Feb 2021 11:11:47 +0900 Subject: [PATCH] walls now work --- .../terrarum/modulebasegame/EntryPoint.kt | 14 ++++++++++---- .../modulebasegame/gameactors/ActorInventory.kt | 17 +++++++---------- .../gameactors/PlayerBuilderSigrid.kt | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt index 6902fcc22..9d67891dc 100644 --- a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt +++ b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt @@ -55,9 +55,13 @@ class EntryPoint : ModuleEntryPoint() { // block items (blocks and walls are the same thing basically) for (tile in BlockCodex.getAll()) { ItemCodex[tile.id] = makeNewItemObj(tile, false) + if (IS_DEVELOPMENT_BUILD) print(tile.id+" ") - ItemCodex["wall@"+tile.id] = makeNewItemObj(tile, true) - if (IS_DEVELOPMENT_BUILD) print("wall@"+tile.id+" ") + + if (BlockCodex[tile.id].isWallable) { + ItemCodex["wall@" + tile.id] = makeNewItemObj(tile, true) + if (IS_DEVELOPMENT_BUILD) print("wall@" + tile.id + " ") + } } @@ -65,7 +69,9 @@ class EntryPoint : ModuleEntryPoint() { println("[Basegame.EntryPoint] Welcome back!") } - private fun makeNewItemObj(tile: BlockProp, isWall: Boolean) = object : GameItem(tile.id) { + private fun makeNewItemObj(tile: BlockProp, isWall: Boolean) = object : GameItem( + if (isWall) "wall@"+tile.id else tile.id + ) { override val isUnique: Boolean = false override var baseMass: Double = tile.density / 1000.0 override var baseToolSize: Double? = null @@ -80,7 +86,7 @@ class EntryPoint : ModuleEntryPoint() { } override fun startPrimaryUse(delta: Float): Boolean { - return BlockBase.blockStartPrimaryUse(this, tile.id, delta) + return BlockBase.blockStartPrimaryUse(this, dynamicID, delta) } override fun effectWhenEquipped(delta: Float) { diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt index d35ff0bd2..d557c27e9 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt @@ -45,18 +45,15 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c init { } - fun add(itemID: ItemID, count: Int = 1) = if (ItemCodex[itemID] == null) throw NullPointerException("Item not found: "+itemID) else add(ItemCodex[itemID]!!, count) + fun add(itemID: ItemID, count: Int = 1) { + if (ItemCodex[itemID] == null) + throw NullPointerException("Item not found: $itemID") + else + add(ItemCodex[itemID]!!, count) + } fun add(item: GameItem, count: Int = 1) { - println("[ActorInventory] add $item, $count") - - - // not wall-able walls - if (item.inventoryCategory == GameItem.Category.WALL && - (!item.dynamicID.startsWith("wall@") || !BlockCodex[item.dynamicID.substring(5)].isWallable)) { - throw IllegalArgumentException("Wall ID ${item.dynamicID} is not wall-able.") - } - + println("[ActorInventory] add-by-elem $item, $count") // other invalid values if (count == 0) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt index 29bfe98fb..e78f34b3c 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/PlayerBuilderSigrid.kt @@ -78,7 +78,7 @@ object PlayerBuilderSigrid { CreateTileAtlas.tags.forEach { t, _ -> inventory.add(t, 9995) try { - inventory.add("wall@"+t, 9995) + inventory.add("wall@"+t, 9995) // this code will try to add nonexisting wall items, do not get surprised with NPEs } catch (e: Throwable) { System.err.println("[PlayerBuilder] $e")