fix: workbench failes to load because uiInventoryPlayer is uninit'd at the load time

This commit is contained in:
minjaesong
2023-10-06 14:18:14 +09:00
parent 9f93832d81
commit 781f671859
2 changed files with 17 additions and 2 deletions

View File

@@ -21,8 +21,7 @@ class FixtureWorkbench : FixtureBase, CraftingStation {
constructor() : super(
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 2, 1),
nameFun = { Lang["ITEM_WORKBENCH"] },
mainUI = (INGAME as? TerrarumIngame)?.uiInventoryPlayer
nameFun = { Lang["ITEM_WORKBENCH"] }
) {
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/workbench.tga")
@@ -40,4 +39,17 @@ class FixtureWorkbench : FixtureBase, CraftingStation {
}
}
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)
}
}