Skip to content

Commit

Permalink
Start implementing new building scree
Browse files Browse the repository at this point in the history
  • Loading branch information
remmintan committed Dec 7, 2024
1 parent 9f05534 commit 149fa8a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<BuildingScreenHandler> = Registry.register(
Registries.SCREEN_HANDLER,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BuildingScreenHandler>(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")
}

}
Original file line number Diff line number Diff line change
@@ -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)
}
Expand All @@ -19,7 +29,6 @@ class BuildingScreenHandler(
return ItemStack.EMPTY
}

override fun canUse(player: PlayerEntity?): Boolean = true

override fun canUse(player: PlayerEntity?): Boolean = isClientInFortressGamemode()

}
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 149fa8a

Please sign in to comment.