feat: working block implementation
This commit is contained in:
parent
23981fb9ca
commit
802bbb6c7b
31 changed files with 1580 additions and 51 deletions
|
|
@ -0,0 +1,134 @@
|
|||
package xyz.nuark.mcmod.enct.screen
|
||||
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import xyz.nuark.mcmod.enct.Enchantmenttransfer
|
||||
import xyz.nuark.mcmod.enct.block.entity.EnchantmentTransferrerBlockEntity
|
||||
import xyz.nuark.mcmod.enct.menu.EnchantmentTransferrerMenu
|
||||
|
||||
class EnchantmentTransferrerScreen(
|
||||
menu: EnchantmentTransferrerMenu,
|
||||
playerInventory: Inventory,
|
||||
title: Component
|
||||
) : AbstractContainerScreen<EnchantmentTransferrerMenu>(menu, playerInventory, title) {
|
||||
|
||||
companion object {
|
||||
val BACKGROUND_LOCATION: ResourceLocation = ResourceLocation.fromNamespaceAndPath(Enchantmenttransfer.ID, "textures/gui/enchantment_transferrer.png")
|
||||
val PROGRESS_GAUGE: ResourceLocation = ResourceLocation.fromNamespaceAndPath(Enchantmenttransfer.ID, "textures/gui/ets_gauge.png")
|
||||
|
||||
const val GAUGE_WIDTH = 117
|
||||
const val GAUGE_HEIGHT = 7
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
super.init()
|
||||
|
||||
imageWidth = 176
|
||||
imageHeight = 154
|
||||
}
|
||||
|
||||
override fun renderBg(guiGraphics: GuiGraphics, partialTick: Float, mouseX: Int, mouseY: Int) {
|
||||
guiGraphics.blit(BACKGROUND_LOCATION, leftPos, topPos, 0, 0, imageWidth, imageHeight)
|
||||
|
||||
// Progress bar
|
||||
if (menu.isProcessing()) {
|
||||
val progress = menu.getProcessTime()
|
||||
val total = menu.getTotalTime()
|
||||
if (total > 0) {
|
||||
val progressWidth = ((progress.toDouble() / total) * GAUGE_WIDTH).toInt()
|
||||
guiGraphics.blit(PROGRESS_GAUGE, leftPos+33, topPos+5, 0f, 0f, progressWidth, GAUGE_HEIGHT, GAUGE_WIDTH, GAUGE_HEIGHT)
|
||||
}
|
||||
}
|
||||
|
||||
// Charge bar
|
||||
val charge = menu.getCharge()
|
||||
val maxCharge = EnchantmentTransferrerBlockEntity.MAX_CHARGE
|
||||
if (charge > 0) {
|
||||
val chargeWidth = ((charge.toDouble() / maxCharge) * GAUGE_WIDTH).toInt()
|
||||
guiGraphics.blit(PROGRESS_GAUGE, leftPos+33, topPos+50, 0f, 0f, chargeWidth, GAUGE_HEIGHT, GAUGE_WIDTH, GAUGE_HEIGHT)
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderLabels(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int) {
|
||||
// No labels for me, thanks
|
||||
}
|
||||
|
||||
override fun renderTooltip(guiGraphics: GuiGraphics, x: Int, y: Int) {
|
||||
val xRange = (leftPos + 33)..(leftPos + 33 + GAUGE_WIDTH)
|
||||
|
||||
when (y) {
|
||||
in (topPos + 5)..(topPos + 5 + GAUGE_HEIGHT) if x in xRange -> { // Over progress bar
|
||||
val progress = menu.getProcessTime()
|
||||
val total = menu.getTotalTime()
|
||||
val processing = menu.isProcessing()
|
||||
|
||||
val status = if (total > 0 && processing) {
|
||||
val perc = ((progress.toDouble() / total) * 100).toInt()
|
||||
"$perc%"
|
||||
} else if (total > 0) {
|
||||
Component.translatable("container.enct.processing.waiting").withColor(0xFFFF00)
|
||||
} else {
|
||||
Component.translatable("container.enct.processing.idle").withColor(0x00FFFF)
|
||||
}
|
||||
|
||||
guiGraphics.renderTooltip(
|
||||
this.font,
|
||||
Component.translatable("container.enct.processing", status),
|
||||
x,
|
||||
y
|
||||
)
|
||||
}
|
||||
in (topPos + 50)..(topPos + 50 + GAUGE_HEIGHT) if x in xRange -> { // Over charge bar
|
||||
val charge = menu.getCharge()
|
||||
guiGraphics.renderTooltip(
|
||||
this.font,
|
||||
Component.translatable("container.enct.charge", charge.toString()),
|
||||
x,
|
||||
y
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
val hoveredSlot = this.hoveredSlot
|
||||
if (hoveredSlot != null && !hoveredSlot.hasItem()) { // Showing tooltips for empty slots
|
||||
when (hoveredSlot.slotIndex) {
|
||||
EnchantmentTransferrerBlockEntity.SLOT_MAIN -> guiGraphics.renderTooltip(
|
||||
this.font,
|
||||
Component.translatable("container.enct.info.main"),
|
||||
x,
|
||||
y
|
||||
)
|
||||
EnchantmentTransferrerBlockEntity.SLOT_TARGET -> guiGraphics.renderTooltip(
|
||||
this.font,
|
||||
Component.translatable("container.enct.info.target"),
|
||||
x,
|
||||
y
|
||||
)
|
||||
EnchantmentTransferrerBlockEntity.SLOT_BOOK -> guiGraphics.renderTooltip(
|
||||
this.font,
|
||||
Component.translatable("container.enct.info.book"),
|
||||
x,
|
||||
y
|
||||
)
|
||||
EnchantmentTransferrerBlockEntity.SLOT_FUEL -> guiGraphics.renderTooltip(
|
||||
this.font,
|
||||
Component.translatable("container.enct.info.fuel"),
|
||||
x,
|
||||
y
|
||||
)
|
||||
}
|
||||
} else {
|
||||
super.renderTooltip(guiGraphics, x, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, partialTick: Float) {
|
||||
renderBackground(guiGraphics, mouseX, mouseY, partialTick)
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTick)
|
||||
renderTooltip(guiGraphics, mouseX, mouseY)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue