Skip to content

Commit

Permalink
Debug Energy Hatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Taskeren committed Aug 20, 2024
1 parent 250502b commit 39aca8d
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 24 deletions.
18 changes: 16 additions & 2 deletions src/main/kotlin/cn/taskeren/op/gt/init/OP_GTRegistrar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cn.taskeren.op.gt.init

import cn.taskeren.op.gt.registerMachine
import cn.taskeren.op.gt.single.OP_ActiveTransformerRack
import cn.taskeren.op.gt.single.OP_DebugEnergyHatch
import cn.taskeren.op.gt.single.OP_OverpowerMachine

object OP_GTRegistrar {
Expand All @@ -11,13 +12,26 @@ object OP_GTRegistrar {
}

private fun registerSingleMachines() {
// #tr OP_NameOverpowerMachine
// #en Incredible Malicious Machine Overpowering System
// #zh 超级绝绝子机器强化系统
OP_MachineItemList.OverpowerMachine.registerMachine {
OP_OverpowerMachine(it, "OP_NameOverpowerMachine", "Overpower Machine", 9)
OP_OverpowerMachine(it, "OP_NameOverpowerMachine", "Incredible Malicious Machine Overpowering System", 9)
}
// #tr OP_NameActiveTransformerRack
// #en Active Transformer Rack
// #zh 有源变压器机械架
// #tw 有源變壓器機械架
OP_MachineItemList.ActiveTransformerRack.registerMachine {
OP_ActiveTransformerRack(it, "OP_NameActiveTransformerRack", "Active Transformer Rack", 9)
}

// #tr OP_NameDebugEnergyHatch
// #en Ascendant Realm Paracausal Manipulating Unit
// #zh 上维领域超因果单元
// #tw 高等維度超因果單元
OP_MachineItemList.DebugEnergyHatch.registerMachine {
OP_DebugEnergyHatch(it, "OP_NameDebugEnergyHatch", "Ascendant Realm Paracausal Manipulating Unit")
}
}

}
2 changes: 2 additions & 0 deletions src/main/kotlin/cn/taskeren/op/gt/init/OP_MachineItemList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum class OP_MachineItemList(override val id: Short) : IdItemContainer, OP_Logg
OverpowerMachine(14301),
ActiveTransformerRack(14302),

DebugEnergyHatch(17508),

;

private lateinit var theItem: ItemStack
Expand Down
211 changes: 211 additions & 0 deletions src/main/kotlin/cn/taskeren/op/gt/single/OP_DebugEnergyHatch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
package cn.taskeren.op.gt.single

import cn.taskeren.op.gt.utils.InfoDataBuilder
import cn.taskeren.op.gt.utils.OP_Text
import cn.taskeren.op.gt.utils.extension.button
import cn.taskeren.op.gt.utils.extension.drawable
import cn.taskeren.op.gt.utils.extension.numeric
import cn.taskeren.op.gt.utils.extension.text
import com.github.technus.tectech.util.TT_Utility
import com.gtnewhorizons.modularui.api.drawable.IDrawable
import com.gtnewhorizons.modularui.api.screen.ModularWindow
import com.gtnewhorizons.modularui.api.screen.UIBuildContext
import gregtech.api.enums.GT_Values
import gregtech.api.gui.modularui.GT_UIInfos
import gregtech.api.gui.modularui.GT_UITextures
import gregtech.api.interfaces.ITexture
import gregtech.api.interfaces.tileentity.IGregTechTileEntity
import gregtech.api.interfaces.tileentity.IWirelessEnergyHatchInformation
import gregtech.api.metatileentity.MetaTileEntity
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
import java.util.function.DoubleConsumer
import java.util.function.DoubleSupplier
import java.util.function.IntConsumer
import kotlin.math.abs

class OP_DebugEnergyHatch : GT_MetaTileEntity_Hatch_Energy, IWirelessEnergyHatchInformation {

private var eu: Long = 0
private var amp: Long = 0

companion object {
val DESC = arrayOf(
"Energy Injector for Multiblocks",
"Infinite and Customizable EU and Amp",
InfoDataBuilder.RED + "CREATIVE EXCLUSIVE",
OP_Text.TOOLTIP_CREDIT_NOVELTY,
)
}

constructor(aID: Int, aName: String, aNameRegional: String) : super(aID, aName, aNameRegional, 12, DESC)

constructor(aName: String, aDescription: Array<String>, aTextures: Array<Array<Array<ITexture>>>) : super(
aName,
12,
aDescription,
aTextures
)

override fun newMetaEntity(aTileEntity: IGregTechTileEntity?): MetaTileEntity? {
return OP_DebugEnergyHatch(mName, mDescriptionArray, mTextures)
}

override fun saveNBTData(aNBT: NBTTagCompound) {
super.saveNBTData(aNBT)
aNBT.setLong("EUT", eu)
aNBT.setLong("AMP", amp)
}

override fun loadNBTData(aNBT: NBTTagCompound) {
super.loadNBTData(aNBT)
eu = aNBT.getLong("EUT")
amp = aNBT.getLong("AMP")
}

override fun getMinimumStoredEU(): Long {
return 2 * eu
}

override fun maxEUInput(): Long {
return eu
}

override fun maxEUStore(): Long {
return totalStorage(eu)
}

override fun maxAmperesIn(): Long {
return amp
}

override fun getConnectionType(): ConnectionType {
return ConnectionType.WIRELESS
}

override fun onFirstTick(aBaseMetaTileEntity: IGregTechTileEntity) {
super.onFirstTick(aBaseMetaTileEntity)

if(aBaseMetaTileEntity.isServerSide) {
euVar = Long.MAX_VALUE
}
}

override fun onPreTick(aBaseMetaTileEntity: IGregTechTileEntity, aTick: Long) {
super.onPreTick(aBaseMetaTileEntity, aTick)

if(aBaseMetaTileEntity.isServerSide) {
if(aTick % IWirelessEnergyHatchInformation.ticks_between_energy_addition == 0L) {
euVar = Long.MAX_VALUE
}
}
}

override fun onRightclick(aBaseMetaTileEntity: IGregTechTileEntity, aPlayer: EntityPlayer): Boolean {
GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer)
return true
}

