From 35bec7bc26a60a595d7affc2695b0e3bb48d10f6 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 14 Sep 2024 20:02:26 +0900 Subject: [PATCH] water buckets --- .../mods/basegame/items/basegame_buckets.kra | 3 + assets/mods/basegame/items/buckets.tga | 3 + assets/mods/basegame/items/itemid.csv | 27 ++++-- assets/mods/basegame/ores/ores.csv | 44 +++++----- .../terrarum/blockproperties/OreCodex.kt | 2 + .../torvald/terrarum/gameworld/GameWorld.kt | 2 +- .../terrarum/modulebasegame/EntryPoint.kt | 3 + .../gameitems/ItemFluidStorage.kt | 88 +++++++++++++++++++ .../modulebasegame/gameitems/OreItemBase.kt | 2 +- .../modulebasegame/worldgenerator/Oregen.kt | 9 +- work_files/graphics/items/basegame_items.kra | 4 +- 11 files changed, 153 insertions(+), 34 deletions(-) create mode 100644 assets/mods/basegame/items/basegame_buckets.kra create mode 100644 assets/mods/basegame/items/buckets.tga create mode 100644 src/net/torvald/terrarum/modulebasegame/gameitems/ItemFluidStorage.kt diff --git a/assets/mods/basegame/items/basegame_buckets.kra b/assets/mods/basegame/items/basegame_buckets.kra new file mode 100644 index 000000000..b8a11aee6 --- /dev/null +++ b/assets/mods/basegame/items/basegame_buckets.kra @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:40720246692cffd852fa2b260308918def950abc774b39aba7add5716ecb3db8 +size 179347 diff --git a/assets/mods/basegame/items/buckets.tga b/assets/mods/basegame/items/buckets.tga new file mode 100644 index 000000000..f701c712e --- /dev/null +++ b/assets/mods/basegame/items/buckets.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0c139d0a944710aef9fa79248038fb95edafa8a38d71cd09c609a1174527c94 +size 2408466 diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index 0c745715e..3f03d9fb9 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -130,6 +130,7 @@ id;classname;tags 320;net.torvald.terrarum.modulebasegame.gameitems.ItemWorldPortal;FIXTURE,STATION + # data storage (discs; 256) # 32768 is a reserved number for a blank disc 32769;net.torvald.terrarum.modulebasegame.gameitems.MusicDisc01;MUSIC,PHONO @@ -152,14 +153,26 @@ id;classname;tags # fluids on storage # preferably autogenerated -# 100000h..1000FFh : Fluid type 0 (water) x container type 0..255 -# 100100h..1001FFh : Fluid type 1 (lava) x container type 0..255 -# 100200h..1002FFh : Fluid type 2 (crude oil) x container type 0..255 -# 100300h..1003FFh : Fluid type 3 (petroleum) x container type 0..255 -# 100400h..1004FFh : Fluid type 4 (compressed air) x container type 0..255 -# 100500h..1005FFh : Fluid type 5 (steam) x container type 0..255 +# FLUIDSTORAGE: required tag for buckets/canisters +# OPENSTORAGE: cannot hold gas. Canisters need LIDDEDSTORAGE/SEALEDSTORAGE +# FLUIDROOMTEMP: cannot hold cryogenic/hot fluids (e.g. lava, steam) +# 100000h..1000FFh : container type 0 x Fluid type 0..255 +# 100100h..1001FFh : container type 1 x Fluid type 0..255 +# 100200h..1002FFh : container type 2 x Fluid type 0..255 +# 100300h..1003FFh : container type 3 x Fluid type 0..255 +# 100400h..1004FFh : container type 4 x Fluid type 0..255 +# 100500h..1005FFh : container type 5 x Fluid type 0..255 # ... -# 10FF00h..10FFFFh : Fluid type 255 (???) x container type 0..255 +# 10FF00h..10FFFFh : container type 255 x Fluid type 0..255 +1048576;net.torvald.terrarum.modulebasegame.gameitems.ItemBucketWooden00;FLUIDSTORAGE,OPENSTORAGE,FLUIDROOMTEMP,FLUIDSTORAGEEMPTY +1048577;net.torvald.terrarum.modulebasegame.gameitems.ItemBucketWooden01;FLUIDSTORAGE,OPENSTORAGE,FLUIDROOMTEMP +#1048578;net.torvald.terrarum.modulebasegame.gameitems.ItemBucketWooden02;FLUIDSTORAGE,OPENSTORAGE,FLUIDROOMTEMP +1048579;net.torvald.terrarum.modulebasegame.gameitems.ItemBucketWooden03;FLUIDSTORAGE,OPENSTORAGE,FLUIDROOMTEMP + +1048832;net.torvald.terrarum.modulebasegame.gameitems.ItemBucketIron00;FLUIDSTORAGE,OPENSTORAGE,FLUIDSTORAGEEMPTY +1048833;net.torvald.terrarum.modulebasegame.gameitems.ItemBucketIron01;FLUIDSTORAGE,OPENSTORAGE +1048834;net.torvald.terrarum.modulebasegame.gameitems.ItemBucketIron02;FLUIDSTORAGE,OPENSTORAGE +1048835;net.torvald.terrarum.modulebasegame.gameitems.ItemBucketIron03;FLUIDSTORAGE,OPENSTORAGE # reserved for debug items 16777216;net.torvald.terrarum.modulebasegame.gameitems.ItemBottomlessWaterBucket;DEBUG,TOOL diff --git a/assets/mods/basegame/ores/ores.csv b/assets/mods/basegame/ores/ores.csv index 9b55c728d..c7169fade 100644 --- a/assets/mods/basegame/ores/ores.csv +++ b/assets/mods/basegame/ores/ores.csv @@ -1,25 +1,25 @@ -"id";"item";"tags" -"1";"item@basegame:128";"COPPER,MALACHITE" -"2";"item@basegame:129";"IRON,HAEMATITE" -"3";"item@basegame:130";"COAL,CARBON" -"4";"item@basegame:131";"ZINC,SPHALERITE" -"5";"item@basegame:132";"TIN,CASSITERITE" -"6";"item@basegame:133";"GOLD,NATURAL_GOLD" -"7";"item@basegame:134";"SILVER,NATURAL_SILVER" -"8";"item@basegame:135";"LEAD,GALENA" -"9";"item@basegame:136";"URANIUM,URANINITE" -#"10";"item@basegame:143";"TITANIUM,RUTILE" +"id";"item";"tags";"versionsince" +"1";"item@basegame:128";"COPPER,MALACHITE";0 +"2";"item@basegame:129";"IRON,HAEMATITE";0 +"3";"item@basegame:130";"COAL,CARBON";0 +"4";"item@basegame:131";"ZINC,SPHALERITE";0 +"5";"item@basegame:132";"TIN,CASSITERITE";0 +"6";"item@basegame:133";"GOLD,NATURAL_GOLD";0 +"7";"item@basegame:134";"SILVER,NATURAL_SILVER";0 +"8";"item@basegame:135";"LEAD,GALENA";0 +"9";"item@basegame:136";"URANIUM,PITCHBLENDE";67108868 +#"10";"item@basegame:143";"TITANIUM,RUTILE";100663296 -"256";"item@basegame:146";"SALT" -"257";"item@basegame:145";"GEM,SIO2,AMETHYST" -"258";"item@basegame:144";"GEM,SIO2,QUARTZ" -"259";"item@basegame:147";"GEM,NITRE" +"256";"item@basegame:146";"SALT";0 +"257";"item@basegame:145";"GEM,SIO2,AMETHYST";0 +"258";"item@basegame:144";"GEM,SIO2,QUARTZ";0 +"259";"item@basegame:147";"GEM,NITRE";0 -#"260";"item@basegame:136";"GEM,RUBY" -#"261";"item@basegame:137";"GEM,EMERALD" -#"262";"item@basegame:138";"GEM,SAPPHIRE" -#"263";"item@basegame:139";"GEM,TOPAZ" -#"264";"item@basegame:140";"GEM,DIAMOND" +#"260";"item@basegame:136";"GEM,RUBY";100663296 +#"261";"item@basegame:137";"GEM,EMERALD";100663296 +#"262";"item@basegame:138";"GEM,SAPPHIRE";100663296 +#"263";"item@basegame:139";"GEM,TOPAZ";100663296 +#"264";"item@basegame:140";"GEM,DIAMOND";100663296 -#"512";"macro@BASETILE";"GRASS" -#"513";"macro@BASETILE";"MOSS" \ No newline at end of file +#"512";"macro@BASETILE";"GRASS";100663296 +#"513";"macro@BASETILE";"MOSS";100663296 \ No newline at end of file diff --git a/src/net/torvald/terrarum/blockproperties/OreCodex.kt b/src/net/torvald/terrarum/blockproperties/OreCodex.kt index 2f90bddfd..9c0bf5936 100644 --- a/src/net/torvald/terrarum/blockproperties/OreCodex.kt +++ b/src/net/torvald/terrarum/blockproperties/OreCodex.kt @@ -56,6 +56,7 @@ class OreCodex { prop.id = "ores@$modname:$key" prop.tags = record.get("tags").split(',').map { it.trim().toUpperCase() }.toHashSet() prop.item = record.get("item").let { if (it == null) "" else if (it.contains(':')) it else "$modname:$it" } + prop.versionSince = record.get("versionsince").toLong() oreProps[prop.id] = prop @@ -83,6 +84,7 @@ class OreProp : TaggedProp { var id: String = "" var item: ItemID = "" var tags = HashSet() + var versionSince: Long = 0L override fun hasTag(s: String) = tags.contains(s) diff --git a/src/net/torvald/terrarum/gameworld/GameWorld.kt b/src/net/torvald/terrarum/gameworld/GameWorld.kt index 2cb0a87cc..9bb0900ef 100644 --- a/src/net/torvald/terrarum/gameworld/GameWorld.kt +++ b/src/net/torvald/terrarum/gameworld/GameWorld.kt @@ -855,7 +855,7 @@ open class GameWorld( layerFluids.unsafeSetTile(x, y, fluidNumber, fill) } else { - layerFluids.unsafeSetTile(x, y, fluidNumber, 0f) + layerFluids.unsafeSetTile(x, y, tileNameToNumberMap[Fluid.NULL]!!, 0f) } diff --git a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt index a673e468e..c734fee97 100644 --- a/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt +++ b/src/net/torvald/terrarum/modulebasegame/EntryPoint.kt @@ -27,6 +27,9 @@ class EntryPoint : ModuleEntryPoint() { CommonResourcePool.addToLoadingList("$moduleName.items") { ItemSheet(ModMgr.getGdxFile(moduleName, "items/items.tga")) } + CommonResourcePool.addToLoadingList("$moduleName.buckets") { + ItemSheet(ModMgr.getGdxFile(moduleName, "items/buckets.tga")) + } CommonResourcePool.loadAll() diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemFluidStorage.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemFluidStorage.kt new file mode 100644 index 000000000..60cfe2c64 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemFluidStorage.kt @@ -0,0 +1,88 @@ +package net.torvald.terrarum.modulebasegame.gameitems + +import net.torvald.terrarum.BlockCodex +import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.INGAME +import net.torvald.terrarum.blockproperties.Fluid +import net.torvald.terrarum.gameactors.ActorWithBody +import net.torvald.terrarum.gameitems.GameItem +import net.torvald.terrarum.gameitems.ItemID +import net.torvald.terrarum.gameitems.mouseInInteractableRange +import net.torvald.terrarum.gameworld.FLUID_MIN_MASS +import net.torvald.terrarum.modulebasegame.gameactors.Pocketed + +/** + * For example, `ItemFluidStoragePrototype("item@mymod:342", 3, 1, "mymod.buckets")` will result in: + * - A bucket of type #2 that holds `fluid@mymod:3` + * + * And, `ItemFluidStoragePrototype("item@mymod:339", 0, 2, "mymod.buckets")` will result in: + * - A bucket of type #3 that is empty + * + * @param originalID ID of the item. Module name is also retrieved from this string. + * @param sheetX x-position within the sheet. Also determines the fluid ID. 0 for empty storage. + * @param sheetY y-position within the sheet. + * @param sheetName resource name of the sheet image. + * + * Created by minjaesong on 2024-09-14. + */ +open class ItemFluidStoragePrototype(originalID: ItemID, sheetX: Int, sheetY: Int, sheetName: String) : GameItem(originalID) { + + private val module = originalID.substringAfter('@').substringBefore(':') + + override var baseMass = 1.0 + override var baseToolSize: Double? = null + override var inventoryCategory = Category.POTION + override val canBeDynamic = false + override val materialId = "" + override var equipPosition = EquipPosition.HAND_GRIP + + @Transient private val fluid = if (sheetX == 0) null else "fluid@$module:$sheetX" + + init { + itemImage = CommonResourcePool.getAsItemSheet(sheetName).get(sheetX,sheetY) + } + + @Transient val itemIDRoot = originalID.substringAfter(':').toInt().and(0x7FFF_FF00) + + override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Long { return mouseInInteractableRange(actor) { mx, my, mtx, mty -> + val world = INGAME.world + val terr = world.getTileFromTerrain(mtx, mty) + val fluidAtWorld = world.getFluid(mtx, mty) + val newItemID: ItemID + + if (BlockCodex[terr].isSolid) return@mouseInInteractableRange -1L + + // empty bucket -> filled bucket + if (fluid == null) { + if (fluidAtWorld.amount < 1f - FLUID_MIN_MASS) return@mouseInInteractableRange -1L + + // TODO respect the FLUIDROOMTEMP tag + + world.setFluid(mtx, mty, fluidAtWorld.type, fluidAtWorld.amount - 1f) + newItemID = "item@$module:${itemIDRoot + fluidAtWorld.type.substringAfter(':').toInt()}" + } + // filled bucket -> empty bucket + else { + if (fluidAtWorld.type != Fluid.NULL && fluidAtWorld.type != fluid) return@mouseInInteractableRange -1L + + world.setFluid(mtx, mty, fluid, fluidAtWorld.amount + 1f) + newItemID = "item@$module:${itemIDRoot}" + } + + // spawn newItemID and add it to the inventory + (actor as Pocketed).inventory.add(newItemID) + 1L + }} +} + + +class ItemBucketWooden00(originalID: ItemID) : ItemFluidStoragePrototype(originalID, 0, 0, "basegame.buckets") +class ItemBucketWooden01(originalID: ItemID) : ItemFluidStoragePrototype(originalID, 1, 0, "basegame.buckets") +class ItemBucketWooden02(originalID: ItemID) : ItemFluidStoragePrototype(originalID, 2, 0, "basegame.buckets") +class ItemBucketWooden03(originalID: ItemID) : ItemFluidStoragePrototype(originalID, 3, 0, "basegame.buckets") + + +class ItemBucketIron00(originalID: ItemID) : ItemFluidStoragePrototype(originalID, 0, 1, "basegame.buckets") +class ItemBucketIron01(originalID: ItemID) : ItemFluidStoragePrototype(originalID, 1, 1, "basegame.buckets") +class ItemBucketIron02(originalID: ItemID) : ItemFluidStoragePrototype(originalID, 2, 1, "basegame.buckets") +class ItemBucketIron03(originalID: ItemID) : ItemFluidStoragePrototype(originalID, 3, 1, "basegame.buckets") \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt index eae7addda..f4928d8fd 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/OreItemBase.kt @@ -145,7 +145,7 @@ class OreLead(originalID: ItemID) : OreItemBase(originalID, true) { } } class OreUranium(originalID: ItemID) : OreItemBase(originalID, true) { - override var originalName = "ITEM_ORE_URANINITE" + override var originalName = "ITEM_ORE_PITCHBLENDE" init { itemImage = CommonResourcePool.getAsItemSheet("basegame.items").get(0,7) } diff --git a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Oregen.kt b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Oregen.kt index 7fe8e1a43..612b98298 100644 --- a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Oregen.kt +++ b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Oregen.kt @@ -53,7 +53,14 @@ class Oregen(world: GameWorld, isFinal: Boolean, private val caveAttenuateBiasSc val oreTiles = ores.map { it.tile } val tileToPut = - noiseValues.zip(oreTiles).firstNotNullOfOrNull { (n, tile) -> if (n > 0.5) tile else null } + noiseValues.zip(oreTiles).firstNotNullOfOrNull { (n, tile) -> + // don't generate it if versionSince of the ore is newer than the world + if (INGAME.worldGenVer != null && INGAME.worldGenVer!! < OreCodex[tile].versionSince) + null + else if (n > 0.5) tile else null + } + + val backingTile = world.getTileFromTerrain(x, y) val blockTagNonGrata = ores.firstOrNull { it.tile == tileToPut }?.blockTagNonGrata ?: hashSetOf() diff --git a/work_files/graphics/items/basegame_items.kra b/work_files/graphics/items/basegame_items.kra index 621c2b710..18162f2c7 100644 --- a/work_files/graphics/items/basegame_items.kra +++ b/work_files/graphics/items/basegame_items.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2f3c121cc3a57cf03fad8a9fab334c5956ba7682d3e68bb08fa31c7b1e310693 -size 2139531 +oid sha256:3d6288cbfad9eac944b23f67fac447b0d7ccdc435d0a8b10e70caf406c890444 +size 2139571