From 26bdd2253ab08c60f0c75a61fd901ec9f7834ef6 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 16 Feb 2024 00:26:13 +0900 Subject: [PATCH] itemised the torch --- assets/mods/basegame/blocks/blocks.csv | 4 ++-- assets/mods/basegame/crafting/fixtures.json | 5 ++--- assets/mods/basegame/items/itemid.csv | 1 + assets/mods/basegame/items/torch.tga | 3 +++ assets/mods/basegame/items/torch_emsv.tga | 3 +++ .../AssembledSpriteAnimation.kt | 7 ------- src/net/torvald/terrarum/ModMgr.kt | 13 +++++++++---- .../terrarum/gameactors/ActorWithBody.kt | 4 ++-- .../torvald/terrarum/gameitems/GameItem.kt | 3 +++ .../modulebasegame/gameactors/DroppedItem.kt | 15 +++++++++------ .../modulebasegame/gameitems/ItemMisc.kt | 19 +++++++++++++++++++ .../terrarum/modulebasegame/ui/UICrafting.kt | 2 +- .../torvald/terrarum/weather/WeatherMixer.kt | 4 ++-- .../terrarum/worlddrawer/LightmapRenderer.kt | 5 +---- 14 files changed, 57 insertions(+), 31 deletions(-) create mode 100644 assets/mods/basegame/items/torch.tga create mode 100644 assets/mods/basegame/items/torch_emsv.tga diff --git a/assets/mods/basegame/blocks/blocks.csv b/assets/mods/basegame/blocks/blocks.csv index 41994ac82..e263d76cd 100644 --- a/assets/mods/basegame/blocks/blocks.csv +++ b/assets/mods/basegame/blocks/blocks.csv @@ -89,9 +89,9 @@ "164";"164";"164";"BLOCK_PLATFORM_ROSEWOOD";"0.0312";"0.0312";"0.0312";"0.0312";"5";"900";"WOOD";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"PLATFORM,WOODEN" # lights -"176";"176";"176";"BLOCK_TORCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"800";"FXTR";"0";"0";"N/A";"1";"0";"16";"1.0000";"0.6372";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,WOODEN" +"176";"item@basegame:33";"item@basegame:33";"BLOCK_TORCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"800";"FXTR";"0";"0";"N/A";"1";"0";"16";"1.0000";"0.6372";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,WOODEN" #"177";"177";"177";"BLOCK_TORCH_FROST";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1100";"FXTR";"0";"0";"N/A";"1";"0";"16";"0.3048";"0.4848";"1.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,WOODEN" -"192";"176";"176";"BLOCK_TORCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"800";"FXTR";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,UNLIT,INTERNAL,WOODEN" +"192";"item@basegame:33";"item@basegame:33";"BLOCK_TORCH";"0.0312";"0.0312";"0.0312";"0.0312";"1";"800";"FXTR";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,UNLIT,INTERNAL,WOODEN" #"193";"177";"177";"BLOCK_TORCH_FROST";"0.0312";"0.0312";"0.0312";"0.0312";"1";"1100";"FXTR";"0";"0";"N/A";"0";"0";"16";"0.0000";"0.0000";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,UNLIT,INTERNAL,WOODEN" "208";"208";"208";"BLOCK_ILLUMINATOR_WHITE";"0.0312";"0.0312";"0.0312";"0.0312";"1";"2500";"GLAS";"1";"1";"N/A";"0";"0";"16";"0.9270";"0.9414";"0.8519";"0.0000";"N/A";"N/A";"0.0";"LIGHT,NORANDTILE" "209";"209";"209";"BLOCK_ILLUMINATOR_YELLOW";"0.0312";"0.0312";"0.0312";"0.0312";"1";"2500";"GLAS";"1";"1";"N/A";"0";"0";"16";"1.0000";"0.8408";"0.0000";"0.0000";"N/A";"N/A";"0.0";"LIGHT,NORANDTILE" diff --git a/assets/mods/basegame/crafting/fixtures.json b/assets/mods/basegame/crafting/fixtures.json index 1703011f0..64c907a95 100644 --- a/assets/mods/basegame/crafting/fixtures.json +++ b/assets/mods/basegame/crafting/fixtures.json @@ -1,5 +1,5 @@ { - "basegame:176": { /* torch */ + "item@basegame:33": { /* torch */ "workbench": "", "ingredients": [ [5, 1, "item@basegame:18", 1, "item@basegame:130"], /* 5 torches = 1 stick, 1 coal */ @@ -9,8 +9,7 @@ "item@basegame:5": { /* tiki torch */ "workbench": "", "ingredients": [ - [1, 1, "$WOOD", 3, "item@basegame:18", 1, "basegame:176"], /* 1 tiki torch = 1 wood, 3 sticks, 1 torch */ - [1, 1, "$WOOD", 3, "item@basegame:18", 1, "basegame:192"] + [1, 1, "$WOOD", 3, "item@basegame:18", 1, "item@basegame:33"] /* 1 tiki torch = 1 wood, 3 sticks, 1 torch */ ] }, diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index ad4f61ae1..56dfd161d 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -31,6 +31,7 @@ id;classname;tags 30;net.torvald.terrarum.modulebasegame.gameitems.ItemMusicalTurntable;FIXTURE,MUSIC 31;net.torvald.terrarum.modulebasegame.gameitems.ItemGunpowder;POWDER,EXPLOSIVE 32;net.torvald.terrarum.modulebasegame.gameitems.ItemCherryBomb;EXPLOSIVE,THROWABLE +33;net.torvald.terrarum.modulebasegame.gameitems.ItemTorch;FIXTURE,LIGHT # ingots 26;net.torvald.terrarum.modulebasegame.gameitems.IngotSteel;INGOT diff --git a/assets/mods/basegame/items/torch.tga b/assets/mods/basegame/items/torch.tga new file mode 100644 index 000000000..ee6f87c79 --- /dev/null +++ b/assets/mods/basegame/items/torch.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f17089a2b57abfea071abcda0ded14dc8c106a42c01f3ee12adb0ea4fe60e21d +size 450 diff --git a/assets/mods/basegame/items/torch_emsv.tga b/assets/mods/basegame/items/torch_emsv.tga new file mode 100644 index 000000000..7da1a7996 --- /dev/null +++ b/assets/mods/basegame/items/torch_emsv.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:831450a9946187e6938f1378890d3ed91dddfbd71ef69cfb8f05f852368ab813 +size 450 diff --git a/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt b/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt index 3f357a0c4..c005a4c20 100644 --- a/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt +++ b/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt @@ -133,13 +133,6 @@ class AssembledSpriteAnimation( } } - private fun fetchItemImage(item: GameItem) = if (isEmissive) - ItemCodex.getItemImageEmissive(item) - else if (isGlow) - ItemCodex.getItemImageGlow(item) - else - ItemCodex.getItemImage(item) - private fun fetchItemImage(mode: Int, item: GameItem) = when (mode) { 0 -> ItemCodex.getItemImage(item) 1 -> ItemCodex.getItemImageGlow(item) diff --git a/src/net/torvald/terrarum/ModMgr.kt b/src/net/torvald/terrarum/ModMgr.kt index 10015e80c..640fa8a73 100644 --- a/src/net/torvald/terrarum/ModMgr.kt +++ b/src/net/torvald/terrarum/ModMgr.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx import com.badlogic.gdx.files.FileHandle import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.utils.JsonValue +import net.torvald.gdx.graphics.Cvec import net.torvald.terrarum.App.* import net.torvald.terrarum.App.setToGameConfig import net.torvald.terrarum.audio.AudioCodex @@ -537,13 +538,10 @@ object ModMgr { Terrarum.blockCodex.fromModule(module, "blocks/blocks.csv") { tile -> // register blocks as items ItemCodex[tile.id] = makeNewItemObj(tile, false) - if (IS_DEVELOPMENT_BUILD) print(tile.id+" ") if (BlockCodex[tile.id].isWallable) { - ItemCodex["wall@" + tile.id] = makeNewItemObj(tile, true).also { - it.tags.add("WALL") - } + ItemCodex["wall@" + tile.id] = makeNewItemObj(tile, true) if (IS_DEVELOPMENT_BUILD) print("wall@" + tile.id + " ") } @@ -585,8 +583,12 @@ object ModMgr { // ) // } + @Transient private var isWall1: Boolean = true + init { + isWall1 = isWall tags.addAll(tile.tags) + if (isWall) tags.add("WALL") originalName = if (isWall && tags.contains("UNLIT")) "${tile.nameKey}>>=BLOCK_UNLIT_TEMPLATE>>=BLOCK_WALL_NAME_TEMPLATE" else if (isWall) "${tile.nameKey}>>=BLOCK_WALL_NAME_TEMPLATE" @@ -594,6 +596,9 @@ object ModMgr { else tile.nameKey } + override fun getLumCol() = + if (isWall1) Cvec(0) + else BlockCodex[originalID].getLumCol(0, 0) override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long { return BlockBase.blockStartPrimaryUse(actor, this, dynamicID, delta) diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index 05a50c696..4057b22bf 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -1797,7 +1797,7 @@ open class ActorWithBody : Actor { if (spriteGlow != null) drawSpriteInGoodPosition(frameDelta, spriteGlow!!, batch, 1) else if (sprite != null) - drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 0, Color.BLACK) // use black version of normal sprite as a substitution + drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 1, Color.BLACK) // use black version of normal sprite as a substitution } } @@ -1807,7 +1807,7 @@ open class ActorWithBody : Actor { if (spriteEmissive != null) drawSpriteInGoodPosition(frameDelta, spriteEmissive!!, batch, 2) else if (sprite != null) - drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 0, Color.BLACK) // use black version of normal sprite as a substitution + drawSpriteInGoodPosition(frameDelta, sprite!!, batch, 2, Color.BLACK) // use black version of normal sprite as a substitution } } diff --git a/src/net/torvald/terrarum/gameitems/GameItem.kt b/src/net/torvald/terrarum/gameitems/GameItem.kt index c69bb183e..abf166f7f 100644 --- a/src/net/torvald/terrarum/gameitems/GameItem.kt +++ b/src/net/torvald/terrarum/gameitems/GameItem.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.gameitems import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.gdx.graphics.Cvec import net.torvald.terrarum.* import net.torvald.terrarum.ReferencingRanges.PREFIX_ACTORITEM import net.torvald.terrarum.ReferencingRanges.PREFIX_DYNAMICITEM @@ -28,6 +29,8 @@ abstract class GameItem(val originalID: ItemID) : Comparable, Cloneabl constructor() : this("-uninitialised-") + open fun getLumCol(): Cvec = Cvec(0) + /** * For items with COMBUSTIBLE tag only * diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt index 701051771..415f290c7 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/DroppedItem.kt @@ -10,6 +10,7 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gameitems.* +import net.torvald.terrarum.weather.WeatherMixer.max import org.dyn4j.geometry.Vector2 /** @@ -130,12 +131,14 @@ open class DroppedItem : ActorWithBody { else if (itemID.isWall()) BlockCodex[itemID.substringAfter('@')].getLumCol(randKey1, randKey2) else { - Cvec( - ItemCodex[itemID]?.itemProperties?.getAsFloat(AVKey.LUMR) ?: 0f, - ItemCodex[itemID]?.itemProperties?.getAsFloat(AVKey.LUMG) ?: 0f, - ItemCodex[itemID]?.itemProperties?.getAsFloat(AVKey.LUMB) ?: 0f, - ItemCodex[itemID]?.itemProperties?.getAsFloat(AVKey.LUMA) ?: 0f, - ) + val itemprop = ItemCodex[itemID] + (itemprop?.getLumCol() ?: Cvec(0)).max( + Cvec( + itemprop?.itemProperties?.getAsFloat(AVKey.LUMR) ?: 0f, + itemprop?.itemProperties?.getAsFloat(AVKey.LUMG) ?: 0f, + itemprop?.itemProperties?.getAsFloat(AVKey.LUMB) ?: 0f, + itemprop?.itemProperties?.getAsFloat(AVKey.LUMA) ?: 0f, + )) } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMisc.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMisc.kt index 1ef10df3b..3b30a9d2c 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMisc.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMisc.kt @@ -1,7 +1,10 @@ package net.torvald.terrarum.modulebasegame.gameitems import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.gdx.graphics.Cvec +import net.torvald.terrarum.BlockCodex import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID @@ -47,4 +50,20 @@ class ItemGunpowder(originalID: ItemID) : LightIngredientBase(originalID) { override var originalName = "ITEM_GUNPOWDER" override val itemImage: TextureRegion get() = CommonResourcePool.getAsItemSheet("basegame.items").get(0,12) +} + +/** + * Created by minjaesong on 2024-02-15. + */ +class ItemTorch(originalID: ItemID) : LightIngredientBase(originalID) { + override var baseMass = 0.8 // from blocks.csv + override var inventoryCategory = Category.FIXTURE + + override var originalName = "BLOCK_TORCH" + override val itemImage: TextureRegion + get() = FixtureItemBase.getItemImageFromSingleImage("basegame", "items/torch.tga") + override val itemImageEmissive: TextureRegion + get() = FixtureItemBase.getItemImageFromSingleImage("basegame", "items/torch_emsv.tga") + + override fun getLumCol() = BlockCodex[Block.TORCH].getLumCol(0, 0) } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt index 8ab36f9b1..140e6ba8b 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt @@ -506,7 +506,7 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas( return if (ingredient.keyMode == CraftingCodex.CraftingItemKeyMode.TAG) { candidate.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") + throw NullPointerException("Item with tag '${ingredient.key}' not found. Possible cause: game or a module not updated or installed (ingredient: $ingredient)") ) } else { diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index fea524e81..ce7ee81cf 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -741,8 +741,8 @@ internal object WeatherMixer : RNGConsumer { } - private operator fun Cvec.times(other: Float) = Cvec(this.r * other, this.g * other, this.b * other, this.a * other) - private infix fun Cvec.max(other: Cvec) = Cvec( + operator fun Cvec.times(other: Float) = Cvec(this.r * other, this.g * other, this.b * other, this.a * other) + infix fun Cvec.max(other: Cvec) = Cvec( if (this.r > other.r) this.r else other.r, if (this.g > other.g) this.g else other.g, if (this.b > other.b) this.b else other.b, diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt index 84d72c3e6..a90207ed9 100644 --- a/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/worlddrawer/LightmapRenderer.kt @@ -377,10 +377,7 @@ object LightmapRenderer { val heldItem = it.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP] - val light = if (heldItem != null && (heldItem.isBlock())) - BlockCodex[heldItem].getLumCol(0, 0) - else - Cvec(0) + val light = ItemCodex[heldItem]?.getLumCol() ?: Cvec(0) Lightbox(Hitbox(