override fun useModularUI(): Boolean {
return true
}

override fun addUIWidgets(builder: ModularWindow.Builder, buildContext: UIBuildContext) {
builder.apply {
drawable {
setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK)
setSize(90, 72)
setPos(43, 4)
}
text {
setStringSupplier { "TIER: " + GT_Values.VN[TT_Utility.getTier(abs(eu)).toInt()] }
setDefaultColor(COLOR_TEXT_WHITE.get())
setPos(46, 22)
}
text {
setStringSupplier { "SUM: " + numberFormat.format(amp * eu) }
setDefaultColor(COLOR_TEXT_WHITE.get())
setPos(46, 46)
}

addLabelledIntegerTextField(
"EUT: ",
24,
DoubleSupplier { eu.toDouble() },
DoubleConsumer { eu = it.toLong() },
46,
8
)
addLabelledIntegerTextField(
"AMP: ",
24,
DoubleSupplier { amp.toDouble() },
DoubleConsumer { amp = it.toLong() },
46,
34
)

addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, IntConsumer { eu -= it }, 512, 64, 7, 4)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, IntConsumer { eu /= it }, 512, 64, 7, 22)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, IntConsumer { amp -= it }, 512, 64, 7, 40)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, IntConsumer { amp /= it }, 512, 64, 7, 58)

addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_MINUS_SMALL, IntConsumer { eu -= it }, 16, 1, 25, 4)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_MINUS_SMALL, IntConsumer { eu /= it }, 16, 2, 25, 22)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_MINUS_SMALL, IntConsumer { amp -= it }, 16, 1, 25, 40)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_MINUS_SMALL, IntConsumer { amp /= it }, 16, 2, 25, 58)

addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_PLUS_SMALL, IntConsumer { eu += it }, 16, 1, 133, 4)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_PLUS_SMALL, IntConsumer { eu *= it }, 16, 2, 133, 22)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_PLUS_SMALL, IntConsumer { amp += it }, 16, 1, 133, 40)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_PLUS_SMALL, IntConsumer { amp *= it }, 16, 2, 133, 58)

addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE, IntConsumer { eu += it }, 512, 64, 151, 4)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE, IntConsumer { eu *= it }, 512, 64, 151, 22)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE, IntConsumer { amp += it }, 512, 64, 151, 40)
addChangeNumberButton(GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE, IntConsumer { amp *= it }, 512, 64, 151, 58)
}
}

fun ModularWindow.Builder.addLabelledIntegerTextField(
label: String,
labelWidth: Int,
getter: DoubleSupplier,
setter: DoubleConsumer,
xPos: Int,
yPos: Int
) {
text(label) {
setDefaultColor(COLOR_TEXT_WHITE.get())
setPos(xPos, yPos)
}
numeric {
setGetter(getter)
setSetter(setter)
setTextColor(COLOR_TEXT_WHITE.get())
setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD.withOffset(-1F, -1F, 2F, 2F))
setPos(xPos + labelWidth, yPos - 1)
setSize(56, 10)
}
}

