metal working station and recipes

This commit is contained in:
minjaesong
2023-12-06 00:22:35 +09:00
parent 0d290dfc1f
commit ceea2ff1a2
14 changed files with 212 additions and 10 deletions

View File

@@ -0,0 +1,104 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.gdx.graphics.Cvec
import net.torvald.spriteanimation.SheetSpriteAnimation
import net.torvald.terrarum.*
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Lightbox
import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2023-12-05.
*/
class FixtureMetalworkingStation : FixtureBase, CraftingStation {
@Transient override val spawnNeedsFloor = true
@Transient override val tags = listOf("metalworking")
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 3, 2), // temporary value, will be overwritten by spawn()
nameFun = { Lang["ITEM_SMELTER_BASIC"] }
) {
CommonResourcePool.addToLoadingList("particles-tiki_smoke.tga") {
TextureRegionPack(ModMgr.getGdxFile("basegame", "particles/bigger_smoke.tga"), 16, 16)
}
CommonResourcePool.loadAll()
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/metalworking_furnace_and_anvil.tga")
// val itemImage2 = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/metalworking_furnace_and_anvil_illum.tga") // put this sprite to the hypothetical "SpriteIllum"
density = BlockCodex[Block.STONE].density.toDouble()
setHitboxDimension(itemImage.texture.width, itemImage.texture.height, 0, 0)
makeNewSprite(TextureRegionPack(itemImage.texture, itemImage.texture.width, itemImage.texture.height)).let {
it.setRowsAndFrames(1,1)
}
/*makeNewSpriteGlow(TextureRegionPack(itemImage2.texture, itemImage.texture.width, itemImage.texture.height)).let {
it.setRowsAndFrames(1,1)
}*/
actorValue[AVKey.BASEMASS] = 100.0
mainUIopenFun = { ui ->
(mainUI as? UIInventoryFull)?.openCrafting(mainUI!!.handler)
}
}
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TerrarumAppConfiguration.TILE_SIZED * 2, TerrarumAppConfiguration.TILE_SIZED * 2), Cvec(0.5f, 0.18f, 0f, 0f)))
@Transient private val actorBlocks = arrayOf(
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, null),
arrayOf(Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION, Block.ACTORBLOCK_NO_COLLISION),
)
override fun placeActorBlocks() {
forEachBlockbox { x, y, ox, oy ->
val tile = actorBlocks[oy][ox]
if (tile != null) {
world!!.setTileTerrain(x, y, tile, true)
}
}
}
private var nextDelay = 0.25f
private var spawnTimer = 0f
@Transient private var mainUIhookHackInstalled = false
override fun update(delta: Float) {
// adding UI to the fixture as players may right-click on the workbenches instead of pressing a keyboard key
(INGAME as? TerrarumIngame)?.let { ingame ->
if (!mainUIhookHackInstalled && ingame.uiInventoryPlayerReady) {
mainUIhookHackInstalled = true
this.mainUI = ingame.uiInventoryPlayer // this field is initialised only after a full load so this hack is necessary
}
}
super.update(delta)
// emit smokes TODO: only when hot
if (spawnTimer >= nextDelay) {
(Terrarum.ingame as TerrarumIngame).addParticle(
ParticleVanishingSprite(
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
25f, true, hitbox.startX + TerrarumAppConfiguration.TILE_SIZED, hitbox.startY + 21, false, (Math.random() * 256).toInt()
)
)
spawnTimer -= nextDelay
nextDelay = Math.random().toFloat() * 0.25f + 0.25f
(sprite as? SheetSpriteAnimation)?.delays?.set(0, Math.random().toFloat() * 0.4f + 0.1f)
}
spawnTimer += delta
}
}

View File

@@ -48,7 +48,7 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
it.setRowsAndFrames(1,1)
}*/
actorValue[AVKey.BASEMASS] = 50.0
actorValue[AVKey.BASEMASS] = 100.0
mainUIopenFun = { ui ->
(mainUI as? UIInventoryFull)?.openCrafting(mainUI!!.handler)