mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
water buckets
This commit is contained in:
@@ -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<String>()
|
||||
var versionSince: Long = 0L
|
||||
|
||||
override fun hasTag(s: String) = tags.contains(s)
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -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")
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user