fun ModularWindow.Builder.addChangeNumberButton(
overlay: IDrawable,
setter: IntConsumer,
changeNumberShift: Int,
changeNumber: Int,
xPos: Int,
yPos: Int
) {
button {
setOnClick { clickData, widget ->
setter.accept(if(clickData.shift) changeNumberShift else changeNumber)
}
setBackground(GT_UITextures.BUTTON_STANDARD, overlay)
setSize(18, 18)
setPos(xPos, yPos)
}
}

}
44 changes: 22 additions & 22 deletions src/main/kotlin/cn/taskeren/op/gt/utils/InfoDataBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import net.minecraft.util.EnumChatFormatting
data class InfoDataBuilder(private val infoDataList: MutableList<String> = mutableListOf()) {

companion object {
private val BLACK = EnumChatFormatting.BLACK.toString()
private val DARK_BLUE = EnumChatFormatting.DARK_BLUE.toString()
private val DARK_GREEN = EnumChatFormatting.DARK_GREEN.toString()
private val DARK_AQUA = EnumChatFormatting.DARK_AQUA.toString()
private val DARK_RED = EnumChatFormatting.DARK_RED.toString()
private val DARK_PURPLE = EnumChatFormatting.DARK_PURPLE.toString()
private val GOLD = EnumChatFormatting.GOLD.toString()
private val GRAY = EnumChatFormatting.GRAY.toString()
private val DARK_GRAY = EnumChatFormatting.DARK_GRAY.toString()
private val BLUE = EnumChatFormatting.BLUE.toString()
private val GREEN = EnumChatFormatting.GREEN.toString()
private val AQUA = EnumChatFormatting.AQUA.toString()
private val RED = EnumChatFormatting.RED.toString()
private val LIGHT_PURPLE = EnumChatFormatting.LIGHT_PURPLE.toString()
private val YELLOW = EnumChatFormatting.YELLOW.toString()
private val WHITE = EnumChatFormatting.WHITE.toString()
private val OBFUSCATED = EnumChatFormatting.OBFUSCATED.toString()
private val BOLD = EnumChatFormatting.BOLD.toString()
private val STRIKETHROUGH = EnumChatFormatting.STRIKETHROUGH.toString()
private val UNDERLINE = EnumChatFormatting.UNDERLINE.toString()
private val ITALIC = EnumChatFormatting.ITALIC.toString()
private val RESET = EnumChatFormatting.RESET.toString()
val BLACK = EnumChatFormatting.BLACK.toString()
val DARK_BLUE = EnumChatFormatting.DARK_BLUE.toString()
val DARK_GREEN = EnumChatFormatting.DARK_GREEN.toString()
val DARK_AQUA = EnumChatFormatting.DARK_AQUA.toString()
val DARK_RED = EnumChatFormatting.DARK_RED.toString()
val DARK_PURPLE = EnumChatFormatting.DARK_PURPLE.toString()
val GOLD = EnumChatFormatting.GOLD.toString()
val GRAY = EnumChatFormatting.GRAY.toString()
val DARK_GRAY = EnumChatFormatting.DARK_GRAY.toString()
val BLUE = EnumChatFormatting.BLUE.toString()
val GREEN = EnumChatFormatting.GREEN.toString()
val AQUA = EnumChatFormatting.AQUA.toString()
val RED = EnumChatFormatting.RED.toString()
val LIGHT_PURPLE = EnumChatFormatting.LIGHT_PURPLE.toString()
val YELLOW = EnumChatFormatting.YELLOW.toString()
val WHITE = EnumChatFormatting.WHITE.toString()
val OBFUSCATED = EnumChatFormatting.OBFUSCATED.toString()
val BOLD = EnumChatFormatting.BOLD.toString()
val STRIKETHROUGH = EnumChatFormatting.STRIKETHROUGH.toString()
val UNDERLINE = EnumChatFormatting.UNDERLINE.toString()
val ITALIC = EnumChatFormatting.ITALIC.toString()
val RESET = EnumChatFormatting.RESET.toString()
}

val black = BLACK
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/cn/taskeren/op/gt/utils/OP_Text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ object OP_Text {

val TOOLTIP_CREDIT = "${ECF.BLUE}Presented by ${ECF.GOLD}${ECF.BOLD}Overpowered${ECF.BLUE}!"

val TOOLTIP_CREDIT_NOVELTY = "${InfoDataBuilder.BLUE}Presented by ${InfoDataBuilder.GOLD}${InfoDataBuilder.BOLD}Overpowered ${InfoDataBuilder.BLUE}from ${InfoDataBuilder.AQUA}Novelty!"

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cn.taskeren.op.gt.utils.extension
import com.gtnewhorizons.modularui.api.forge.ItemStackHandler
import com.gtnewhorizons.modularui.api.screen.ModularWindow
import com.gtnewhorizons.modularui.api.widget.Widget
import com.gtnewhorizons.modularui.common.widget.ButtonWidget
import com.gtnewhorizons.modularui.common.widget.DrawableWidget
import com.gtnewhorizons.modularui.common.widget.SlotWidget
import com.gtnewhorizons.modularui.common.widget.TextWidget
import com.gtnewhorizons.modularui.common.widget.textfield.NumericWidget

fun ModularWindow.Builder.widget(block: () -> Widget) = apply { widget(block()) }

Expand All @@ -17,6 +19,18 @@ fun ModularWindow.Builder.slot(inventoryHandler: ItemStackHandler, slot: Int, bl
SlotWidget(inventoryHandler, slot).apply(block)
}

fun ModularWindow.Builder.text(block: TextWidget.() -> Unit) = widget {
TextWidget().apply(block)
}

fun ModularWindow.Builder.text(text: String, block: TextWidget.() -> Unit) = widget {
TextWidget(text).apply(block)
}

fun ModularWindow.Builder.numeric(block: NumericWidget.() -> Unit) = widget {
NumericWidget().apply(block)
}

fun ModularWindow.Builder.button(block: ButtonWidget.() -> Unit) = widget {
ButtonWidget().apply(block)
}

0 comments on commit 39aca8d

Please sign in to comment.