Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package gregtechlite.gtlitecore.api.metatileentity.multiblock

import gregtech.api.capability.GregtechDataCodes
import gregtech.api.capability.GregtechTileCapabilities
import gregtech.api.capability.IControllable
import gregtech.api.capability.IEnergyContainer
import gregtech.api.capability.IWorkable
import gregtech.api.capability.*
import gregtech.api.capability.impl.EnergyContainerHandler
import gregtech.api.capability.impl.EnergyContainerList
import gregtech.api.metatileentity.multiblock.IMultiblockPart
import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase
import gregtech.api.pattern.BlockPattern
Expand All @@ -27,7 +24,8 @@ import kotlin.math.pow
abstract class ModuleMultiblockBase(metaTileEntityId: ResourceLocation,
protected val tier: Int,
protected val moduleTier: Int,
protected val minCasingTier: Int) : MultiblockWithDisplayBase(metaTileEntityId), ModuleReceiver, IWorkable, IControllable
protected val minCasingTier: Int) : MultiblockWithDisplayBase(metaTileEntityId),
ModuleReceiver, IWorkable, IControllable
{

override var moduleProvider: ModuleProvider? = null
Expand All @@ -41,8 +39,10 @@ abstract class ModuleMultiblockBase(metaTileEntityId: ResourceLocation,

@JvmField
protected var isActive: Boolean = false

@JvmField
protected var maxProgress: Int = 0

@JvmField
protected var progress: Int = 0

Expand All @@ -61,9 +61,9 @@ abstract class ModuleMultiblockBase(metaTileEntityId: ResourceLocation,
init
{
this.energyContainer = EnergyContainerHandler(
this,
(160008000 * 4.0.pow((this.tier - 9).toDouble())).toLong(), this.energyConsumed,
1, 0, 0
this,
(160008000L * 4.0.pow((this.tier - 9).toDouble())).toLong(), this.energyConsumed,
1, 0, 0
)
}

Expand Down Expand Up @@ -127,13 +127,30 @@ abstract class ModuleMultiblockBase(metaTileEntityId: ResourceLocation,
}
}

fun getCombinedEnergyContainer(): IEnergyContainer
{
return if (moduleProvider?.subEnergyContainer == null)
{
EnergyContainerHandler(this, 0, 0, 0, 0, 0)
}
else
{
EnergyContainerList(
listOf(
this.moduleProvider!!.subEnergyContainer,
this.energyContainer
)
)
}
}

override fun <T : Any> getCapability(capability: Capability<T>, side: EnumFacing?): T?
{
if (capability === GregtechTileCapabilities.CAPABILITY_WORKABLE) return GregtechTileCapabilities.CAPABILITY_WORKABLE.cast(
this
this
)
if (capability === GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) return GregtechTileCapabilities.CAPABILITY_CONTROLLABLE.cast(
this
this
)
return super.getCapability<T>(capability, side)
}
Expand Down Expand Up @@ -202,7 +219,7 @@ abstract class ModuleMultiblockBase(metaTileEntityId: ResourceLocation,
isActive = active
markDirty()
if (world != null && !world.isRemote) writeCustomData(
GregtechDataCodes.WORKABLE_ACTIVE
GregtechDataCodes.WORKABLE_ACTIVE
) { buf: PacketBuffer? -> buf!!.writeBoolean(active) }
}
}
Expand All @@ -214,24 +231,19 @@ abstract class ModuleMultiblockBase(metaTileEntityId: ResourceLocation,

protected fun drainEnergy(simulate: Boolean, energy: Long): Boolean
{
val result = energyContainer.energyStored - energy
if (result >= 0L && result <= energyContainer.energyCapacity)
val container = getCombinedEnergyContainer()
val result = container.energyStored - energy
if (result >= 0L && result <= container.energyCapacity)
{
if (!simulate) energyContainer.changeEnergy(-energy)
if (!simulate) container.changeEnergy(-energy)
return true
}
return false
}

protected fun drainEnergy(simulate: Boolean): Boolean
{
val result = energyContainer.energyStored - energyContainer.inputVoltage
if (result >= 0L && result <= energyContainer.energyCapacity)
{
if (!simulate) energyContainer.changeEnergy(-energyContainer.inputVoltage)
return true
}
return false
return drainEnergy(simulate, energyContainer.inputVoltage)
}

@SideOnly(Side.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ import gregtech.api.capability.impl.EnergyContainerList
import gregtech.api.metatileentity.MetaTileEntity
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity
import gregtech.api.metatileentity.multiblock.IMultiblockPart
import gregtech.api.metatileentity.multiblock.MultiblockAbility.COMPUTATION_DATA_RECEPTION
import gregtech.api.metatileentity.multiblock.MultiblockAbility.EXPORT_FLUIDS
import gregtech.api.metatileentity.multiblock.MultiblockAbility.EXPORT_ITEMS
import gregtech.api.metatileentity.multiblock.MultiblockAbility.IMPORT_FLUIDS
import gregtech.api.metatileentity.multiblock.MultiblockAbility.IMPORT_ITEMS
import gregtech.api.metatileentity.multiblock.MultiblockAbility.INPUT_ENERGY
import gregtech.api.metatileentity.multiblock.MultiblockAbility.INPUT_LASER
import gregtech.api.metatileentity.multiblock.MultiblockAbility.SUBSTATION_INPUT_ENERGY
import gregtech.api.metatileentity.multiblock.MultiblockAbility.*
import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase
import gregtech.api.metatileentity.multiblock.ui.MultiblockUIBuilder
import gregtech.api.metatileentity.multiblock.ui.MultiblockUIFactory
Expand All @@ -33,11 +26,8 @@ import gregtech.api.pattern.PatternMatchContext
import gregtech.api.pattern.TraceabilityPredicate
import gregtech.api.unification.material.Materials.Neutronium
import gregtech.api.util.KeyUtil
import gregtech.api.util.RelativeDirection.DOWN
import gregtech.api.util.RelativeDirection.FRONT
import gregtech.api.util.RelativeDirection.RIGHT
import gregtech.api.util.RelativeDirection.*
import gregtech.client.renderer.ICubeRenderer
import gregtech.common.ConfigHolder
import gregtechlite.gtlitecore.api.GTLiteAPI.ACCELERATION_TRACK_TIER
import gregtechlite.gtlitecore.api.SECOND
import gregtechlite.gtlitecore.api.capability.ModuleProvider
Expand All @@ -56,7 +46,6 @@ import net.minecraft.util.text.TextFormatting
import net.minecraft.world.World
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
import java.util.*
import java.util.concurrent.ConcurrentHashMap

class MultiblockSpaceElevator(id: ResourceLocation) : MultiblockWithDisplayBase(id), ModuleProvider
Expand All @@ -82,8 +71,8 @@ class MultiblockSpaceElevator(id: ResourceLocation) : MultiblockWithDisplayBase(
private val fourthCasingState = AerospaceCasing.HIGH_STRENGTH_CONCRETE.state
}

override fun createMetaTileEntity(te: IGregTechTileEntity): MetaTileEntity
= MultiblockSpaceElevator(metaTileEntityId)
override fun createMetaTileEntity(te: IGregTechTileEntity): MetaTileEntity =
MultiblockSpaceElevator(metaTileEntityId)

override fun update()
{
Expand Down Expand Up @@ -328,7 +317,7 @@ class MultiblockSpaceElevator(id: ResourceLocation) : MultiblockWithDisplayBase(
{
super.renderMetaTileEntity(renderState, translation, pipeline)
this.frontOverlay.renderOrientedState(renderState, translation, pipeline,
getFrontFacing(), true, true)
getFrontFacing(), true, true)
}

override fun hasMaintenanceMechanics() = false
Expand Down Expand Up @@ -361,73 +350,47 @@ class MultiblockSpaceElevator(id: ResourceLocation) : MultiblockWithDisplayBase(
{
// TODO: replace logo to space elevator logo and add warning/error indicators if necessary.
return SpaceElevatorUIFactory(this)
.configureDisplayText(::configureDisplayText)
.createFlexButton { _, guiSyncManager ->
guiSyncManager.registerSyncedAction("refresh_structure_pattern") { reinitializeStructurePattern() }
return@createFlexButton ButtonWidget()
.background(GTLiteMuiTextures.BUTTON_REFRESH_STRUCTURE_PATTERN)
.disableHoverBackground()
.onMousePressed {
guiSyncManager.callSyncedAction("refresh_structure_pattern")
true
}
.tooltip { tooltip ->
tooltip.addLine(KeyUtil.lang("gtlitecore.machine.space_elevator.refresh_structure_pattern"))
}
}
.configureDisplayText(::configureDisplayText)
.createFlexButton { _, guiSyncManager ->
guiSyncManager.registerSyncedAction("refresh_structure_pattern") { reinitializeStructurePattern() }
return@createFlexButton ButtonWidget()
.background(GTLiteMuiTextures.BUTTON_REFRESH_STRUCTURE_PATTERN)
.disableHoverBackground()
.onMousePressed {
guiSyncManager.callSyncedAction("refresh_structure_pattern")
true
}
.tooltip { tooltip ->
tooltip.addLine(KeyUtil.lang("gtlitecore.machine.space_elevator.refresh_structure_pattern"))
}
}
}

override fun configureDisplayText(builder: MultiblockUIBuilder)
{
builder.setWorkingStatus(true, isActive)
.addEnergyUsageLine(energyContainer)
.addCustom { keyManager, syncer ->
// TODO: Space Elevator UI is unsynced the second time we open the panel
// due to isStructureFormed in client being False value.
if (isStructureFormed)
{
val casingTier = syncer.syncInt(::casingTier)
val isExtended = syncer.syncBoolean(::isExtended)
val maxModules = syncer.syncInt(::maxModules)
keyManager.add(
.addEnergyUsageLine(energyContainer)
.addCustom { keyManager, syncer ->
if (isStructureFormed)
{
val casingTier = syncer.syncInt(::casingTier)
val isExtended = syncer.syncBoolean(::isExtended)
val maxModules = syncer.syncInt(::maxModules)
keyManager.add(
KeyUtil.lang(
TextFormatting.GRAY,
"gtlitecore.machine.space_elevator.acceleration_track_tier", casingTier
TextFormatting.GRAY,
"gtlitecore.machine.space_elevator.acceleration_track_tier", casingTier
)
)
keyManager.add(
)
keyManager.add(
KeyUtil.lang(
TextFormatting.GRAY,
"gtlitecore.machine.space_elevator.max_module_count", maxModules
TextFormatting.GRAY,
"gtlitecore.machine.space_elevator.max_module_count", maxModules
)
)

// Only for debug mode to test extended structure pattern checking module and
// other module checking situation.
if (!this.moduleReceivers.isEmpty() && ConfigHolder.misc.debug)
{
val moduleNames = arrayListOf<String>()
val uniqueNames = arrayListOf<String>()
this.moduleReceivers.forEach { moduleReceiver ->
moduleNames.add(moduleReceiver.displayCountName)
if (!uniqueNames.contains(moduleNames[moduleNames.indexOf(moduleReceiver.displayCountName)]))
{
uniqueNames.add(moduleReceiver.displayCountName)
}
uniqueNames.forEach { receiverName ->
keyManager.add(
KeyUtil.lang(
TextFormatting.GRAY,
receiverName,
Collections.frequency(moduleNames, receiverName)
)
)
}
}
}
}

)
}

}
}

@SideOnly(Side.CLIENT)
Expand Down Expand Up @@ -477,9 +440,12 @@ class MultiblockSpaceElevator(id: ResourceLocation) : MultiblockWithDisplayBase(

private fun setExtended(extended: Boolean)
{
isExtended = extended
invalidateStructure()
reinitializeStructurePattern()
if (isExtended != extended)
{
isExtended = extended
invalidateStructure()
reinitializeStructurePattern()
}
}

override fun isModule(receiver: ModuleReceiver): Boolean = moduleReceivers.contains(receiver)
Expand All @@ -488,51 +454,50 @@ class MultiblockSpaceElevator(id: ResourceLocation) : MultiblockWithDisplayBase(
* The UI Factory for Space Elevator
* Used to create buttons for enabling modules and disabling modules.
*/
private class SpaceElevatorUIFactory(controller: MultiblockSpaceElevator) : MultiblockUIFactory(controller)
private class SpaceElevatorUIFactory(val controller: MultiblockSpaceElevator) : MultiblockUIFactory(controller)
{
private val mte = controller
override fun createDistinctButton(mainPanel: ModularPanel, panelSyncManager: PanelSyncManager): IWidget
{
panelSyncManager.registerSyncedAction("enable_modules") { mte.enabledAllModules() }
panelSyncManager.registerSyncedAction("enable_modules") { controller.enabledAllModules() }

return ButtonWidget()
.disableHoverBackground()
.overlay(GTLiteMuiTextures.BUTTON_ENABLE_MODULE)
.tooltip { tooltip ->
tooltip.addLine(KeyUtil.lang("gtlitecore.machine.space_elevator.enable_module"))
}
.onMousePressed {
panelSyncManager.callSyncedAction("enable_modules")
true
}
.disableHoverBackground()
.overlay(GTLiteMuiTextures.BUTTON_ENABLE_MODULE)
.tooltip { tooltip ->
tooltip.addLine(KeyUtil.lang("gtlitecore.machine.space_elevator.enable_module"))
}
.onMousePressed {
panelSyncManager.callSyncedAction("enable_modules")
true
}
}

override fun createVoidingButton(mainPanel: ModularPanel, panelSyncManager: PanelSyncManager): IWidget
{
panelSyncManager.registerSyncedAction("disable_modules") { mte.disabledAllModules() }
panelSyncManager.registerSyncedAction("disable_modules") { controller.disabledAllModules() }

return ButtonWidget()
.disableHoverBackground()
.overlay(GTLiteMuiTextures.BUTTON_DISABLE_MODULE)
.tooltip { tooltip ->
tooltip.addLine(KeyUtil.lang("gtlitecore.machine.space_elevator.disable_module"))
}.onMousePressed {
panelSyncManager.callSyncedAction("disable_modules")
true
}
.disableHoverBackground()
.overlay(GTLiteMuiTextures.BUTTON_DISABLE_MODULE)
.tooltip { tooltip ->
tooltip.addLine(KeyUtil.lang("gtlitecore.machine.space_elevator.disable_module"))
}.onMousePressed {
panelSyncManager.callSyncedAction("disable_modules")
true
}

}

override fun createPowerButton(mainPanel: ModularPanel, panelSyncManager: PanelSyncManager): Widget<*>
{
val state = BooleanSyncValue(mte::getIsExtended, mte::setExtended)
val state = BooleanSyncValue(controller::getIsExtended, controller::setExtended)
return ToggleButton()
.disableHoverBackground()
.overlay(false, GTLiteMuiTextures.BUTTON_ELEVATOR_EXTENSION[0])
.overlay(true, GTLiteMuiTextures.BUTTON_ELEVATOR_EXTENSION[1])
.addTooltip(false, KeyUtil.lang("gtlitecore.machine.space_elevator.extension_info.disabled"))
.addTooltip(true, KeyUtil.lang("gtlitecore.machine.space_elevator.extension_info.enabled"))
.value(state)
.disableHoverBackground()
.overlay(false, GTLiteMuiTextures.BUTTON_ELEVATOR_EXTENSION[0])
.overlay(true, GTLiteMuiTextures.BUTTON_ELEVATOR_EXTENSION[1])
.addTooltip(false, KeyUtil.lang("gtlitecore.machine.space_elevator.extension_info.disabled"))
.addTooltip(true, KeyUtil.lang("gtlitecore.machine.space_elevator.extension_info.enabled"))
.value(state)
}

}
Expand Down
Loading