diff --git a/src/building/java/net/remmintan/mods/minefortress/blocks/building/FortressBuildingBlockEntity.kt b/src/building/java/net/remmintan/mods/minefortress/blocks/building/FortressBuildingBlockEntity.kt index 0e2ac020..21f6b917 100644 --- a/src/building/java/net/remmintan/mods/minefortress/blocks/building/FortressBuildingBlockEntity.kt +++ b/src/building/java/net/remmintan/mods/minefortress/blocks/building/FortressBuildingBlockEntity.kt @@ -26,7 +26,7 @@ import net.remmintan.mods.minefortress.core.interfaces.automation.area.IAutomati import net.remmintan.mods.minefortress.core.interfaces.automation.area.IAutomationBlockInfo import net.remmintan.mods.minefortress.core.interfaces.blueprints.ProfessionType import net.remmintan.mods.minefortress.core.interfaces.buildings.IFortressBuilding -import net.remmintan.mods.minefortress.gui.BuildingScreenHandler +import net.remmintan.mods.minefortress.gui.building.BuildingScreenHandler import java.time.LocalDateTime import java.util.* diff --git a/src/gui/kotlin/net/remmintan/mods/minefortress/gui/BuildingScreen.kt b/src/gui/kotlin/net/remmintan/mods/minefortress/gui/BuildingScreen.kt deleted file mode 100644 index 9b610e0f..00000000 --- a/src/gui/kotlin/net/remmintan/mods/minefortress/gui/BuildingScreen.kt +++ /dev/null @@ -1,23 +0,0 @@ -package net.remmintan.mods.minefortress.gui - -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.gui.screen.ingame.HandledScreen -import net.minecraft.entity.player.PlayerInventory -import net.minecraft.text.Text -import net.minecraft.util.Identifier - -class BuildingScreen(handler: BuildingScreenHandler, playerInventory: PlayerInventory, title: Text) : - HandledScreen(handler, playerInventory, title) { - - - - override fun drawBackground(context: DrawContext?, delta: Float, mouseX: Int, mouseY: Int) { - - } - - companion object { - val TEXTURE = Identifier("textures/gui/container/creative_inventory/tabs.png") - const val TAB_TEXTURE_PREFIX: String = "textures/gui/container/creative_inventory/tab_" - } - -} \ No newline at end of file diff --git a/src/gui/kotlin/net/remmintan/mods/minefortress/gui/FortressHandledScreens.kt b/src/gui/kotlin/net/remmintan/mods/minefortress/gui/FortressHandledScreens.kt index 861b6899..8aeecdd4 100644 --- a/src/gui/kotlin/net/remmintan/mods/minefortress/gui/FortressHandledScreens.kt +++ b/src/gui/kotlin/net/remmintan/mods/minefortress/gui/FortressHandledScreens.kt @@ -7,6 +7,8 @@ import net.minecraft.registry.Registry import net.minecraft.resource.featuretoggle.FeatureFlags import net.minecraft.screen.ScreenHandlerType import net.minecraft.util.Identifier +import net.remmintan.mods.minefortress.gui.building.BuildingScreen +import net.remmintan.mods.minefortress.gui.building.BuildingScreenHandler val BUILDING_SCREEN_HANDLER_TYPE: ScreenHandlerType = Registry.register( Registries.SCREEN_HANDLER, diff --git a/src/gui/kotlin/net/remmintan/mods/minefortress/gui/building/BuildingScreen.kt b/src/gui/kotlin/net/remmintan/mods/minefortress/gui/building/BuildingScreen.kt new file mode 100644 index 00000000..eee5b396 --- /dev/null +++ b/src/gui/kotlin/net/remmintan/mods/minefortress/gui/building/BuildingScreen.kt @@ -0,0 +1,45 @@ +package net.remmintan.mods.minefortress.gui.building + +import net.minecraft.client.gui.DrawContext +import net.minecraft.client.gui.screen.ingame.HandledScreen +import net.minecraft.entity.player.PlayerInventory +import net.minecraft.text.Text +import net.minecraft.util.Identifier + +class BuildingScreen(handler: BuildingScreenHandler, playerInventory: PlayerInventory, title: Text) : + HandledScreen(handler, playerInventory, title) { + + + override fun drawBackground(context: DrawContext?, delta: Float, mouseX: Int, mouseY: Int) { + context?.let { + handler.tabs.forEach { tab -> renderTabIcon(it, tab) } + it.drawTexture(BACKGROUND_TEXTURE, x, y, 0, 0, backgroundWidth, backgroundHeight) + } + } + + private fun renderTabIcon(context: DrawContext, tab: BuildingScreenTab) { + val u = tab.column * 26 + val v = if (tab === handler.selectedTab) 32 else 0 + val x: Int = this.x + tab.tabX + val y = this.y - 28 + + context.drawTexture(TABS_TEXTURE, x, y, u, v, 26, 32) + + context.matrices.push() + context.matrices.translate(0.0f, 0.0f, 100.0f) + + val iconX = x + 5 + val iconY = y + 9 + context.drawItem(tab.icon, iconX, iconY) + context.drawItemInSlot(textRenderer, tab.icon, iconX, iconY) + + context.matrices.pop() + } + + + companion object { + val TABS_TEXTURE = Identifier("textures/gui/container/creative_inventory/tabs.png") + val BACKGROUND_TEXTURE = Identifier("textures/gui/demo_background.png") + } + +} \ No newline at end of file diff --git a/src/gui/kotlin/net/remmintan/mods/minefortress/gui/BuildingScreenHandler.kt b/src/gui/kotlin/net/remmintan/mods/minefortress/gui/building/BuildingScreenHandler.kt similarity index 52% rename from src/gui/kotlin/net/remmintan/mods/minefortress/gui/BuildingScreenHandler.kt rename to src/gui/kotlin/net/remmintan/mods/minefortress/gui/building/BuildingScreenHandler.kt index fcf2ea56..8d77c668 100644 --- a/src/gui/kotlin/net/remmintan/mods/minefortress/gui/BuildingScreenHandler.kt +++ b/src/gui/kotlin/net/remmintan/mods/minefortress/gui/building/BuildingScreenHandler.kt @@ -1,16 +1,26 @@ -package net.remmintan.mods.minefortress.gui +package net.remmintan.mods.minefortress.gui.building import net.minecraft.entity.player.PlayerEntity import net.minecraft.item.ItemStack +import net.minecraft.item.Items import net.minecraft.screen.ArrayPropertyDelegate import net.minecraft.screen.PropertyDelegate import net.minecraft.screen.ScreenHandler +import net.remmintan.mods.minefortress.core.isClientInFortressGamemode +import net.remmintan.mods.minefortress.gui.BUILDING_SCREEN_HANDLER_TYPE class BuildingScreenHandler( syncId: Int, propertyDelegate: PropertyDelegate = ArrayPropertyDelegate(3) ) : ScreenHandler(BUILDING_SCREEN_HANDLER_TYPE, syncId) { + val tabs = listOf( + BuildingScreenTab(Items.COBBLESTONE, 0), + BuildingScreenTab(Items.PLAYER_HEAD, 1), + BuildingScreenTab(Items.DIAMOND, 2), + ) + var selectedTab = tabs[0] + init { addProperties(propertyDelegate) } @@ -19,7 +29,6 @@ class BuildingScreenHandler( return ItemStack.EMPTY } - override fun canUse(player: PlayerEntity?): Boolean = true - + override fun canUse(player: PlayerEntity?): Boolean = isClientInFortressGamemode() } \ No newline at end of file diff --git a/src/gui/kotlin/net/remmintan/mods/minefortress/gui/building/BuildingScreenTab.kt b/src/gui/kotlin/net/remmintan/mods/minefortress/gui/building/BuildingScreenTab.kt new file mode 100644 index 00000000..c83803f9 --- /dev/null +++ b/src/gui/kotlin/net/remmintan/mods/minefortress/gui/building/BuildingScreenTab.kt @@ -0,0 +1,9 @@ +package net.remmintan.mods.minefortress.gui.building + +import net.minecraft.item.Item +import net.minecraft.item.ItemStack + +class BuildingScreenTab(icon: Item, val column: Int) { + val tabX = 27 * column + val icon = ItemStack(icon) +} \ No newline at end of file