Migrate to DelegateSyncher and Delegate<>

This commit is contained in:
DBotThePony 2024-02-25 18:30:25 +07:00
parent 22430cd937
commit 2fbce58148
Signed by: DBot
GPG Key ID: DCC23B5715498507
159 changed files with 769 additions and 4575 deletions

View File

@ -141,9 +141,9 @@ dependencies {
jarJar("ru.dbotthepony.kommons:kommons-gson:[$kommons_version,)") { setTransitive(false) } jarJar("ru.dbotthepony.kommons:kommons-gson:[$kommons_version,)") { setTransitive(false) }
jarJar("ru.dbotthepony.kommons:kommons-guava:[$kommons_version,)") { setTransitive(false) } jarJar("ru.dbotthepony.kommons:kommons-guava:[$kommons_version,)") { setTransitive(false) }
implementation("ru.dbotthepony.kommons:kommons:[$kommons_version,)") { setTransitive(false) } compileOnly("ru.dbotthepony.kommons:kommons:[$kommons_version,)") { setTransitive(false) }
implementation("ru.dbotthepony.kommons:kommons-gson:[$kommons_version,)") { setTransitive(false) } compileOnly("ru.dbotthepony.kommons:kommons-gson:[$kommons_version,)") { setTransitive(false) }
implementation("ru.dbotthepony.kommons:kommons-guava:[$kommons_version,)") { setTransitive(false) } compileOnly("ru.dbotthepony.kommons:kommons-guava:[$kommons_version,)") { setTransitive(false) }
minecraftLibrary("ru.dbotthepony.kommons:kommons:[$kommons_version,)") { setTransitive(false) } minecraftLibrary("ru.dbotthepony.kommons:kommons:[$kommons_version,)") { setTransitive(false) }
minecraftLibrary("ru.dbotthepony.kommons:kommons-gson:[$kommons_version,)") { setTransitive(false) } minecraftLibrary("ru.dbotthepony.kommons:kommons-gson:[$kommons_version,)") { setTransitive(false) }

View File

@ -19,7 +19,7 @@ forge_version=48.1.0
mixingradle_version=0.7.33 mixingradle_version=0.7.33
mixin_version=0.8.5 mixin_version=0.8.5
kommons_version=2.3.3 kommons_version=2.9.13
jei_version=16.0.0.28 jei_version=16.0.0.28
jupiter_version=5.9.2 jupiter_version=5.9.2

View File

@ -5,18 +5,21 @@ import net.minecraft.nbt.CompoundTag
import net.minecraftforge.common.util.INBTSerializable import net.minecraftforge.common.util.INBTSerializable
import net.minecraftforge.event.entity.living.LivingAttackEvent import net.minecraftforge.event.entity.living.LivingAttackEvent
import net.minecraftforge.event.entity.living.LivingHurtEvent import net.minecraftforge.event.entity.living.LivingHurtEvent
import ru.dbotthepony.kommons.io.DelegateSyncher
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
import java.io.InputStream import java.io.InputStream
abstract class AndroidFeature(val type: AndroidFeatureType<*>, val android: MatteryPlayerCapability) : INBTSerializable<CompoundTag> { abstract class AndroidFeature(val type: AndroidFeatureType<*>, val android: MatteryPlayerCapability) : INBTSerializable<CompoundTag> {
val ply get() = android.ply val ply get() = android.ply
val synchronizer = FieldSynchronizer() val syncher = DelegateSyncher()
val syncherRemote = syncher.Remote()
open var level by synchronizer.int(setter = setter@{ value, field, setByRemote -> open var level by syncher.int(setter = setter@{ field, value ->
if (value != field.read()) { if (value != field.get()) {
field.write(value) field.accept(value)
applyModifiers() applyModifiers()
} }
}) })
@ -28,7 +31,7 @@ abstract class AndroidFeature(val type: AndroidFeatureType<*>, val android: Matt
* Called when it is required to network everything again * Called when it is required to network everything again
*/ */
open fun invalidateNetwork() { open fun invalidateNetwork() {
synchronizer.invalidate() syncherRemote.invalidate()
} }
open fun applyModifiers() {} open fun applyModifiers() {}
@ -38,11 +41,11 @@ abstract class AndroidFeature(val type: AndroidFeatureType<*>, val android: Matt
open fun onAttack(event: LivingAttackEvent) {} open fun onAttack(event: LivingAttackEvent) {}
open fun collectNetworkPayload(): FastByteArrayOutputStream? { open fun collectNetworkPayload(): FastByteArrayOutputStream? {
return synchronizer.collectNetworkPayload() return syncherRemote.write()
} }
open fun applyNetworkPayload(stream: InputStream) { open fun applyNetworkPayload(stream: InputStream) {
synchronizer.read(stream) syncher.read(stream)
} }
override fun serializeNBT(): CompoundTag { override fun serializeNBT(): CompoundTag {

View File

@ -8,9 +8,11 @@ import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.player.Player import net.minecraft.world.entity.player.Player
import net.minecraftforge.common.MinecraftForge import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.common.util.INBTSerializable import net.minecraftforge.common.util.INBTSerializable
import net.minecraftforge.eventbus.api.Cancelable
import net.minecraftforge.eventbus.api.Event import net.minecraftforge.eventbus.api.Event
import net.minecraftforge.eventbus.api.Event.HasResult import net.minecraftforge.eventbus.api.Event.HasResult
import ru.dbotthepony.kommons.io.DelegateSyncher
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.awareItemsStream import ru.dbotthepony.mc.otm.capability.awareItemsStream
@ -19,7 +21,6 @@ import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.milliTime import ru.dbotthepony.mc.otm.milliTime
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
import ru.dbotthepony.mc.otm.triggers.AndroidResearchTrigger import ru.dbotthepony.mc.otm.triggers.AndroidResearchTrigger
import java.io.InputStream import java.io.InputStream
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
@ -53,9 +54,10 @@ class AndroidResearch(val type: AndroidResearchType, val capability: MatteryPlay
val ply: Player get() = capability.ply val ply: Player get() = capability.ply
val synchronizer = FieldSynchronizer() val syncher = DelegateSyncher()
val syncherRemote = syncher.Remote()
var isResearched by synchronizer.bool().property var isResearched by syncher.boolean()
private set private set
var tag = CompoundTag() var tag = CompoundTag()
@ -65,7 +67,7 @@ class AndroidResearch(val type: AndroidResearchType, val capability: MatteryPlay
* Called when it is required to network everything again * Called when it is required to network everything again
*/ */
fun invalidateNetwork() { fun invalidateNetwork() {
synchronizer.invalidate() syncherRemote.invalidate()
} }
fun unResearch() { fun unResearch() {
@ -187,11 +189,11 @@ class AndroidResearch(val type: AndroidResearchType, val capability: MatteryPlay
} }
fun collectNetworkPayload(): FastByteArrayOutputStream? { fun collectNetworkPayload(): FastByteArrayOutputStream? {
return synchronizer.collectNetworkPayload() return syncherRemote.write()
} }
fun applyNetworkPayload(stream: InputStream) { fun applyNetworkPayload(stream: InputStream) {
synchronizer.read(stream) syncher.read(stream)
} }
val canResearch: Boolean get() { val canResearch: Boolean get() {

View File

@ -7,6 +7,7 @@ import net.minecraft.ChatFormatting
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraftforge.eventbus.api.IEventBus import net.minecraftforge.eventbus.api.IEventBus
import net.minecraftforge.registries.DeferredRegister import net.minecraftforge.registries.DeferredRegister
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.client.ShiftPressedCond import ru.dbotthepony.mc.otm.client.ShiftPressedCond
import ru.dbotthepony.mc.otm.config.AndroidConfig import ru.dbotthepony.mc.otm.config.AndroidConfig

View File

@ -7,6 +7,7 @@ import net.minecraft.resources.ResourceLocation
import net.minecraftforge.eventbus.api.IEventBus import net.minecraftforge.eventbus.api.IEventBus
import net.minecraftforge.registries.DeferredRegister import net.minecraftforge.registries.DeferredRegister
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.core.getValue import ru.dbotthepony.mc.otm.core.getValue
import ru.dbotthepony.mc.otm.data.SingletonCodec import ru.dbotthepony.mc.otm.data.SingletonCodec

View File

@ -2,18 +2,21 @@ package ru.dbotthepony.mc.otm.android
import net.minecraft.client.multiplayer.ClientLevel import net.minecraft.client.multiplayer.ClientLevel
import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.CompoundTag
import net.minecraft.server.level.ServerPlayer
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
abstract class AndroidSwitchableFeature(type: AndroidFeatureType<*>, android: MatteryPlayerCapability) : AndroidFeature(type, android) { abstract class AndroidSwitchableFeature(type: AndroidFeatureType<*>, android: MatteryPlayerCapability) : AndroidFeature(type, android) {
var isActive by synchronizer.bool(setter = setter@{ value, access, setByRemote -> var isActive by syncher.boolean(setter = setter@{ access, value ->
if (value != access.readBoolean()) { if (value != access.get()) {
access.write(value) access.accept(value)
if (!setByRemote) { if (ply is ServerPlayer) {
if (value) { if (value) {
applyModifiers() applyModifiers()
} else { } else {
@ -21,13 +24,13 @@ abstract class AndroidSwitchableFeature(type: AndroidFeatureType<*>, android: Ma
} }
} }
} }
}).property })
open val allowToSwitchByPlayer: Boolean get() = true open val allowToSwitchByPlayer: Boolean get() = true
open val allowToSwitchByPlayerWhileSpectator: Boolean get() = true open val allowToSwitchByPlayerWhileSpectator: Boolean get() = true
open val maxCooldown: Int get() = 0 open val maxCooldown: Int get() = 0
open var cooldown by synchronizer.int().property open var cooldown by syncher.int()
val isOnCooldown: Boolean val isOnCooldown: Boolean
get() = maxCooldown > 0 && cooldown > 0 get() = maxCooldown > 0 && cooldown > 0

View File

@ -23,6 +23,7 @@ import net.minecraft.world.phys.shapes.Shapes
import net.minecraftforge.client.event.RenderLevelStageEvent import net.minecraftforge.client.event.RenderLevelStageEvent
import net.minecraftforge.event.ForgeEventFactory import net.minecraftforge.event.ForgeEventFactory
import net.minecraftforge.event.entity.living.LivingDeathEvent import net.minecraftforge.event.entity.living.LivingDeathEvent
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.NULLABLE_MINECRAFT_SERVER import ru.dbotthepony.mc.otm.NULLABLE_MINECRAFT_SERVER
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.android.AndroidActiveFeature import ru.dbotthepony.mc.otm.android.AndroidActiveFeature
@ -38,7 +39,6 @@ import ru.dbotthepony.mc.otm.config.AndroidConfig
import ru.dbotthepony.mc.otm.core.genericPositions import ru.dbotthepony.mc.otm.core.genericPositions
import ru.dbotthepony.mc.otm.core.holder import ru.dbotthepony.mc.otm.core.holder
import ru.dbotthepony.mc.otm.core.isFall import ru.dbotthepony.mc.otm.core.isFall
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.Vector import ru.dbotthepony.mc.otm.core.math.Vector
import ru.dbotthepony.mc.otm.core.math.asVector import ru.dbotthepony.mc.otm.core.math.asVector
import ru.dbotthepony.mc.otm.core.math.component1 import ru.dbotthepony.mc.otm.core.math.component1

View File

@ -4,6 +4,7 @@ import net.minecraft.client.multiplayer.ClientLevel
import net.minecraft.network.FriendlyByteBuf import net.minecraft.network.FriendlyByteBuf
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.entity.item.ItemEntity
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.config.AndroidConfig import ru.dbotthepony.mc.otm.config.AndroidConfig
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
@ -13,7 +14,6 @@ import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.ResearchIcons import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.core.math.Vector import ru.dbotthepony.mc.otm.core.math.Vector
import ru.dbotthepony.mc.otm.core.getEntitiesInEllipsoid import ru.dbotthepony.mc.otm.core.getEntitiesInEllipsoid
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.minus import ru.dbotthepony.mc.otm.core.math.minus
import ru.dbotthepony.mc.otm.core.math.plus import ru.dbotthepony.mc.otm.core.math.plus
import ru.dbotthepony.mc.otm.core.position import ru.dbotthepony.mc.otm.core.position

View File

@ -3,6 +3,9 @@ package ru.dbotthepony.mc.otm.android.feature
import net.minecraft.network.FriendlyByteBuf import net.minecraft.network.FriendlyByteBuf
import net.minecraft.server.level.ServerPlayer import net.minecraft.server.level.ServerPlayer
import net.minecraft.sounds.SoundSource import net.minecraft.sounds.SoundSource
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
@ -11,7 +14,6 @@ import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.ResearchIcons import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.config.AndroidConfig import ru.dbotthepony.mc.otm.config.AndroidConfig
import ru.dbotthepony.mc.otm.config.ClientConfig import ru.dbotthepony.mc.otm.config.ClientConfig
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.Vector import ru.dbotthepony.mc.otm.core.math.Vector
import ru.dbotthepony.mc.otm.core.math.plus import ru.dbotthepony.mc.otm.core.math.plus
import ru.dbotthepony.mc.otm.network.GenericNetworkChannel import ru.dbotthepony.mc.otm.network.GenericNetworkChannel
@ -55,13 +57,13 @@ class JumpBoostFeature(capability: MatteryPlayerCapability) : AndroidSwitchableF
override val maxCooldown: Int override val maxCooldown: Int
get() = (AndroidConfig.JumpBoost.BASE_COOLDOWN - AndroidConfig.JumpBoost.COOLDOWN_REDUCTION * level).coerceAtLeast(0) get() = (AndroidConfig.JumpBoost.BASE_COOLDOWN - AndroidConfig.JumpBoost.COOLDOWN_REDUCTION * level).coerceAtLeast(0)
override var cooldown by synchronizer.int(setter = setter@{ value, access, setByRemote -> override var cooldown by syncher.int(setter = setter@{ access, value ->
access.write(value) access.accept(value)
if (setByRemote) { if (ply !is ServerPlayer) {
tickCooldownClient = false tickCooldownClient = false
} }
}).property })
private var lastGround = false private var lastGround = false

View File

@ -1,12 +1,11 @@
package ru.dbotthepony.mc.otm.android.feature package ru.dbotthepony.mc.otm.android.feature
import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.CompoundTag
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.level.ServerPlayer import net.minecraft.server.level.ServerPlayer
import net.minecraftforge.event.entity.living.LivingHurtEvent import net.minecraftforge.event.entity.living.LivingHurtEvent
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.android.AndroidFeature import ru.dbotthepony.mc.otm.android.AndroidFeature
import ru.dbotthepony.mc.otm.android.AndroidResearchManager
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.core.isBypassArmor import ru.dbotthepony.mc.otm.core.isBypassArmor
@ -19,17 +18,15 @@ import ru.dbotthepony.mc.otm.triggers.NanobotsArmorTrigger
import kotlin.math.roundToInt import kotlin.math.roundToInt
class NanobotsArmorFeature(android: MatteryPlayerCapability) : AndroidFeature(AndroidFeatures.NANOBOTS_ARMOR, android) { class NanobotsArmorFeature(android: MatteryPlayerCapability) : AndroidFeature(AndroidFeatures.NANOBOTS_ARMOR, android) {
var strength by synchronizer.int( var strength by syncher.int(
setter = setter@{ setter = setter@{ access, value -> access.accept(value.coerceIn(0 .. 3)) }
value, access, _ -> access.write(value.coerceIn(0 .. 3)) )
}
).property
var speed: Int = 0 var speed: Int = 0
set(value) { field = value.coerceIn(0 .. 3) } set(value) { field = value.coerceIn(0 .. 3) }
private var ticksPassed = 0 private var ticksPassed = 0
var layers by synchronizer.int().property var layers by syncher.int()
override fun tickServer() { override fun tickServer() {
if (layers < strength + 1 && android.androidEnergy.extractEnergyExact(ENERGY_PER_LAYER, true)) { if (layers < strength + 1 && android.androidEnergy.extractEnergyExact(ENERGY_PER_LAYER, true)) {
@ -65,7 +62,7 @@ class NanobotsArmorFeature(android: MatteryPlayerCapability) : AndroidFeature(An
} }
} }
event.amount = event.amount - realAbsorbed event.amount -= realAbsorbed
(ply as ServerPlayer?)?.awardStat(StatNames.DAMAGE_ABSORBED, (realAbsorbed * 10f).roundToInt()) (ply as ServerPlayer?)?.awardStat(StatNames.DAMAGE_ABSORBED, (realAbsorbed * 10f).roundToInt())
layers-- layers--
} }

View File

@ -2,13 +2,13 @@ package ru.dbotthepony.mc.otm.android.feature
import net.minecraft.world.effect.MobEffectInstance import net.minecraft.world.effect.MobEffectInstance
import net.minecraft.world.effect.MobEffects import net.minecraft.world.effect.MobEffects
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact import ru.dbotthepony.mc.otm.capability.energy.extractEnergyExact
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.ResearchIcons import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.config.AndroidConfig import ru.dbotthepony.mc.otm.config.AndroidConfig
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.registry.AndroidFeatures import ru.dbotthepony.mc.otm.registry.AndroidFeatures
class NightVisionFeature(android: MatteryPlayerCapability) : AndroidSwitchableFeature(AndroidFeatures.NIGHT_VISION, android) { class NightVisionFeature(android: MatteryPlayerCapability) : AndroidSwitchableFeature(AndroidFeatures.NIGHT_VISION, android) {

View File

@ -17,7 +17,7 @@ import ru.dbotthepony.mc.otm.config.AndroidConfig
import ru.dbotthepony.mc.otm.core.damageType import ru.dbotthepony.mc.otm.core.damageType
import ru.dbotthepony.mc.otm.core.getEntitiesInEllipsoid import ru.dbotthepony.mc.otm.core.getEntitiesInEllipsoid
import ru.dbotthepony.mc.otm.core.getExplosionResistance import ru.dbotthepony.mc.otm.core.getExplosionResistance
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.Vector import ru.dbotthepony.mc.otm.core.math.Vector
import ru.dbotthepony.mc.otm.core.math.getEllipsoidBlockPositions import ru.dbotthepony.mc.otm.core.math.getEllipsoidBlockPositions
import ru.dbotthepony.mc.otm.core.math.minus import ru.dbotthepony.mc.otm.core.math.minus

View File

@ -6,7 +6,7 @@ import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.ResearchIcons import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.registry.AndroidFeatures import ru.dbotthepony.mc.otm.registry.AndroidFeatures
import java.util.* import java.util.*

View File

@ -7,7 +7,7 @@ import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.ResearchIcons import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.config.AndroidConfig import ru.dbotthepony.mc.otm.config.AndroidConfig
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.registry.AndroidFeatures import ru.dbotthepony.mc.otm.registry.AndroidFeatures
import java.util.* import java.util.*

View File

@ -4,9 +4,8 @@ import com.google.common.collect.ImmutableList
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
import it.unimi.dsi.fastutil.longs.Long2ObjectFunction import it.unimi.dsi.fastutil.longs.Long2ObjectFunction
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap
import it.unimi.dsi.fastutil.objects.ObjectArraySet import it.unimi.dsi.fastutil.objects.ObjectArraySet
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
import it.unimi.dsi.fastutil.objects.Reference2IntArrayMap import it.unimi.dsi.fastutil.objects.Reference2IntArrayMap
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
@ -37,12 +36,13 @@ import net.minecraftforge.event.level.ChunkWatchEvent
import net.minecraftforge.event.level.LevelEvent import net.minecraftforge.event.level.LevelEvent
import net.minecraftforge.event.server.ServerStoppingEvent import net.minecraftforge.event.server.ServerStoppingEvent
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import ru.dbotthepony.kommons.io.DelegateSyncher
import ru.dbotthepony.kommons.util.Listenable
import ru.dbotthepony.mc.otm.SERVER_IS_LIVE import ru.dbotthepony.mc.otm.SERVER_IS_LIVE
import ru.dbotthepony.mc.otm.block.INeighbourChangeListener import ru.dbotthepony.mc.otm.block.INeighbourChangeListener
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
import ru.dbotthepony.mc.otm.core.ISubscriptable
import ru.dbotthepony.mc.otm.core.collect.WeakHashSet import ru.dbotthepony.mc.otm.core.collect.WeakHashSet
import ru.dbotthepony.mc.otm.core.get import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.immutableList import ru.dbotthepony.mc.otm.core.immutableList
@ -56,9 +56,7 @@ import ru.dbotthepony.mc.otm.core.util.TickList
import ru.dbotthepony.mc.otm.core.util.countingLazy import ru.dbotthepony.mc.otm.core.util.countingLazy
import ru.dbotthepony.mc.otm.network.BlockEntitySyncPacket import ru.dbotthepony.mc.otm.network.BlockEntitySyncPacket
import ru.dbotthepony.mc.otm.network.GenericNetworkChannel import ru.dbotthepony.mc.otm.network.GenericNetworkChannel
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
import ru.dbotthepony.mc.otm.once import ru.dbotthepony.mc.otm.once
import ru.dbotthepony.mc.otm.onceServer
import ru.dbotthepony.mc.otm.sometimeServer import ru.dbotthepony.mc.otm.sometimeServer
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import java.util.* import java.util.*
@ -79,7 +77,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
private val sidelessCaps = Reference2ObjectOpenHashMap<Capability<*>, SidelessCap<*>>() private val sidelessCaps = Reference2ObjectOpenHashMap<Capability<*>, SidelessCap<*>>()
protected val tickList = TickList() protected val tickList = TickList()
protected val blockStateChangesCounter = IntCounter() protected val blockStateChangesCounter = IntCounter()
protected val dirtyListeners = ISubscriptable.Impl<Unit>() protected val dirtyListeners = Listenable.Impl<Unit>()
private val waitForServerLevel = ArrayList<() -> Unit>() private val waitForServerLevel = ArrayList<() -> Unit>()
private val _droppableContainers = ObjectArraySet<Container>() private val _droppableContainers = ObjectArraySet<Container>()
@ -129,9 +127,6 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
open fun tick() { open fun tick() {
tickList.tick() tickList.tick()
if (synchronizer.isNotEmpty)
synchronizeToPlayers(false)
} }
/** /**
@ -181,7 +176,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
} }
} }
interface SideListener<T> : Supplier<LazyOptional<T>>, ISubscriptable<LazyOptional<T>> interface SideListener<T> : Supplier<LazyOptional<T>>, Listenable<LazyOptional<T>>
inner class Side(val side: RelativeSide) { inner class Side(val side: RelativeSide) {
init { init {
@ -202,9 +197,9 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
} }
} }
private val listeners = ISubscriptable.Impl<LazyOptional<T>>() private val listeners = Listenable.Impl<LazyOptional<T>>()
override fun addListener(listener: Consumer<LazyOptional<T>>): ISubscriptable.L { override fun addListener(listener: Consumer<LazyOptional<T>>): Listenable.L {
val l = listeners.addListener(listener) val l = listeners.addListener(listener)
if (level is ServerLevel) listener.accept(value) if (level is ServerLevel) listener.accept(value)
return l return l
@ -488,30 +483,8 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
dirtyListeners.accept(Unit) dirtyListeners.accept(Unit)
} }
val synchronizer = FieldSynchronizer { val syncher = DelegateSyncher()
if (isSynchronizing || tickList.ticks != 0) private val synchers = Object2ObjectArrayMap<ServerPlayer, DelegateSyncher.Remote>()
return@FieldSynchronizer
if (isRemoved) markSynchronizerClean()
if (level?.isClientSide == false && (_subCache == null || (_subCache ?: throw ConcurrentModificationException()).players.isNotEmpty())) {
onceServer {
if (!isRemoved) {
synchronizeToPlayers(true)
}
}
} else {
markSynchronizerClean()
}
}
private fun markSynchronizerClean() {
synchronizer.markClean()
}
init {
synchronizer.defaultEndpoint.markUnused()
}
override fun setLevel(level: Level) { override fun setLevel(level: Level) {
val old = this.level val old = this.level
@ -595,51 +568,29 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
return subs return subs
} }
private fun synchronizeToPlayers(calledBySynchronizer: Boolean) {
isSynchronizing = true
try {
check(level is ServerLevel) { "Invalid realm or Level is null" }
synchronizer.observe()
val subscription = subscription
if (subscription.players.isNotEmpty() && (playerListUpdated || synchronizer.isDirty)) {
playerListUpdated = false
for (player in subscription.players) {
if (player !in subscription.veto) {
val payload = synchronizer.computeEndpointFor(player).collectNetworkPayload()
if (payload != null) {
GenericNetworkChannel.send(player, BlockEntitySyncPacket(blockPos, payload.array, payload.length))
}
}
}
synchronizer.markClean()
} else if (calledBySynchronizer) {
synchronizer.markClean()
}
} finally {
isSynchronizing = false
}
}
private class ChunkSubscribers(level: ServerLevel, val chunkPos: Long) { private class ChunkSubscribers(level: ServerLevel, val chunkPos: Long) {
val level = WeakReference(level) val level = WeakReference(level)
val blockEntities = WeakHashSet<MatteryBlockEntity>(linked = true, initialCapacity = 0) val blockEntities = WeakHashSet<MatteryBlockEntity>(linked = true, initialCapacity = 0)
val players = ObjectArraySet<ServerPlayer>(0) val players = ObjectArraySet<ServerPlayer>(0)
val veto = ObjectArraySet<ServerPlayer>(0) val veto = ObjectArraySet<ServerPlayer>(0)
val blockEntitiesWithObservers = WeakHashSet<MatteryBlockEntity>(linked = true, initialCapacity = 0)
private val player2ResubCount = Reference2IntArrayMap<ServerPlayer>() private val player2ResubCount = Reference2IntArrayMap<ServerPlayer>()
private var isTicking = false
private fun checkShouldTick() {
val shouldTick = blockEntities.isNotEmpty() && players.isNotEmpty()
if (!shouldTick && isTicking) {
isTicking = false
tickingMap[level.get()]?.remove(this)
} else if (shouldTick && !isTicking) {
isTicking = true
tickingMap.computeIfAbsent(level.get()) { ArrayList() }.add(this)
}
}
operator fun component1() = blockEntities operator fun component1() = blockEntities
operator fun component2() = players operator fun component2() = players
val hasObservers: Boolean get() {
return blockEntities.any { it.synchronizer.hasObservers }
}
private fun recheckPlayer(player: ServerPlayer) { private fun recheckPlayer(player: ServerPlayer) {
sometimeServer { sometimeServer {
if (player in players && !player.hasDisconnected()) { if (player in players && !player.hasDisconnected()) {
@ -649,8 +600,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
veto.remove(player) veto.remove(player)
blockEntities.forEach { blockEntities.forEach {
it.playerListUpdated = true it.synchers[player] = it.syncher.Remote()
it.synchronizeToPlayers(false)
} }
} }
} else if (player in players && player.hasDisconnected()) { } else if (player in players && player.hasDisconnected()) {
@ -663,6 +613,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
if (players.add(player)) { if (players.add(player)) {
veto.add(player) veto.add(player)
recheckPlayer(player) recheckPlayer(player)
checkShouldTick()
} else if (player !in veto) { } else if (player !in veto) {
player2ResubCount[player] = player2ResubCount.getInt(player) + 1 player2ResubCount[player] = player2ResubCount.getInt(player) + 1
LOGGER.debug("{} got subscribed to {} without prior unsubscribing, forcefully resubscribing (this happened {} times)", player, ChunkPos(chunkPos), player2ResubCount.getInt(player)) LOGGER.debug("{} got subscribed to {} without prior unsubscribing, forcefully resubscribing (this happened {} times)", player, ChunkPos(chunkPos), player2ResubCount.getInt(player))
@ -674,15 +625,13 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
fun unsubscribe(player: ServerPlayer, normal: Boolean = true): Boolean { fun unsubscribe(player: ServerPlayer, normal: Boolean = true): Boolean {
if (players.remove(player)) { if (players.remove(player)) {
veto.remove(player) veto.remove(player)
if (normal) player2ResubCount.removeInt(player)
blockEntities.forEach { blockEntities.forEach {
it.synchronizer.removeEndpointFor(player) it.synchers.remove(player)
}
if (normal) {
player2ResubCount.removeInt(player)
} }
checkShouldTick()
return true return true
} }
@ -690,27 +639,18 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
} }
fun subscribe(blockEntity: MatteryBlockEntity) { fun subscribe(blockEntity: MatteryBlockEntity) {
if (!blockEntities.add(blockEntity)) return if (blockEntities.add(blockEntity)) {
players.forEach {
onceServer { if (it !in veto) {
if (!blockEntity.isRemoved && blockEntity in blockEntities) { blockEntity.synchers[it] = blockEntity.syncher.Remote()
blockEntity.synchronizeToPlayers(false) }
} }
} }
if (blockEntity.synchronizer.hasObservers && blockEntity.tickList.ticks == 0) {
blockEntitiesWithObservers.add(blockEntity)
tickingMap
.computeIfAbsent(level.get() ?: throw NullPointerException("Level got GCd!")) { WeakHashSet(linked = true, initialCapacity = 2) }
.add(this)
}
} }
fun unsubscribe(blockEntity: MatteryBlockEntity): Boolean { fun unsubscribe(blockEntity: MatteryBlockEntity): Boolean {
blockEntities.remove(blockEntity) blockEntities.remove(blockEntity)
blockEntitiesWithObservers.remove(blockEntity) checkShouldTick()
return players.isEmpty() && blockEntities.isEmpty() return players.isEmpty() && blockEntities.isEmpty()
} }
@ -743,7 +683,7 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
const val LOOT_TABLE_SEED_KEY = RandomizableContainerBlockEntity.LOOT_TABLE_SEED_TAG const val LOOT_TABLE_SEED_KEY = RandomizableContainerBlockEntity.LOOT_TABLE_SEED_TAG
private val playerMap = WeakHashMap<ServerLevel, Long2ObjectOpenHashMap<ChunkSubscribers>>() private val playerMap = WeakHashMap<ServerLevel, Long2ObjectOpenHashMap<ChunkSubscribers>>()
private val tickingMap = WeakHashMap<ServerLevel, WeakHashSet<ChunkSubscribers>>() private val tickingMap = WeakHashMap<ServerLevel, ArrayList<ChunkSubscribers>>()
private val vec2Dir = Int2ObjectOpenHashMap<Direction>() private val vec2Dir = Int2ObjectOpenHashMap<Direction>()
private val LOGGER = LogManager.getLogger() private val LOGGER = LogManager.getLogger()
@ -809,22 +749,20 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
fun postLevelTick(event: LevelTickEvent) { fun postLevelTick(event: LevelTickEvent) {
val level = event.level as? ServerLevel ?: return val level = event.level as? ServerLevel ?: return
val ticking = tickingMap[level] ?: return
ticking.removeIf { tickingMap[level]?.forEach {
val shouldRemove = it.blockEntitiesWithObservers.isEmpty() it.blockEntities.forEach { be ->
be.syncher.observe()
if (!shouldRemove && it.players.isNotEmpty()) { be.synchers.entries.forEach { e ->
it.blockEntitiesWithObservers.forEach { val (player, data) = e
it.synchronizeToPlayers(false) val payload = data.write()
if (payload != null) {
GenericNetworkChannel.send(player, BlockEntitySyncPacket(be.blockPos, payload.array, payload.length))
}
} }
} }
shouldRemove
}
if (ticking.isEmpty()) {
tickingMap.remove(level)
} }
} }

View File

@ -16,6 +16,8 @@ import net.minecraftforge.common.capabilities.ForgeCapabilities
import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidStack
import net.minecraftforge.fluids.capability.IFluidHandler import net.minecraftforge.fluids.capability.IFluidHandler
import net.minecraftforge.items.IItemHandler import net.minecraftforge.items.IItemHandler
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.capability.item.CombinedItemHandler import ru.dbotthepony.mc.otm.capability.item.CombinedItemHandler
import ru.dbotthepony.mc.otm.capability.item.EmptyItemHandler import ru.dbotthepony.mc.otm.capability.item.EmptyItemHandler
import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.FlowDirection
@ -144,11 +146,11 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo
savetables.bool(::automatePush, "fluid_${side}_push") savetables.bool(::automatePush, "fluid_${side}_push")
} }
var flow by synchronizer.enum(possibleModes, setter = { value, access, setByRemote -> var flow by syncher.enum(possibleModes, setter = { access, value ->
require(possibleModes.isSupertype(value)) { "Energy mode $value is not allowed (allowed modes: ${possibleModes.family})" } require(possibleModes.isSupertype(value)) { "Energy mode $value is not allowed (allowed modes: ${possibleModes.family})" }
if (access.read() != value) { if (access.get() != value) {
access.write(value) access.accept(value)
markDirtyFast() markDirtyFast()
if (value == FlowDirection.NONE) { if (value == FlowDirection.NONE) {
@ -180,13 +182,8 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo
init { init {
waitForServerLevel { waitForServerLevel {
redstoneControl.addListener { redstoneControl.addListener(::updateTickerState)
updateTickerState() neighbour.addListener(::updateTickerState)
}
neighbour.addListener {
updateTickerState()
}
updateTickerState() updateTickerState()
} }
@ -384,18 +381,13 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo
savetables.bool(::automatePull, "energy_${side}_pull") savetables.bool(::automatePull, "energy_${side}_pull")
savetables.bool(::automatePush, "energy_${side}_push") savetables.bool(::automatePush, "energy_${side}_push")
dirtyListeners.addListener { dirtyListeners.addListener(Runnable {
updateTickerState() updateTickerState()
} })
waitForServerLevel { waitForServerLevel {
redstoneControl.addListener { redstoneControl.addListener(::updateTickerState)
updateTickerState() neighbour.addListener(::updateTickerState)
}
neighbour.addListener {
updateTickerState()
}
updateTickerState() updateTickerState()
} }
@ -443,11 +435,11 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo
} }
} }
override var energyFlow by synchronizer.enum(possibleModes, setter = { value, access, setByRemote -> override var energyFlow by syncher.enum(possibleModes, setter = { access, value ->
require(possibleModes.isSupertype(value)) { "Energy mode $value is not allowed (allowed modes: ${possibleModes.family})" } require(possibleModes.isSupertype(value)) { "Energy mode $value is not allowed (allowed modes: ${possibleModes.family})" }
if (access.read() != value) { if (access.get() != value) {
access.write(value) access.accept(value)
markDirtyFast() markDirtyFast()
if (value == FlowDirection.NONE) { if (value == FlowDirection.NONE) {
@ -462,7 +454,7 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo
updateTickerState() updateTickerState()
} }
}) }).delegate
fun invalidate(force: Boolean = false) { fun invalidate(force: Boolean = false) {
if (force) { if (force) {
@ -611,11 +603,11 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo
capController.close() capController.close()
} }
var mode by synchronizer.enum(ItemHandlerMode.DISABLED, setter = { value, access, setByRemote -> var mode by syncher.enum(ItemHandlerMode.DISABLED, setter = { access, value ->
require(value in possibleViews) { "View type $value is not allowed (allowed views: $possibleViews)" } require(value in possibleViews) { "View type $value is not allowed (allowed views: $possibleViews)" }
if (access.read() != value) { if (access.get() != value) {
access.write(value) access.accept(value)
markDirtyFast() markDirtyFast()
if (value == ItemHandlerMode.DISABLED) { if (value == ItemHandlerMode.DISABLED) {
@ -633,7 +625,7 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo
ItemHandlerMode.BATTERY -> battery!! ItemHandlerMode.BATTERY -> battery!!
} }
} }
}) }).delegate
var automatePull = false var automatePull = false
set(value) { set(value) {
@ -671,13 +663,8 @@ abstract class MatteryDeviceBlockEntity(blockEntityType: BlockEntityType<*>, blo
savetables.enum(::mode, "itemhandler_${side}_mode", ItemHandlerMode::valueOf) savetables.enum(::mode, "itemhandler_${side}_mode", ItemHandlerMode::valueOf)
waitForServerLevel { waitForServerLevel {
redstoneControl.addListener { redstoneControl.addListener(::updateTickerState)
updateTickerState() neighbour.addListener(::updateTickerState)
}
neighbour.addListener {
updateTickerState()
}
updateTickerState() updateTickerState()
} }

View File

@ -1,26 +1,27 @@
package ru.dbotthepony.mc.otm.block.entity package ru.dbotthepony.mc.otm.block.entity
import it.unimi.dsi.fastutil.booleans.BooleanConsumer
import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.CompoundTag
import net.minecraftforge.common.util.INBTSerializable import net.minecraftforge.common.util.INBTSerializable
import ru.dbotthepony.mc.otm.core.IBooleanSubscriptable import ru.dbotthepony.kommons.io.DelegateSyncher
import ru.dbotthepony.mc.otm.core.ISubscriptable import ru.dbotthepony.kommons.util.Listenable
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.core.nbt.mapString import ru.dbotthepony.mc.otm.core.nbt.mapString
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer import java.util.function.Consumer
interface IRedstoneControlled { interface IRedstoneControlled {
val redstoneControl: AbstractRedstoneControl val redstoneControl: AbstractRedstoneControl
} }
abstract class AbstractRedstoneControl : INBTSerializable<CompoundTag?>, IBooleanSubscriptable { abstract class AbstractRedstoneControl : INBTSerializable<CompoundTag?>, Listenable<Boolean> {
abstract var redstoneSetting: RedstoneSetting abstract var redstoneSetting: RedstoneSetting
abstract var redstoneSignal: Int abstract var redstoneSignal: Int
protected val listeners = IBooleanSubscriptable.Impl() protected val listeners = Listenable.Impl<Boolean>()
val isBlockedByRedstone: Boolean get() = !redstoneSetting.test(redstoneSignal) val isBlockedByRedstone: Boolean get() = !redstoneSetting.test(redstoneSignal)
final override fun addListener(listener: BooleanConsumer): ISubscriptable.L { final override fun addListener(listener: Consumer<Boolean>): Listenable.L {
return listeners.addListener(listener) return listeners.addListener(listener)
} }
@ -77,38 +78,32 @@ class RedstoneControl(private val valueChanges: (new: Boolean, old: Boolean) ->
} }
class SynchronizedRedstoneControl( class SynchronizedRedstoneControl(
synchronizer: FieldSynchronizer, synchronizer: DelegateSyncher,
private val valueChanges: (new: Boolean, old: Boolean) -> Unit, private val valueChanges: (new: Boolean, old: Boolean) -> Unit,
) : AbstractRedstoneControl() { ) : AbstractRedstoneControl() {
override var redstoneSetting: RedstoneSetting by synchronizer.enum(RedstoneSetting.LOW, setter = { value, access, setByRemote -> override var redstoneSetting: RedstoneSetting by synchronizer.enum(RedstoneSetting.LOW, setter = { access, value ->
if (access.read() == value) return@enum if (access.get() == value) return@enum
if (setByRemote) {
access.write(value)
} else {
val old = isBlockedByRedstone
access.write(value)
val state = isBlockedByRedstone
if (state != old) { val old = isBlockedByRedstone
valueChanges.invoke(state, old) access.accept(value)
listeners.accept(state) val state = isBlockedByRedstone
}
if (state != old) {
valueChanges.invoke(state, old)
listeners.accept(state)
} }
}) }).delegate
override var redstoneSignal: Int by synchronizer.int(0, setter = { value, access, setByRemote -> override var redstoneSignal: Int by synchronizer.int(0, setter = { access, value ->
if (access.readInt() == value) return@int if (access.get() == value) return@int
if (setByRemote) {
access.write(value)
} else {
val old = isBlockedByRedstone
access.write(value)
val state = isBlockedByRedstone
if (state != old) { val old = isBlockedByRedstone
valueChanges.invoke(state, old) access.accept(value)
listeners.accept(state) val state = isBlockedByRedstone
}
if (state != old) {
valueChanges.invoke(state, old)
listeners.accept(state)
} }
}).property }).delegate
} }

View File

@ -9,7 +9,6 @@ import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.EquipmentSlot import net.minecraft.world.entity.EquipmentSlot
import net.minecraft.world.entity.LivingEntity import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.boss.wither.WitherBoss
import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.entity.player.Player import net.minecraft.world.entity.player.Player
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
@ -20,7 +19,8 @@ import net.minecraft.world.level.levelgen.structure.BoundingBox
import net.minecraft.world.phys.AABB import net.minecraft.world.phys.AABB
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
import net.minecraftforge.common.Tags import net.minecraftforge.common.Tags
import net.minecraftforge.registries.ForgeRegistries import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.block.BlackHoleBlock import ru.dbotthepony.mc.otm.block.BlackHoleBlock
import ru.dbotthepony.mc.otm.block.entity.tech.GravitationStabilizerBlockEntity import ru.dbotthepony.mc.otm.block.entity.tech.GravitationStabilizerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
@ -37,6 +37,7 @@ import ru.dbotthepony.mc.otm.core.math.getSphericalBlockPositions
import ru.dbotthepony.mc.otm.core.math.times import ru.dbotthepony.mc.otm.core.math.times
import ru.dbotthepony.mc.otm.core.nbt.map import ru.dbotthepony.mc.otm.core.nbt.map
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.core.util.decimal
import ru.dbotthepony.mc.otm.matter.MatterManager import ru.dbotthepony.mc.otm.matter.MatterManager
import ru.dbotthepony.mc.otm.registry.MDamageTypes import ru.dbotthepony.mc.otm.registry.MDamageTypes
import ru.dbotthepony.mc.otm.registry.MatteryDamageSource import ru.dbotthepony.mc.otm.registry.MatteryDamageSource
@ -46,9 +47,9 @@ import kotlin.math.roundToInt
import kotlin.math.sqrt import kotlin.math.sqrt
class BlackHoleBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryBlockEntity(MBlockEntities.BLACK_HOLE, p_155229_, p_155230_) { class BlackHoleBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryBlockEntity(MBlockEntities.BLACK_HOLE, p_155229_, p_155230_) {
var mass by synchronizer.decimal(BASELINE_MASS, setter = setter@{ mass, field, setByRemote -> var mass by syncher.decimal(BASELINE_MASS, setter = setter@{ field, mass ->
if (setByRemote) { if (level !is ServerLevel) {
field.write(mass) field.accept(mass)
return@setter return@setter
} }
@ -57,19 +58,19 @@ class BlackHoleBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mattery
return@setter return@setter
} }
field.write(mass) field.accept(mass)
setChanged() setChanged()
updateGravStrength() updateGravStrength()
}) })
var gravitationStrength by synchronizer.double(1.0).property var gravitationStrength by syncher.double(1.0).delegate
private set private set
var affectedBounds = BoundingBox(0, 0, 0, 1, 1, 1) var affectedBounds = BoundingBox(0, 0, 0, 1, 1, 1)
private set private set
var affectedBoundsAABB: AABB = AABB.of(affectedBounds) var affectedBoundsAABB: AABB = AABB.of(affectedBounds)
private set private set
var spinDirection by synchronizer.bool().property var spinDirection by syncher.boolean().delegate
private var sphereIterator: Iterator<BlockPos>? = null private var sphereIterator: Iterator<BlockPos>? = null
private var sleepTicks = 4 private var sleepTicks = 4

View File

@ -2,7 +2,6 @@ package ru.dbotthepony.mc.otm.block.entity.cable
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.core.Direction import net.minecraft.core.Direction
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.entity.BlockEntityType
@ -23,6 +22,7 @@ import ru.dbotthepony.mc.otm.once
import ru.dbotthepony.mc.otm.onceServer import ru.dbotthepony.mc.otm.onceServer
import java.util.Collections import java.util.Collections
import java.util.EnumMap import java.util.EnumMap
import java.util.function.Consumer
// after some thinking, team decided to settle with IC2's side (techreborn, gregtech, integrated dynamics*, pipez*, p2p tunnels, ...) of implementation, // after some thinking, team decided to settle with IC2's side (techreborn, gregtech, integrated dynamics*, pipez*, p2p tunnels, ...) of implementation,
// where cables have no residue capacitance, and never pull/push energy by themselves // where cables have no residue capacitance, and never pull/push energy by themselves
@ -50,7 +50,7 @@ abstract class EnergyCableBlockEntity(type: BlockEntityType<*>, blockPos: BlockP
init { init {
waitForServerLevel { waitForServerLevel {
neighbour.addListener { neighbour.addListener(Consumer {
if (isEnabled) { if (isEnabled) {
if (it.isPresent) { if (it.isPresent) {
if (it.resolve().get() !is CableSide) { if (it.resolve().get() !is CableSide) {
@ -62,7 +62,7 @@ abstract class EnergyCableBlockEntity(type: BlockEntityType<*>, blockPos: BlockP
updateBlockState(blockRotation.side2Dir(side), it.isPresent || node.neighboursView[GraphNode.link(blockRotation.side2Dir(side))] != null) updateBlockState(blockRotation.side2Dir(side), it.isPresent || node.neighboursView[GraphNode.link(blockRotation.side2Dir(side))] != null)
} }
} }
} })
} }
} }

View File

@ -12,6 +12,7 @@ import net.minecraftforge.common.capabilities.ForgeCapabilities
import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidStack
import net.minecraftforge.fluids.capability.IFluidHandler import net.minecraftforge.fluids.capability.IFluidHandler
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import ru.dbotthepony.kommons.util.ListenableDelegate
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
import ru.dbotthepony.mc.otm.capability.item.CombinedItemHandler import ru.dbotthepony.mc.otm.capability.item.CombinedItemHandler
import ru.dbotthepony.mc.otm.capability.fluid.BlockMatteryFluidHandler import ru.dbotthepony.mc.otm.capability.fluid.BlockMatteryFluidHandler
@ -27,15 +28,14 @@ import ru.dbotthepony.mc.otm.menu.decorative.FluidTankMenu
import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlockEntities
class FluidTankBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.FLUID_TANK, blockPos, blockState) { class FluidTankBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.FLUID_TANK, blockPos, blockState) {
val fluid = BlockMatteryFluidHandler(ItemsConfig::FLUID_TANK_CAPACITY, synchronizer.Field(FluidStack.EMPTY, FluidStackValueCodec, setter = { value, access, remote -> val fluid = BlockMatteryFluidHandler(ItemsConfig::FLUID_TANK_CAPACITY, syncher.Slot(ListenableDelegate.SmartBox(FluidStack.EMPTY, setter = { access, value ->
access.write(value) access.accept(value)
level?.lightEngine?.checkBlock(blockPos) level?.lightEngine?.checkBlock(blockPos)
if (!remote) { if (level is ServerLevel) {
markDirtyFast() markDirtyFast()
} }
})) }), FluidStackValueCodec))
val fillInput = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer) val fillInput = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer)
val drainInput = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer) val drainInput = MatteryContainer(::markDirtyFast, 1).also(::addDroppableContainer)

View File

@ -3,12 +3,16 @@ package ru.dbotthepony.mc.otm.block.entity.decorative
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.CompoundTag
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.MenuProvider import net.minecraft.world.MenuProvider
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.AbstractContainerMenu import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.block.entity.IRedstoneControlled import ru.dbotthepony.mc.otm.block.entity.IRedstoneControlled
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
import ru.dbotthepony.mc.otm.block.entity.SynchronizedRedstoneControl import ru.dbotthepony.mc.otm.block.entity.SynchronizedRedstoneControl
@ -17,24 +21,23 @@ import ru.dbotthepony.mc.otm.core.math.component1
import ru.dbotthepony.mc.otm.core.math.component2 import ru.dbotthepony.mc.otm.core.math.component2
import ru.dbotthepony.mc.otm.core.math.component3 import ru.dbotthepony.mc.otm.core.math.component3
import ru.dbotthepony.mc.otm.menu.decorative.HoloSignMenu import ru.dbotthepony.mc.otm.menu.decorative.HoloSignMenu
import ru.dbotthepony.mc.otm.network.synchronizer.FloatFieldAccess
import ru.dbotthepony.mc.otm.once import ru.dbotthepony.mc.otm.once
import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.registry.MBlocks import ru.dbotthepony.mc.otm.registry.MBlocks
class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBlockEntity(MBlockEntities.HOLO_SIGN, blockPos, blockState), MenuProvider, IRedstoneControlled { class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBlockEntity(MBlockEntities.HOLO_SIGN, blockPos, blockState), MenuProvider, IRedstoneControlled {
override val redstoneControl = SynchronizedRedstoneControl(synchronizer) { _, _ -> setChanged() } override val redstoneControl = SynchronizedRedstoneControl(syncher) { _, _ -> setChanged() }
var signText by synchronizer.string("", setter = { value, access, remote -> var signText by syncher.string("", setter = { access, value ->
setChanged() setChanged()
access.write(value) access.accept(value)
}) }).delegate
private fun colorSetter(value: Float, access: FloatFieldAccess, setByRemote: Boolean) { private fun colorSetter(access: Delegate<Float>, value: Float) {
if (access.readFloat() != value) { if (access.get() != value) {
access.write(value) access.accept(value)
if (setByRemote) { if (level !is ServerLevel) {
markDirtyClientside() markDirtyClientside()
} else { } else {
markDirtyFast() markDirtyFast()
@ -47,10 +50,10 @@ class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryB
minecraft.levelRenderer.setBlocksDirty(x, y, z, x, y, z) minecraft.levelRenderer.setBlocksDirty(x, y, z, x, y, z)
} }
var textRed by synchronizer.float(1f, setter = ::colorSetter).property var textRed by syncher.float(1f, setter = ::colorSetter).delegate
var textGreen by synchronizer.float(1f, setter = ::colorSetter).property var textGreen by syncher.float(1f, setter = ::colorSetter).delegate
var textBlue by synchronizer.float(85f / 255f, setter = ::colorSetter).property var textBlue by syncher.float(85f / 255f, setter = ::colorSetter).delegate
var textAlpha by synchronizer.float(1f).property var textAlpha by syncher.float(1f).delegate
var isLocked = false var isLocked = false

View File

@ -9,6 +9,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity
import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.core.ifPresentK
import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlockEntities
import java.util.function.Consumer
class InfiniteWaterSourceBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBlockEntity(MBlockEntities.INFINITE_WATER_SOURCE, blockPos, blockState), IFluidHandler { class InfiniteWaterSourceBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBlockEntity(MBlockEntities.INFINITE_WATER_SOURCE, blockPos, blockState), IFluidHandler {
override fun getTanks(): Int { override fun getTanks(): Int {
@ -55,7 +56,7 @@ class InfiniteWaterSourceBlockEntity(blockPos: BlockPos, blockState: BlockState)
} }
} }
tracker.addListener { ticker.isEnabled = it.isPresent } tracker.addListener(Consumer { ticker.isEnabled = it.isPresent })
} }
} }
} }

View File

@ -7,6 +7,9 @@ import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.kommons.util.value
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity import ru.dbotthepony.mc.otm.block.entity.tech.BatteryBankBlockEntity
import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.FlowDirection
@ -22,7 +25,7 @@ import ru.dbotthepony.mc.otm.menu.matter.MatterCapacitorBankMenu
import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlockEntities
class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.MATTER_CAPACITOR_BANK, p_155229_, p_155230_), IMatterStorage { class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.MATTER_CAPACITOR_BANK, p_155229_, p_155230_), IMatterStorage {
var gaugeLevel by synchronizer.float().property var gaugeLevel by syncher.float()
private set private set
val matterNode = SimpleMatterNode(matter = this) val matterNode = SimpleMatterNode(matter = this)
@ -123,7 +126,7 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
val container = object : MatteryContainer(this::markDirtyFast, BatteryBankBlockEntity.CAPACITY) { val container = object : MatteryContainer(this::markDirtyFast, BatteryBankBlockEntity.CAPACITY) {
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
super.setChanged(slot, new, old) super.setChanged(slot, new, old)
capacitorStatus[slot].boolean = new.getCapability(MatteryCapability.MATTER).isPresent capacitorStatus[slot].value = new.getCapability(MatteryCapability.MATTER).isPresent
gaugeLevel = storedMatter.percentage(maxStoredMatter) gaugeLevel = storedMatter.percentage(maxStoredMatter)
} }
@ -147,7 +150,7 @@ class MatterCapacitorBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState)
})) }))
val capacitorStatus = immutableList(BatteryBankBlockEntity.CAPACITY) { val capacitorStatus = immutableList(BatteryBankBlockEntity.CAPACITY) {
synchronizer.bool(false) syncher.boolean(false)
} }
init { init {

View File

@ -11,6 +11,8 @@ import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import net.minecraftforge.registries.ForgeRegistries import net.minecraftforge.registries.ForgeRegistries
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryPoweredBlockEntity
import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.MatteryCapability
@ -27,6 +29,7 @@ import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.container.UpgradeContainer import ru.dbotthepony.mc.otm.container.UpgradeContainer
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.core.util.item
import ru.dbotthepony.mc.otm.graph.matter.MatterNode import ru.dbotthepony.mc.otm.graph.matter.MatterNode
import ru.dbotthepony.mc.otm.matter.IMatterValue import ru.dbotthepony.mc.otm.matter.IMatterValue
import ru.dbotthepony.mc.otm.matter.MatterManager import ru.dbotthepony.mc.otm.matter.MatterManager
@ -43,7 +46,7 @@ class MatterReconstructorBlockEntity(blockPos: BlockPos, blockState: BlockState)
private var lastItem: Item? = null private var lastItem: Item? = null
private var initialDamage = 0.0 private var initialDamage = 0.0
var visualItemStack by synchronizer.item(observe = false) var visualItemStack by syncher.item()
private set private set
var visualProgress = 0f var visualProgress = 0f

View File

@ -9,6 +9,8 @@ import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.block.entity.JobContainer import ru.dbotthepony.mc.otm.block.entity.JobContainer
import ru.dbotthepony.mc.otm.block.entity.JobStatus import ru.dbotthepony.mc.otm.block.entity.JobStatus
import ru.dbotthepony.mc.otm.block.entity.ItemJob import ru.dbotthepony.mc.otm.block.entity.ItemJob
@ -26,6 +28,7 @@ import ru.dbotthepony.mc.otm.container.HandlerFilter
import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.container.UpgradeContainer import ru.dbotthepony.mc.otm.container.UpgradeContainer
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.util.item
import ru.dbotthepony.mc.otm.data.DecimalCodec import ru.dbotthepony.mc.otm.data.DecimalCodec
import ru.dbotthepony.mc.otm.data.UUIDCodec import ru.dbotthepony.mc.otm.data.UUIDCodec
import ru.dbotthepony.mc.otm.data.minRange import ru.dbotthepony.mc.otm.data.minRange
@ -142,10 +145,10 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
visualProgress = 0f visualProgress = 0f
} }
var visualItemStack by synchronizer.item(observe = false) var visualItemStack by syncher.item()
private set private set
var visualProgress by synchronizer.float().property var visualProgress by syncher.float()
private set private set
var renderRotation = 0f var renderRotation = 0f

View File

@ -7,6 +7,8 @@ import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.block.entity.JobContainer import ru.dbotthepony.mc.otm.block.entity.JobContainer
import ru.dbotthepony.mc.otm.block.entity.JobStatus import ru.dbotthepony.mc.otm.block.entity.JobStatus
import ru.dbotthepony.mc.otm.block.entity.ItemJob import ru.dbotthepony.mc.otm.block.entity.ItemJob
@ -21,6 +23,7 @@ import ru.dbotthepony.mc.otm.config.MachinesConfig
import ru.dbotthepony.mc.otm.container.MatteryContainer import ru.dbotthepony.mc.otm.container.MatteryContainer
import ru.dbotthepony.mc.otm.container.HandlerFilter import ru.dbotthepony.mc.otm.container.HandlerFilter
import ru.dbotthepony.mc.otm.container.UpgradeContainer import ru.dbotthepony.mc.otm.container.UpgradeContainer
import ru.dbotthepony.mc.otm.core.util.item
import ru.dbotthepony.mc.otm.menu.matter.MatterScannerMenu import ru.dbotthepony.mc.otm.menu.matter.MatterScannerMenu
import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.graph.matter.MatterNode import ru.dbotthepony.mc.otm.graph.matter.MatterNode
@ -162,10 +165,10 @@ class MatterScannerBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
visualProgress = 0f visualProgress = 0f
} }
var visualItemStack by synchronizer.item(observe = false) var visualItemStack by syncher.item()
private set private set
var visualProgress by synchronizer.float().property var visualProgress by syncher.float()
private set private set
override fun onJobTick(status: JobStatus<ItemJob>, id: Int) { override fun onJobTick(status: JobStatus<ItemJob>, id: Int) {

View File

@ -21,6 +21,7 @@ import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.storage.optics.priority import ru.dbotthepony.mc.otm.storage.optics.priority
import ru.dbotthepony.mc.otm.storage.optics.powered import ru.dbotthepony.mc.otm.storage.optics.powered
import ru.dbotthepony.mc.otm.storage.optics.flow import ru.dbotthepony.mc.otm.storage.optics.flow
import java.util.function.Consumer
class DriveRackBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.DRIVE_RACK, blockPos, blockState) { class DriveRackBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryPoweredBlockEntity(MBlockEntities.DRIVE_RACK, blockPos, blockState) {
override val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this::markDirtyFast, MachinesConfig.DRIVE_RACK)) override val energy = ProfiledEnergyStorage(WorkerEnergyStorage(this::markDirtyFast, MachinesConfig.DRIVE_RACK))
@ -67,9 +68,9 @@ class DriveRackBlockEntity(blockPos: BlockPos, blockState: BlockState) : Mattery
savetables.int(::extractPriority) savetables.int(::extractPriority)
savetables.enum(::mode, map = FlowDirection::valueOf) savetables.enum(::mode, map = FlowDirection::valueOf)
redstoneControl.addListener { redstoneControl.addListener(Consumer {
cell.isDetached = it cell.isDetached = it
} })
} }
override fun setLevel(level: Level) { override fun setLevel(level: Level) {

View File

@ -34,6 +34,7 @@ import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.storage.* import ru.dbotthepony.mc.otm.storage.*
import java.math.BigInteger import java.math.BigInteger
import java.util.* import java.util.*
import java.util.function.Consumer
import java.util.stream.Stream import java.util.stream.Stream
private data class SlotTuple(val slot: Int, val stack: ItemStack) private data class SlotTuple(val slot: Int, val stack: ItemStack)
@ -101,24 +102,24 @@ class StorageBusBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matter
savetables.int(::extractPriority) savetables.int(::extractPriority)
exposeGlobally(MatteryCapability.STORAGE_NODE, cell) { it != RelativeSide.FRONT } exposeGlobally(MatteryCapability.STORAGE_NODE, cell) { it != RelativeSide.FRONT }
side(RelativeSide.FRONT).track(ForgeCapabilities.ITEM_HANDLER).addListener { side(RelativeSide.FRONT).track(ForgeCapabilities.ITEM_HANDLER).addListener(Consumer {
component?.let(cell::removeStorageComponent) component?.let(cell::removeStorageComponent)
component = if (it.isPresent) { component = if (it.isPresent) {
ItemHandlerComponent(it.orThrow()).also { if (!redstoneControl.isBlockedByRedstone) cell.addStorageComponent(it) } ItemHandlerComponent(it.orThrow()).also { if (!redstoneControl.isBlockedByRedstone) cell.addStorageComponent(it) }
} else { } else {
null null
} }
} })
redstoneControl.addListener { redstoneControl.addListener(Consumer {
val component = component ?: return@addListener val component = component ?: return@Consumer
if (it) { if (it) {
cell.removeStorageComponent(component) cell.removeStorageComponent(component)
} else { } else {
cell.addStorageComponent(component) cell.addStorageComponent(component)
} }
} })
} }
val filter = ItemFilter(MAX_FILTERS) { val filter = ItemFilter(MAX_FILTERS) {

View File

@ -14,6 +14,8 @@ import net.minecraft.world.item.crafting.SmokingRecipe
import net.minecraft.world.level.block.entity.BlockEntityType import net.minecraft.world.level.block.entity.BlockEntityType
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.capabilities.ForgeCapabilities
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.block.entity.ExperienceStorage import ru.dbotthepony.mc.otm.block.entity.ExperienceStorage
import ru.dbotthepony.mc.otm.block.entity.JobContainer import ru.dbotthepony.mc.otm.block.entity.JobContainer
import ru.dbotthepony.mc.otm.block.entity.JobStatus import ru.dbotthepony.mc.otm.block.entity.JobStatus
@ -32,7 +34,9 @@ import ru.dbotthepony.mc.otm.container.UpgradeContainer
import ru.dbotthepony.mc.otm.container.balance import ru.dbotthepony.mc.otm.container.balance
import ru.dbotthepony.mc.otm.core.collect.filter import ru.dbotthepony.mc.otm.core.collect.filter
import ru.dbotthepony.mc.otm.core.collect.maybe import ru.dbotthepony.mc.otm.core.collect.maybe
import ru.dbotthepony.mc.otm.core.getValue
import ru.dbotthepony.mc.otm.core.immutableList import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.core.util.item
import ru.dbotthepony.mc.otm.menu.tech.PoweredFurnaceMenu import ru.dbotthepony.mc.otm.menu.tech.PoweredFurnaceMenu
import ru.dbotthepony.mc.otm.recipe.MatteryCookingRecipe import ru.dbotthepony.mc.otm.recipe.MatteryCookingRecipe
import ru.dbotthepony.mc.otm.recipe.MicrowaveRecipe import ru.dbotthepony.mc.otm.recipe.MicrowaveRecipe
@ -60,9 +64,9 @@ sealed class AbstractPoweredFurnaceBlockEntity<P : AbstractCookingRecipe, S : Ma
} }
inner class SyncSlot { inner class SyncSlot {
var inputItem by synchronizer.item(observe = false) var inputItem by syncher.item()
var outputItem by synchronizer.item(observe = false) var outputItem by syncher.item()
var progress by synchronizer.float().property var progress by syncher.float()
var visualRotation = 0f var visualRotation = 0f
} }

View File

@ -7,6 +7,9 @@ import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.capabilities.ForgeCapabilities
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.kommons.util.value
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.capability.energy import ru.dbotthepony.mc.otm.capability.energy
@ -25,14 +28,14 @@ import ru.dbotthepony.mc.otm.registry.MBlockEntities
import java.util.function.Supplier import java.util.function.Supplier
class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.BATTERY_BANK, p_155229_, p_155230_), IMatteryEnergyStorage { class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.BATTERY_BANK, p_155229_, p_155230_), IMatteryEnergyStorage {
var gaugeLevel by synchronizer.float().property var gaugeLevel by syncher.float()
private set private set
// 6 на 2 // 6 на 2
val container: MatteryContainer = object : MatteryContainer(::setChanged, CAPACITY) { val container: MatteryContainer = object : MatteryContainer(::setChanged, CAPACITY) {
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) { override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
super.setChanged(slot, new, old) super.setChanged(slot, new, old)
batteryStatus[slot].boolean = new.getCapability(ForgeCapabilities.ENERGY).isPresent batteryStatus[slot].value = new.getCapability(ForgeCapabilities.ENERGY).isPresent
gaugeLevel = batteryLevel.percentage(maxBatteryLevel) gaugeLevel = batteryLevel.percentage(maxBatteryLevel)
} }
@ -40,7 +43,7 @@ class BatteryBankBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Matte
}.also(::addDroppableContainer) }.also(::addDroppableContainer)
val batteryStatus = immutableList(CAPACITY) { val batteryStatus = immutableList(CAPACITY) {
synchronizer.bool(false) syncher.boolean(false)
} }
val itemConfig = ConfigurableItemHandler(inputOutput = container.handler(HandlerFilter.Dischargeable)) val itemConfig = ConfigurableItemHandler(inputOutput = container.handler(HandlerFilter.Dischargeable))

View File

@ -10,6 +10,8 @@ import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.AbstractContainerMenu import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.capabilities.ForgeCapabilities
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.block.tech.EnergyCounterBlock import ru.dbotthepony.mc.otm.block.tech.EnergyCounterBlock
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
import ru.dbotthepony.mc.otm.capability.* import ru.dbotthepony.mc.otm.capability.*
@ -23,12 +25,13 @@ import ru.dbotthepony.mc.otm.core.nbt.map
import ru.dbotthepony.mc.otm.core.nbt.mapPresent import ru.dbotthepony.mc.otm.core.nbt.mapPresent
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.core.util.countingLazy import ru.dbotthepony.mc.otm.core.util.countingLazy
import ru.dbotthepony.mc.otm.core.util.decimal
import ru.dbotthepony.mc.otm.menu.tech.EnergyCounterMenu import ru.dbotthepony.mc.otm.menu.tech.EnergyCounterMenu
import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlockEntities
import java.util.* import java.util.*
class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.ENERGY_COUNTER, p_155229_, p_155230_) { class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.ENERGY_COUNTER, p_155229_, p_155230_) {
var passed by synchronizer.decimal() var passed by syncher.decimal()
override val blockRotation: BlockRotation by countingLazy(blockStateChangesCounter) { override val blockRotation: BlockRotation by countingLazy(blockStateChangesCounter) {
BlockRotation.of(blockState[EnergyCounterBlock.INPUT_DIRECTION]) BlockRotation.of(blockState[EnergyCounterBlock.INPUT_DIRECTION])
@ -37,7 +40,7 @@ class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mat
private val history = Array(10 * 20) { Decimal.ZERO } private val history = Array(10 * 20) { Decimal.ZERO }
internal var historyTick = 0 internal var historyTick = 0
var lastTick by synchronizer.decimal() var lastTick by syncher.decimal()
internal set internal set
var ioLimit: Decimal? = null var ioLimit: Decimal? = null

View File

@ -4,7 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.PoseStack
import it.unimi.dsi.fastutil.ints.IntAVLTreeSet import it.unimi.dsi.fastutil.ints.IntAVLTreeSet
import it.unimi.dsi.fastutil.ints.IntSet import it.unimi.dsi.fastutil.ints.IntSet
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap
import net.minecraft.ChatFormatting import net.minecraft.ChatFormatting
import net.minecraft.client.model.PlayerModel import net.minecraft.client.model.PlayerModel
import net.minecraft.client.player.AbstractClientPlayer import net.minecraft.client.player.AbstractClientPlayer
@ -62,6 +62,17 @@ import net.minecraftforge.registries.ForgeRegistries
import net.minecraftforge.server.command.EnumArgument import net.minecraftforge.server.command.EnumArgument
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.joml.Vector4f import org.joml.Vector4f
import ru.dbotthepony.kommons.collect.ListenableMap
import ru.dbotthepony.kommons.collect.ListenableSet
import ru.dbotthepony.kommons.io.DelegateSyncher
import ru.dbotthepony.kommons.io.IntValueCodec
import ru.dbotthepony.kommons.io.RGBCodec
import ru.dbotthepony.kommons.io.UUIDValueCodec
import ru.dbotthepony.kommons.io.VarIntValueCodec
import ru.dbotthepony.kommons.util.ListenableDelegate
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.kommons.util.value
import ru.dbotthepony.mc.otm.* import ru.dbotthepony.mc.otm.*
import ru.dbotthepony.mc.otm.android.AndroidFeature import ru.dbotthepony.mc.otm.android.AndroidFeature
import ru.dbotthepony.mc.otm.android.AndroidFeatureType import ru.dbotthepony.mc.otm.android.AndroidFeatureType
@ -91,25 +102,20 @@ import ru.dbotthepony.mc.otm.container.vanishCursedItems
import ru.dbotthepony.mc.otm.core.* import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.core.collect.UUIDIntModifiersMap import ru.dbotthepony.mc.otm.core.collect.UUIDIntModifiersMap
import ru.dbotthepony.mc.otm.core.collect.filter import ru.dbotthepony.mc.otm.core.collect.filter
import ru.dbotthepony.mc.otm.core.math.RGBColorDFUCodec
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.minus import ru.dbotthepony.mc.otm.core.math.minus
import ru.dbotthepony.mc.otm.core.nbt.getCompoundList import ru.dbotthepony.mc.otm.core.nbt.getCompoundList
import ru.dbotthepony.mc.otm.core.nbt.getIntList import ru.dbotthepony.mc.otm.core.nbt.getIntList
import ru.dbotthepony.mc.otm.core.nbt.getStringList import ru.dbotthepony.mc.otm.core.nbt.getStringList
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.core.util.IntValueCodec
import ru.dbotthepony.mc.otm.core.util.ItemValueCodec import ru.dbotthepony.mc.otm.core.util.ItemValueCodec
import ru.dbotthepony.mc.otm.core.util.RGBCodec
import ru.dbotthepony.mc.otm.core.util.Savetables import ru.dbotthepony.mc.otm.core.util.Savetables
import ru.dbotthepony.mc.otm.core.util.TickList import ru.dbotthepony.mc.otm.core.util.TickList
import ru.dbotthepony.mc.otm.core.util.UUIDValueCodec
import ru.dbotthepony.mc.otm.core.util.VarIntValueCodec
import ru.dbotthepony.mc.otm.menu.ExopackInventoryMenu import ru.dbotthepony.mc.otm.menu.ExopackInventoryMenu
import ru.dbotthepony.mc.otm.menu.IItemStackSortingSettings import ru.dbotthepony.mc.otm.menu.IItemStackSortingSettings
import ru.dbotthepony.mc.otm.network.* import ru.dbotthepony.mc.otm.network.*
import ru.dbotthepony.mc.otm.network.SmokeParticlesPacket.Companion.makeSmoke import ru.dbotthepony.mc.otm.network.SmokeParticlesPacket.Companion.makeSmoke
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
import ru.dbotthepony.mc.otm.registry.AndroidFeatures import ru.dbotthepony.mc.otm.registry.AndroidFeatures
import ru.dbotthepony.mc.otm.registry.MDamageTypes import ru.dbotthepony.mc.otm.registry.MDamageTypes
import ru.dbotthepony.mc.otm.registry.MItems import ru.dbotthepony.mc.otm.registry.MItems
@ -200,7 +206,12 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
* any differences in field order/types/etc between client and server * any differences in field order/types/etc between client and server
* will break *everything* * will break *everything*
*/ */
val synchronizer = FieldSynchronizer() val syncher = DelegateSyncher()
/**
* Remote for "this" player
*/
val privateSyncherRemote = syncher.Remote()
/** /**
* For fields that need to be synchronized to everyone * For fields that need to be synchronized to everyone
@ -209,7 +220,10 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
* any differences in field order/types/etc between client and server * any differences in field order/types/etc between client and server
* will break *everything* * will break *everything*
*/ */
val publicSynchronizer = FieldSynchronizer() val publicSyncher = DelegateSyncher()
val publicSyncherRemote = publicSyncher.Remote()
val remoteSynchers = Object2ObjectArrayMap<ServerPlayer, DelegateSyncher.Remote>()
/** /**
* For data to be stored to and loaded from NBT automatically * For data to be stored to and loaded from NBT automatically
@ -219,8 +233,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
/** /**
* Whenever player has Exopack * Whenever player has Exopack
*/ */
var hasExopack by publicSynchronizer.bool(setter = setter@{ value, access, _ -> var hasExopack by publicSyncher.boolean(setter = setter@{ access, value ->
access.write(value) access.accept(value)
_exoPackMenu = null _exoPackMenu = null
if (value && ply is ServerPlayer) { if (value && ply is ServerPlayer) {
@ -228,32 +242,34 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
ExopackObtainedTrigger.trigger(ply) ExopackObtainedTrigger.trigger(ply)
} }
} }
}).property })
/** /**
* Whenever to render Exopack on player * Whenever to render Exopack on player
*/ */
var isExopackVisible by publicSynchronizer.bool(true).property var isExopackVisible by publicSyncher.boolean(true)
/** /**
* Whenever to render Exopack glow in dark * Whenever to render Exopack glow in dark
*/ */
var exopackGlows by publicSynchronizer.bool(true).property var exopackGlows by publicSyncher.boolean(true)
var exopackColor by publicSynchronizer.Field(null, RGBCodec.nullable) var exopackColor by publicSyncher.add(ListenableDelegate.Box(null), RGBCodec.nullable)
/** /**
* Tick event schedulers * Tick event schedulers
*/ */
val tickList = TickList() val tickList = TickList()
private val exopackSlotModifierMap: MutableMap<UUID, Int> by synchronizer.Map( // kotlin moment
private fun _recomputeModifiers() {
exopackSlotModifier.recompute()
}
private val exopackSlotModifierMap = syncher.MapSlot(
ListenableMap<UUID, Int>().also { it.addListener(Runnable { _recomputeModifiers() }) },
keyCodec = UUIDValueCodec, keyCodec = UUIDValueCodec,
valueCodec = IntValueCodec, valueCodec = IntValueCodec,
backingMap = HashMap(),
callback = {
this.exopackSlotModifier.recompute()
},
) )
/** /**
@ -267,16 +283,16 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
} else { } else {
exopackContainer = PlayerMatteryContainer(it) exopackContainer = PlayerMatteryContainer(it)
} }
}, backingMap = this.exopackSlotModifierMap) }, backingMap = this.exopackSlotModifierMap.delegate)
val regularSlotFilters = immutableList(Inventory.INVENTORY_SIZE) { val regularSlotFilters = immutableList(Inventory.INVENTORY_SIZE) {
synchronizer.Field(null, ItemValueCodec.nullable) syncher.add(null, ItemValueCodec.nullable)
} }
val slotsChargeFlag by synchronizer.Set( val slotsChargeFlag = syncher.SetSlot(
codec = VarIntValueCodec, ListenableSet(IntAVLTreeSet()),
backingSet = IntAVLTreeSet(), VarIntValueCodec,
) ).delegate
private fun slotChargeToDefault() { private fun slotChargeToDefault() {
// броня // броня
@ -311,7 +327,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
} }
value.deserializeNBT(field.serializeNBT()) value.deserializeNBT(field.serializeNBT())
value.addFilterSynchronizer(synchronizer) value.addFilterSynchronizer(syncher)
field = value field = value
_combinedInventory = null _combinedInventory = null
@ -373,9 +389,9 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
/** /**
* Whenever Exopack has 3x3 crafting grid upgrade installed * Whenever Exopack has 3x3 crafting grid upgrade installed
*/ */
var isExopackCraftingUpgraded by publicSynchronizer.bool(setter = setter@{ value, access, _ -> var isExopackCraftingUpgraded by publicSyncher.boolean(setter = setter@{ access, value ->
if (value != access.readBoolean()) { if (value != access.get()) {
access.write(value) access.accept(value)
_exoPackMenu = null _exoPackMenu = null
if (value && ply is ServerPlayer) { if (value && ply is ServerPlayer) {
@ -384,11 +400,11 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
} }
} }
} }
}).property })
var isExopackEnderAccessInstalled by publicSynchronizer.bool(setter = setter@{ value, access, _ -> var isExopackEnderAccessInstalled by publicSyncher.boolean(setter = setter@{ access, value ->
if (value != access.readBoolean()) { if (value != access.get()) {
access.write(value) access.accept(value)
_exoPackMenu = null _exoPackMenu = null
if (value && ply is ServerPlayer) { if (value && ply is ServerPlayer) {
@ -397,7 +413,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
} }
} }
} }
}).property })
private var _exoPackMenu: ExopackInventoryMenu? = null private var _exoPackMenu: ExopackInventoryMenu? = null
set(value) { set(value) {
@ -441,11 +457,6 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
private var nextDischargeHurt = 20 private var nextDischargeHurt = 20
private var nextHealTick = 0 private var nextHealTick = 0
// players tracking us
// stored separately because EntityTracker and ChunkMup, etc are buried deep and
// getting them unburied will be a very work intense task
private val trackingPlayers = Reference2ObjectOpenHashMap<ServerPlayer, FieldSynchronizer.Endpoint>()
/** /**
* This returns if player is an Android or will become one on death/sleep/etc * This returns if player is an Android or will become one on death/sleep/etc
*/ */
@ -471,7 +482,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
/** /**
* Whenever player should become an Android once transformation conditions are met (e.g. player dies or sleeps in bed) * Whenever player should become an Android once transformation conditions are met (e.g. player dies or sleeps in bed)
*/ */
var willBecomeAndroid by publicSynchronizer.bool().property var willBecomeAndroid by publicSyncher.boolean()
/** /**
* Whenever player is an Android * Whenever player is an Android
@ -487,14 +498,14 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
* *
* Android-immune (de)buffs are specified in `data/overdrive_that_matters/tags/mob_effect/android_immune_effects.json` * Android-immune (de)buffs are specified in `data/overdrive_that_matters/tags/mob_effect/android_immune_effects.json`
*/ */
var isAndroid by publicSynchronizer.bool().property var isAndroid by publicSyncher.boolean()
/** /**
* Whenever player has exosuit smelting upgrade * Whenever player has exosuit smelting upgrade
*/ */
var isExopackSmeltingInstalled by synchronizer.bool(setter = { value, access, _ -> var isExopackSmeltingInstalled by syncher.boolean(setter = { access, value ->
if (value != access.readBoolean()) { if (value != access.get()) {
access.write(value) access.accept(value)
_exoPackMenu = null _exoPackMenu = null
if (value && ply is ServerPlayer) { if (value && ply is ServerPlayer) {
@ -503,7 +514,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
} }
} }
} }
}).property })
inner class SmelterBelt(index: Int) : MachineJobEventLoop<ItemJob>(ItemJob.CODEC) { inner class SmelterBelt(index: Int) : MachineJobEventLoop<ItemJob>(ItemJob.CODEC) {
override val energy: IMatteryEnergyStorage override val energy: IMatteryEnergyStorage
@ -568,12 +579,12 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
/** /**
* [IMatteryEnergyStorage] instance, representing Android' battery charge * [IMatteryEnergyStorage] instance, representing Android' battery charge
*/ */
val androidEnergy = BatteryBackedEnergyStorage(ply, synchronizer, AndroidConfig.ANDROID_MAX_ENERGY, AndroidConfig.ANDROID_MAX_ENERGY, true) val androidEnergy = BatteryBackedEnergyStorage(ply, syncher, AndroidConfig.ANDROID_MAX_ENERGY, AndroidConfig.ANDROID_MAX_ENERGY, true)
/** /**
* [IMatteryEnergyStorage] instance, representing Exopack battery charge * [IMatteryEnergyStorage] instance, representing Exopack battery charge
*/ */
val exopackEnergy = ProfiledEnergyStorage(BatteryBackedEnergyStorage(ply, synchronizer, Decimal.ZERO, ExopackConfig.ENERGY_CAPACITY, false, onChange = { for (v in smelters) v.notify(MachineJobEventLoop.IdleReason.POWER) })) val exopackEnergy = ProfiledEnergyStorage(BatteryBackedEnergyStorage(ply, syncher, Decimal.ZERO, ExopackConfig.ENERGY_CAPACITY, false, onChange = { for (v in smelters) v.notify(MachineJobEventLoop.IdleReason.POWER) }))
val exopackChargeSlots = MatteryContainer(4) val exopackChargeSlots = MatteryContainer(4)
@ -604,7 +615,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
savetables.float(::exopackSmelterExperience, "exoPackSmelterExperience") savetables.float(::exopackSmelterExperience, "exoPackSmelterExperience")
savetables.bool(::isExopackSmeltingInstalled, "isExoPackSmeltingInstalled") savetables.bool(::isExopackSmeltingInstalled, "isExoPackSmeltingInstalled")
savetables.codecNullable(::exopackColor, RGBAColor.CODECRGB) savetables.codecNullable(::exopackColor, RGBColorDFUCodec)
savetables.bool(::exopackGlows) savetables.bool(::exopackGlows)
savetables.stateful(::sortingSettings) savetables.stateful(::sortingSettings)
@ -612,8 +623,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
} }
fun invalidateNetworkState() { fun invalidateNetworkState() {
synchronizer.invalidate() privateSyncherRemote.invalidate()
publicSynchronizer.invalidate() remoteSynchers.values.forEach { it.invalidate() }
for (instance in research.values) { for (instance in research.values) {
instance.invalidateNetwork() instance.invalidateNetwork()
@ -982,7 +993,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
override fun deserializeNBT(tag: CompoundTag) { override fun deserializeNBT(tag: CompoundTag) {
savetables.deserializeNBT(tag) savetables.deserializeNBT(tag)
if (MItems.ExopackUpgrades.INVENTORY_UPGRADE_ENDER_DRAGON.uuid(ItemStack.EMPTY) in exopackSlotModifierMap) { if (MItems.ExopackUpgrades.INVENTORY_UPGRADE_ENDER_DRAGON.uuid(ItemStack.EMPTY) in exopackSlotModifierMap.delegate) {
isExopackEnderAccessInstalled = true isExopackEnderAccessInstalled = true
} }
@ -1318,28 +1329,28 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
tickedOnce = true tickedOnce = true
val payload = synchronizer.collectNetworkPayload() val payload = privateSyncherRemote.write()
if (payload != null) { if (payload != null) {
MatteryPlayerNetworkChannel.send(ply, MatteryPlayerFieldPacket(payload, false)) MatteryPlayerNetworkChannel.send(ply, MatteryPlayerFieldPacket(payload, false))
} }
val trackingIterator = trackingPlayers.entries.iterator() val trackingIterator = remoteSynchers.entries.iterator()
for ((ply, endpoint) in trackingIterator) { for ((ply, remote) in trackingIterator) {
if (ply.hasDisconnected()) { if (ply.hasDisconnected()) {
trackingIterator.remove() trackingIterator.remove()
continue continue
} }
val payload2 = endpoint.collectNetworkPayload() val payload2 = remote.write()
if (payload2 != null) { if (payload2 != null) {
MatteryPlayerNetworkChannel.send(ply, MatteryPlayerFieldPacket(payload2, true, this.ply.uuid)) MatteryPlayerNetworkChannel.send(ply, MatteryPlayerFieldPacket(payload2, true, this.ply.uuid))
} }
} }
val payload3 = publicSynchronizer.collectNetworkPayload() val payload3 = publicSyncherRemote.write()
if (payload3 != null) { if (payload3 != null) {
MatteryPlayerNetworkChannel.send(ply, MatteryPlayerFieldPacket(payload3, true)) MatteryPlayerNetworkChannel.send(ply, MatteryPlayerFieldPacket(payload3, true))
@ -1751,14 +1762,14 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
fun onStartTracking(event: PlayerEvent.StartTracking) { fun onStartTracking(event: PlayerEvent.StartTracking) {
if (event.target is ServerPlayer) { if (event.target is ServerPlayer) {
event.target.matteryPlayer?.let { event.target.matteryPlayer?.let {
it.trackingPlayers[event.entity as ServerPlayer] = it.publicSynchronizer.Endpoint() it.remoteSynchers[event.entity as ServerPlayer] = it.publicSyncher.Remote()
} }
} }
} }
fun onStopTracking(event: PlayerEvent.StopTracking) { fun onStopTracking(event: PlayerEvent.StopTracking) {
if (event.target is ServerPlayer) { if (event.target is ServerPlayer) {
event.target.matteryPlayer?.trackingPlayers?.remove(event.entity as ServerPlayer) event.target.matteryPlayer?.remoteSynchers?.remove(event.entity as ServerPlayer)
} }
} }

View File

@ -7,6 +7,9 @@ import net.minecraft.world.item.ItemStack
import net.minecraft.world.ticks.ContainerSingleItem import net.minecraft.world.ticks.ContainerSingleItem
import net.minecraftforge.common.capabilities.ForgeCapabilities import net.minecraftforge.common.capabilities.ForgeCapabilities
import net.minecraftforge.common.util.INBTSerializable import net.minecraftforge.common.util.INBTSerializable
import ru.dbotthepony.kommons.io.DelegateSyncher
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.capability.extractEnergy import ru.dbotthepony.mc.otm.capability.extractEnergy
import ru.dbotthepony.mc.otm.capability.receiveEnergy import ru.dbotthepony.mc.otm.capability.receiveEnergy
@ -15,14 +18,15 @@ import ru.dbotthepony.mc.otm.core.math.getDecimal
import ru.dbotthepony.mc.otm.core.nbt.getItemStack import ru.dbotthepony.mc.otm.core.nbt.getItemStack
import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.core.ifPresentK
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer import ru.dbotthepony.mc.otm.core.util.decimal
import ru.dbotthepony.mc.otm.core.util.observedItem
import ru.dbotthepony.mc.otm.registry.StatNames import ru.dbotthepony.mc.otm.registry.StatNames
import ru.dbotthepony.mc.otm.triggers.AndroidBatteryTrigger import ru.dbotthepony.mc.otm.triggers.AndroidBatteryTrigger
import ru.dbotthepony.mc.otm.triggers.ExopackBatterySlotTrigger import ru.dbotthepony.mc.otm.triggers.ExopackBatterySlotTrigger
class BatteryBackedEnergyStorage( class BatteryBackedEnergyStorage(
private val ply: Player, private val ply: Player,
synchronizer: FieldSynchronizer, synchronizer: DelegateSyncher,
initialCharge: Decimal, initialCharge: Decimal,
maxCharge: Decimal, maxCharge: Decimal,
val isAndroid: Boolean, val isAndroid: Boolean,
@ -34,8 +38,8 @@ class BatteryBackedEnergyStorage(
private var battery by synchronizer.decimal(initialCharge) private var battery by synchronizer.decimal(initialCharge)
private var maxBattery by synchronizer.decimal(maxCharge) private var maxBattery by synchronizer.decimal(maxCharge)
var item by synchronizer.item(setter = setter@{ value, access, _ -> var item by synchronizer.observedItem(setter = setter@{ access, value ->
access.write(value) access.accept(value)
if (ply is ServerPlayer && isAndroid) { if (ply is ServerPlayer && isAndroid) {
AndroidBatteryTrigger.trigger(ply, value) AndroidBatteryTrigger.trigger(ply, value)

View File

@ -3,7 +3,7 @@ package ru.dbotthepony.mc.otm.capability.energy
import net.minecraftforge.energy.IEnergyStorage import net.minecraftforge.energy.IEnergyStorage
import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import java.math.BigInteger import java.math.BigInteger
import kotlin.math.roundToInt import kotlin.math.roundToInt

View File

@ -5,15 +5,17 @@ import net.minecraft.world.item.BlockItem
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraftforge.common.util.INBTSerializable import net.minecraftforge.common.util.INBTSerializable
import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.FluidStack
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.core.tagNotNull import ru.dbotthepony.mc.otm.core.tagNotNull
import ru.dbotthepony.mc.otm.network.synchronizer.IMutableField
import java.util.function.IntSupplier import java.util.function.IntSupplier
/** /**
* Fluid handler for blocks * Fluid handler for blocks
*/ */
open class BlockMatteryFluidHandler(private val _capacity: IntSupplier, field: IMutableField<FluidStack>) : AbstractMatteryFluidHandler(), INBTSerializable<CompoundTag?> { open class BlockMatteryFluidHandler(private val _capacity: IntSupplier, field: Delegate<FluidStack>) : AbstractMatteryFluidHandler(), INBTSerializable<CompoundTag?> {
override var fluid by field override var fluid by field
override val capacity: Int override val capacity: Int

View File

@ -4,7 +4,7 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider
import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.FlowDirection
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.orNull import ru.dbotthepony.mc.otm.core.orNull
import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
import kotlin.math.roundToInt import kotlin.math.roundToInt

View File

@ -3,7 +3,7 @@ package ru.dbotthepony.mc.otm.capability.matter
import net.minecraft.world.item.Item import net.minecraft.world.item.Item
import net.minecraftforge.common.capabilities.ICapabilityProvider import net.minecraftforge.common.capabilities.ICapabilityProvider
import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.MatteryCapability
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.orNull import ru.dbotthepony.mc.otm.core.orNull
import java.util.* import java.util.*
import java.util.function.Predicate import java.util.function.Predicate

View File

@ -12,7 +12,7 @@ import ru.dbotthepony.mc.otm.capability.matteryPlayer
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.Widgets18 import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.client.render.is3DContext import ru.dbotthepony.mc.otm.client.render.is3DContext
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.network.ActivateAndroidFeaturePacket import ru.dbotthepony.mc.otm.network.ActivateAndroidFeaturePacket
import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel
import kotlin.math.roundToInt import kotlin.math.roundToInt

View File

@ -16,7 +16,7 @@ import ru.dbotthepony.mc.otm.capability.matteryPlayer
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.RenderGravity import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.render.drawArc import ru.dbotthepony.mc.otm.client.render.drawArc
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.angleDifference import ru.dbotthepony.mc.otm.core.math.angleDifference
import ru.dbotthepony.mc.otm.core.math.normalizeAngle import ru.dbotthepony.mc.otm.core.math.normalizeAngle
import ru.dbotthepony.mc.otm.core.util.formatTickDuration import ru.dbotthepony.mc.otm.core.util.formatTickDuration

View File

@ -31,7 +31,7 @@ import ru.dbotthepony.mc.otm.client.render.sprites.MatteryAtlas
import ru.dbotthepony.mc.otm.client.render.sprites.MatterySprite import ru.dbotthepony.mc.otm.client.render.sprites.MatterySprite
import ru.dbotthepony.mc.otm.config.ClientConfig import ru.dbotthepony.mc.otm.config.ClientConfig
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.util.formatPower import ru.dbotthepony.mc.otm.core.util.formatPower
import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.core.ifPresentK
import ru.dbotthepony.mc.otm.registry.AndroidFeatures import ru.dbotthepony.mc.otm.registry.AndroidFeatures

View File

@ -9,7 +9,7 @@ import net.minecraft.network.chat.Component
import net.minecraft.util.FormattedCharSequence import net.minecraft.util.FormattedCharSequence
import org.joml.Matrix4f import org.joml.Matrix4f
import ru.dbotthepony.mc.otm.core.FloatSupplier import ru.dbotthepony.mc.otm.core.FloatSupplier
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.component1 import ru.dbotthepony.mc.otm.core.math.component1
import ru.dbotthepony.mc.otm.core.math.component2 import ru.dbotthepony.mc.otm.core.math.component2
import ru.dbotthepony.mc.otm.core.math.component3 import ru.dbotthepony.mc.otm.core.math.component3

View File

@ -1,7 +1,7 @@
package ru.dbotthepony.mc.otm.client.render package ru.dbotthepony.mc.otm.client.render
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
interface IGUIRenderable { interface IGUIRenderable {
/** /**

View File

@ -10,7 +10,7 @@ import net.minecraft.resources.ResourceLocation
import net.minecraft.util.FormattedCharSequence import net.minecraft.util.FormattedCharSequence
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import kotlin.math.PI import kotlin.math.PI
import kotlin.math.roundToInt import kotlin.math.roundToInt

View File

@ -6,8 +6,8 @@ import com.mojang.blaze3d.vertex.VertexConsumer
import net.minecraft.core.Vec3i import net.minecraft.core.Vec3i
import org.joml.Matrix4f import org.joml.Matrix4f
import org.joml.Vector3f import org.joml.Vector3f
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.IAngle import ru.dbotthepony.mc.otm.core.math.IAngle
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.Vector import ru.dbotthepony.mc.otm.core.math.Vector
import ru.dbotthepony.mc.otm.core.math.rotateAroundPoint import ru.dbotthepony.mc.otm.core.math.rotateAroundPoint
import ru.dbotthepony.mc.otm.core.math.rotateAroundThis import ru.dbotthepony.mc.otm.core.math.rotateAroundThis

View File

@ -14,9 +14,9 @@ import org.apache.logging.log4j.LogManager
import org.joml.Matrix4f import org.joml.Matrix4f
import org.lwjgl.opengl.GL11.GL_ALWAYS import org.lwjgl.opengl.GL11.GL_ALWAYS
import org.lwjgl.opengl.GL11.GL_LESS import org.lwjgl.opengl.GL11.GL_LESS
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import java.util.* import java.util.*
import kotlin.collections.ArrayDeque import kotlin.collections.ArrayDeque
import kotlin.math.PI import kotlin.math.PI

View File

@ -22,18 +22,19 @@ import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
import ru.dbotthepony.mc.otm.core.immutableList import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.core.get import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.rotate import ru.dbotthepony.mc.otm.core.math.rotate
import ru.dbotthepony.mc.otm.core.math.rotateY import ru.dbotthepony.mc.otm.core.math.rotateY
import ru.dbotthepony.mc.otm.nanoTime import ru.dbotthepony.mc.otm.nanoTime
import java.util.function.BooleanSupplier import java.util.function.BooleanSupplier
import java.util.function.Supplier
import kotlin.math.PI import kotlin.math.PI
abstract class BankRenderer<T : MatteryDeviceBlockEntity>(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<T> { abstract class BankRenderer<T : MatteryDeviceBlockEntity>(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<T> {
protected abstract fun gaugeLevel(entity: T): Float protected abstract fun gaugeLevel(entity: T): Float
protected abstract val texture: AbstractMatterySprite protected abstract val texture: AbstractMatterySprite
protected abstract val models: List<BakedModel> protected abstract val models: List<BakedModel>
protected abstract fun status(entity: T): List<BooleanSupplier> protected abstract fun status(entity: T): List<Supplier<Boolean>>
private val random = XoroshiroRandomSource(nanoTime) private val random = XoroshiroRandomSource(nanoTime)
@ -53,7 +54,7 @@ abstract class BankRenderer<T : MatteryDeviceBlockEntity>(private val context: B
stack.translate(-0.5f, -0.5f, -0.5f) stack.translate(-0.5f, -0.5f, -0.5f)
for ((i, model) in models.withIndex()) { for ((i, model) in models.withIndex()) {
if (!status[i].asBoolean) { if (!status[i].get()) {
continue continue
} }
@ -124,7 +125,7 @@ class BatteryBankRenderer(context: BlockEntityRendererProvider.Context) : BankRe
} }
} }
override fun status(entity: BatteryBankBlockEntity): List<BooleanSupplier> { override fun status(entity: BatteryBankBlockEntity): List<Supplier<Boolean>> {
return entity.batteryStatus return entity.batteryStatus
} }
@ -151,7 +152,7 @@ class MatterBatteryBankRenderer(context: BlockEntityRendererProvider.Context) :
} }
} }
override fun status(entity: MatterCapacitorBankBlockEntity): List<BooleanSupplier> { override fun status(entity: MatterCapacitorBankBlockEntity): List<Supplier<Boolean>> {
return entity.capacitorStatus return entity.capacitorStatus
} }

View File

@ -18,7 +18,7 @@ import ru.dbotthepony.mc.otm.capability.matteryPlayer
import ru.dbotthepony.mc.otm.client.ShiftPressedCond import ru.dbotthepony.mc.otm.client.ShiftPressedCond
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.* import ru.dbotthepony.mc.otm.client.render.*
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.VECTOR_FORWARD import ru.dbotthepony.mc.otm.core.math.VECTOR_FORWARD
import ru.dbotthepony.mc.otm.core.math.VECTOR_RIGHT import ru.dbotthepony.mc.otm.core.math.VECTOR_RIGHT
import ru.dbotthepony.mc.otm.core.math.VECTOR_UP import ru.dbotthepony.mc.otm.core.math.VECTOR_UP

View File

@ -11,7 +11,7 @@ import ru.dbotthepony.mc.otm.block.entity.tech.EnergyCounterBlockEntity
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.* import ru.dbotthepony.mc.otm.client.render.*
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.asAngle import ru.dbotthepony.mc.otm.core.math.asAngle
import ru.dbotthepony.mc.otm.core.util.formatPower import ru.dbotthepony.mc.otm.core.util.formatPower
import ru.dbotthepony.mc.otm.core.math.times import ru.dbotthepony.mc.otm.core.math.times

View File

@ -19,7 +19,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler
import ru.dbotthepony.mc.otm.block.entity.decorative.FluidTankBlockEntity import ru.dbotthepony.mc.otm.block.entity.decorative.FluidTankBlockEntity
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.core.ifPresentK
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.linearInterpolation import ru.dbotthepony.mc.otm.core.math.linearInterpolation
import ru.dbotthepony.mc.otm.registry.MBlocks import ru.dbotthepony.mc.otm.registry.MBlocks

View File

@ -20,7 +20,7 @@ import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.* import ru.dbotthepony.mc.otm.client.render.*
import ru.dbotthepony.mc.otm.core.* import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.VECTOR_DOWN import ru.dbotthepony.mc.otm.core.math.VECTOR_DOWN
import ru.dbotthepony.mc.otm.core.math.VECTOR_FORWARD import ru.dbotthepony.mc.otm.core.math.VECTOR_FORWARD
import ru.dbotthepony.mc.otm.core.math.VECTOR_RIGHT import ru.dbotthepony.mc.otm.core.math.VECTOR_RIGHT

View File

@ -11,7 +11,7 @@ import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.render.draw import ru.dbotthepony.mc.otm.client.render.draw
import ru.dbotthepony.mc.otm.core.get import ru.dbotthepony.mc.otm.core.get
import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom import ru.dbotthepony.mc.otm.core.math.BlockRotationFreedom
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.rotateWithBlockFacing import ru.dbotthepony.mc.otm.core.math.rotateWithBlockFacing
class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<HoloSignBlockEntity> { class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<HoloSignBlockEntity> {

View File

@ -12,13 +12,13 @@ import net.minecraft.client.renderer.RenderType
import net.minecraft.network.FriendlyByteBuf import net.minecraft.network.FriendlyByteBuf
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
import org.lwjgl.opengl.GL11.GL_ALWAYS import org.lwjgl.opengl.GL11.GL_ALWAYS
import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.IGUIRenderable import ru.dbotthepony.mc.otm.client.render.IGUIRenderable
import ru.dbotthepony.mc.otm.client.render.IUVCoords import ru.dbotthepony.mc.otm.client.render.IUVCoords
import ru.dbotthepony.mc.otm.client.render.UVWindingOrder import ru.dbotthepony.mc.otm.client.render.UVWindingOrder
import ru.dbotthepony.mc.otm.client.render.color import ru.dbotthepony.mc.otm.client.render.color
import ru.dbotthepony.mc.otm.client.render.renderTexturedRect import ru.dbotthepony.mc.otm.client.render.renderTexturedRect
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.linearInterpolation import ru.dbotthepony.mc.otm.core.math.linearInterpolation
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap

View File

@ -16,6 +16,8 @@ import net.minecraftforge.client.event.ContainerScreenEvent.Render.Background
import net.minecraftforge.client.event.ContainerScreenEvent.Render.Foreground import net.minecraftforge.client.event.ContainerScreenEvent.Render.Foreground
import net.minecraftforge.common.MinecraftForge import net.minecraftforge.common.MinecraftForge
import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL11
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.capability.matteryPlayer import ru.dbotthepony.mc.otm.capability.matteryPlayer
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.moveMousePosScaled import ru.dbotthepony.mc.otm.client.moveMousePosScaled

View File

@ -14,7 +14,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.LargeRectangleButtonPan
import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls import ru.dbotthepony.mc.otm.client.screen.panels.button.makeDeviceControls
import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkedStringInputPanel import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkedStringInputPanel
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.menu.decorative.HoloSignMenu import ru.dbotthepony.mc.otm.menu.decorative.HoloSignMenu
import ru.dbotthepony.mc.otm.registry.MItems import ru.dbotthepony.mc.otm.registry.MItems

View File

@ -28,7 +28,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.util.ScrollableCanvasPanel
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.map import ru.dbotthepony.mc.otm.core.map
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.util.CreativeMenuItemComparator import ru.dbotthepony.mc.otm.core.util.CreativeMenuItemComparator
import ru.dbotthepony.mc.otm.menu.decorative.PainterMenu import ru.dbotthepony.mc.otm.menu.decorative.PainterMenu
@ -126,8 +126,8 @@ class PainterScreen(menu: PainterMenu, inventory: Inventory, title: Component) :
val buttons = ArrayList<RectangleButtonPanel<PainterScreen>>() val buttons = ArrayList<RectangleButtonPanel<PainterScreen>>()
menu.listeners.addListener { menu.listeners.addListener(Runnable {
if (frame.isRemoved) return@addListener if (frame.isRemoved) return@Runnable
buttons.forEach { it.remove() } buttons.forEach { it.remove() }
buttons.clear() buttons.clear()
@ -186,7 +186,7 @@ class PainterScreen(menu: PainterMenu, inventory: Inventory, title: Component) :
} }
} }
} }
} })
DeviceControls(this, frame, itemConfig = menu.itemConfig) DeviceControls(this, frame, itemConfig = menu.itemConfig)

View File

@ -21,8 +21,8 @@ import ru.dbotthepony.mc.otm.client.screen.panels.util.DiscreteScrollBarPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.ScrollBarConstants import ru.dbotthepony.mc.otm.client.screen.panels.util.ScrollBarConstants
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.asGetterSetter import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.core.math.integerDivisionDown import ru.dbotthepony.mc.otm.core.math.integerDivisionDown
import ru.dbotthepony.mc.otm.core.util.ItemSorter import ru.dbotthepony.mc.otm.core.util.ItemSorter
import ru.dbotthepony.mc.otm.core.util.formatMatter import ru.dbotthepony.mc.otm.core.util.formatMatter
@ -55,7 +55,7 @@ class MatterPanelScreen(
val controls = DeviceControls(this, frame) val controls = DeviceControls(this, frame)
controls.sortingButtons(menu.settings::isAscending.asGetterSetter(), menu.settings::sorting.asGetterSetter(), ItemSorter.DEFAULT) { controls.sortingButtons(Delegate.Of(menu.settings::isAscending), Delegate.Of(menu.settings::sorting), ItemSorter.DEFAULT) {
for (v in ItemSorter.entries) { for (v in ItemSorter.entries) {
add(v, skinElement = v.icon, tooltip = v.title) add(v, skinElement = v.icon, tooltip = v.title)
} }
@ -65,7 +65,7 @@ class MatterPanelScreen(
LargeBooleanRectangleButtonPanel( LargeBooleanRectangleButtonPanel(
this, this,
frame, frame,
prop = menu::isProvidingTasks.asGetterSetter(), prop = Delegate.Of(menu::isProvidingTasks),
iconActive = Widgets18.PLAY, iconActive = Widgets18.PLAY,
iconInactive = Widgets18.PAUSE, iconInactive = Widgets18.PAUSE,
tooltipActive = TranslatableComponent("otm.gui.matter_panel.is_providing_tasks"), tooltipActive = TranslatableComponent("otm.gui.matter_panel.is_providing_tasks"),

View File

@ -6,6 +6,7 @@ import it.unimi.dsi.fastutil.floats.FloatConsumer
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
import ru.dbotthepony.kommons.math.HSVColor
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.client.CursorType import ru.dbotthepony.mc.otm.client.CursorType
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
@ -19,8 +20,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.AbstractButtonPanel
import ru.dbotthepony.mc.otm.client.screen.panels.input.TextInputPanel import ru.dbotthepony.mc.otm.client.screen.panels.input.TextInputPanel
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.HSVColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import java.util.function.Consumer import java.util.function.Consumer
import java.util.function.Supplier import java.util.function.Supplier
import kotlin.math.roundToInt import kotlin.math.roundToInt

View File

@ -14,7 +14,7 @@ import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.render.determineTooltipPosition import ru.dbotthepony.mc.otm.client.render.determineTooltipPosition
import ru.dbotthepony.mc.otm.client.render.sprites.sprite import ru.dbotthepony.mc.otm.client.render.sprites.sprite
import ru.dbotthepony.mc.otm.client.screen.panels.util.DiscreteScrollBarPanel import ru.dbotthepony.mc.otm.client.screen.panels.util.DiscreteScrollBarPanel
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.util.formatTickDuration import ru.dbotthepony.mc.otm.core.util.formatTickDuration
import ru.dbotthepony.mc.otm.core.math.integerDivisionDown import ru.dbotthepony.mc.otm.core.math.integerDivisionDown

View File

@ -18,9 +18,9 @@ import ru.dbotthepony.mc.otm.client.screen.panels.button.SmallBooleanRectangleBu
import ru.dbotthepony.mc.otm.client.screen.panels.button.SmallRectangleButtonPanel import ru.dbotthepony.mc.otm.client.screen.panels.button.SmallRectangleButtonPanel
import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleRenderButton import ru.dbotthepony.mc.otm.compat.cos.CosmeticToggleRenderButton
import ru.dbotthepony.mc.otm.compat.cos.isCosmeticArmorLoaded import ru.dbotthepony.mc.otm.compat.cos.isCosmeticArmorLoaded
import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.network.DisableExopackGlowPacket import ru.dbotthepony.mc.otm.network.DisableExopackGlowPacket
import ru.dbotthepony.mc.otm.network.DisplayExopackPacket import ru.dbotthepony.mc.otm.network.DisplayExopackPacket
import ru.dbotthepony.mc.otm.network.EnableExopackGlowPacket import ru.dbotthepony.mc.otm.network.EnableExopackGlowPacket
@ -57,7 +57,7 @@ private fun createExopackAppearanceWindow(screen: MatteryScreen<*>, matteryPlaye
screen, screen,
frame, frame,
text = TranslatableComponent("otm.gui.exopack.toggle_visibility"), text = TranslatableComponent("otm.gui.exopack.toggle_visibility"),
isChecked = GetterSetter.of( isChecked = Delegate.Of(
{ {
matteryPlayer.isExopackVisible matteryPlayer.isExopackVisible
}, },
@ -78,7 +78,7 @@ private fun createExopackAppearanceWindow(screen: MatteryScreen<*>, matteryPlaye
screen, screen,
frame, frame,
text = TranslatableComponent("otm.gui.exopack.toggle_glow"), text = TranslatableComponent("otm.gui.exopack.toggle_glow"),
isChecked = GetterSetter.of( isChecked = Delegate.Of(
{ {
matteryPlayer.exopackGlows matteryPlayer.exopackGlows
}, },

View File

@ -13,7 +13,7 @@ import ru.dbotthepony.mc.otm.client.render.*
import ru.dbotthepony.mc.otm.client.render.sprites.StretchingRectangleElement import ru.dbotthepony.mc.otm.client.render.sprites.StretchingRectangleElement
import ru.dbotthepony.mc.otm.client.screen.panels.button.AbstractButtonPanel import ru.dbotthepony.mc.otm.client.screen.panels.button.AbstractButtonPanel
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
open class FramePanel<out S : Screen>( open class FramePanel<out S : Screen>(
screen: S, screen: S,

View File

@ -5,7 +5,7 @@ import net.minecraft.network.chat.Component
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.RenderGravity import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
open class Label<out S : Screen> @JvmOverloads constructor( open class Label<out S : Screen> @JvmOverloads constructor(
screen: S, screen: S,

View File

@ -3,14 +3,14 @@ package ru.dbotthepony.mc.otm.client.screen.panels.button
import net.minecraft.ChatFormatting import net.minecraft.ChatFormatting
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.kommons.util.value
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.IGUIRenderable import ru.dbotthepony.mc.otm.client.render.IGUIRenderable
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.value
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
abstract class BooleanRectangleButtonPanel<out S : Screen>( abstract class BooleanRectangleButtonPanel<out S : Screen>(
@ -20,7 +20,7 @@ abstract class BooleanRectangleButtonPanel<out S : Screen>(
y: Float = 0f, y: Float = 0f,
width: Float, width: Float,
height: Float, height: Float,
val prop: GetterSetter<Boolean>, val prop: Delegate<Boolean>,
var iconActive: IGUIRenderable? = null, var iconActive: IGUIRenderable? = null,
var iconInactive: IGUIRenderable? = null, var iconInactive: IGUIRenderable? = null,
val onChange: ((newValue: Boolean) -> Unit)? = null, val onChange: ((newValue: Boolean) -> Unit)? = null,

View File

@ -6,7 +6,7 @@ import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.RenderGravity import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.render.Widgets18 import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import java.util.function.IntConsumer import java.util.function.IntConsumer
open class ButtonPanel<out S : Screen>( open class ButtonPanel<out S : Screen>(

View File

@ -5,6 +5,8 @@ import net.minecraft.ChatFormatting
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items import net.minecraft.world.item.Items
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.kommons.util.value
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
import ru.dbotthepony.mc.otm.capability.FlowDirection import ru.dbotthepony.mc.otm.capability.FlowDirection
@ -24,14 +26,11 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel
import ru.dbotthepony.mc.otm.config.ClientConfig import ru.dbotthepony.mc.otm.config.ClientConfig
import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.asGetterSetter
import ru.dbotthepony.mc.otm.core.immutableList import ru.dbotthepony.mc.otm.core.immutableList
import ru.dbotthepony.mc.otm.core.math.RelativeSide import ru.dbotthepony.mc.otm.core.math.RelativeSide
import ru.dbotthepony.mc.otm.core.util.ItemStackSorter import ru.dbotthepony.mc.otm.core.util.ItemStackSorter
import ru.dbotthepony.mc.otm.core.value
import ru.dbotthepony.mc.otm.menu.MatteryMenu import ru.dbotthepony.mc.otm.menu.MatteryMenu
import ru.dbotthepony.mc.otm.menu.UpgradeSlots import ru.dbotthepony.mc.otm.menu.UpgradeSlots
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
@ -78,7 +77,7 @@ private class PullPushButton<out S : MatteryScreen<*>, T : Enum<T>>(
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
enum: Class<T>, enum: Class<T>,
prop: GetterSetter<T>, prop: Delegate<T>,
defaultValue: T, defaultValue: T,
val pullProp: BooleanInputWithFeedback, val pullProp: BooleanInputWithFeedback,
val pushProp: BooleanInputWithFeedback val pushProp: BooleanInputWithFeedback
@ -372,7 +371,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
alignButtons() alignButtons()
} }
fun addStorageMode(prop: GetterSetter<FlowDirection>) { fun addStorageMode(prop: Delegate<FlowDirection>) {
val mode = LargeEnumRectangleButtonPanel(screen, this, prop = prop, defaultValue = FlowDirection.BI_DIRECTIONAL, enum = FlowDirection::class.java) val mode = LargeEnumRectangleButtonPanel(screen, this, prop = prop, defaultValue = FlowDirection.BI_DIRECTIONAL, enum = FlowDirection::class.java)
mode.add(FlowDirection.INPUT, Widgets18.ONLY_STORE, FlowDirection.INPUT.title) mode.add(FlowDirection.INPUT, Widgets18.ONLY_STORE, FlowDirection.INPUT.title)
@ -383,7 +382,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
addButton(mode) addButton(mode)
} }
inline fun <reified T : Enum<T>> sortingButtons(ascending: GetterSetter<Boolean>, sorting: GetterSetter<T>, default: T, configurator: LargeEnumRectangleButtonPanel<S, T>.() -> Unit): List<EditablePanel<S>> { inline fun <reified T : Enum<T>> sortingButtons(ascending: Delegate<Boolean>, sorting: Delegate<T>, default: T, configurator: LargeEnumRectangleButtonPanel<S, T>.() -> Unit): List<EditablePanel<S>> {
val result = ArrayList<EditablePanel<S>>() val result = ArrayList<EditablePanel<S>>()
LargeBooleanRectangleButtonPanel( LargeBooleanRectangleButtonPanel(
@ -439,7 +438,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
set(value) {} set(value) {}
private fun makeButtons() { private fun makeButtons() {
buttons = sortingButtons(input.settings::isAscending.asGetterSetter(), input.settings::sorting.asGetterSetter(), ItemStackSorter.DEFAULT) { buttons = sortingButtons(Delegate.Of(input.settings::isAscending), Delegate.Of(input.settings::sorting), ItemStackSorter.DEFAULT) {
for (v in ItemStackSorter.entries) { for (v in ItemStackSorter.entries) {
add(v, v.icon, v.title) add(v, v.icon, v.title)
} }

View File

@ -1,11 +1,8 @@
package ru.dbotthepony.mc.otm.client.screen.panels.button package ru.dbotthepony.mc.otm.client.screen.panels.button
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import net.minecraft.world.entity.player.Player
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.core.value
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
open class CheckBoxInputPanel<out S : Screen>( open class CheckBoxInputPanel<out S : Screen>(

View File

@ -2,9 +2,9 @@ package ru.dbotthepony.mc.otm.client.screen.panels.button
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.client.screen.panels.Label import ru.dbotthepony.mc.otm.client.screen.panels.Label
import ru.dbotthepony.mc.otm.core.GetterSetter
open class CheckBoxLabelPanel<out S : Screen>( open class CheckBoxLabelPanel<out S : Screen>(
screen: S, screen: S,
@ -14,7 +14,7 @@ open class CheckBoxLabelPanel<out S : Screen>(
y: Float = 0f, y: Float = 0f,
width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f, width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f,
height: Float = CheckBoxPanel.REGULAR_DIMENSIONS, height: Float = CheckBoxPanel.REGULAR_DIMENSIONS,
isChecked: GetterSetter<Boolean> = GetterSetter.box(false) isChecked: Delegate<Boolean> = Delegate.Box(false)
) : AbstractCheckBoxLabelPanel<S>(screen, parent, x, y, width, height) { ) : AbstractCheckBoxLabelPanel<S>(screen, parent, x, y, width, height) {
override val checkbox = CheckBoxPanel(screen, this, 0f, 0f, isChecked = isChecked) override val checkbox = CheckBoxPanel(screen, this, 0f, 0f, isChecked = isChecked)
override val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text) override val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text)

View File

@ -1,11 +1,11 @@
package ru.dbotthepony.mc.otm.client.screen.panels.button package ru.dbotthepony.mc.otm.client.screen.panels.button
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.sprites.AbstractMatterySprite import ru.dbotthepony.mc.otm.client.render.sprites.AbstractMatterySprite
import ru.dbotthepony.mc.otm.client.render.WidgetLocation import ru.dbotthepony.mc.otm.client.render.WidgetLocation
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.GetterSetter
open class CheckBoxPanel<out S : Screen>( open class CheckBoxPanel<out S : Screen>(
screen: S, screen: S,
@ -14,7 +14,7 @@ open class CheckBoxPanel<out S : Screen>(
y: Float = 0f, y: Float = 0f,
width: Float = REGULAR_DIMENSIONS, width: Float = REGULAR_DIMENSIONS,
height: Float = REGULAR_DIMENSIONS, height: Float = REGULAR_DIMENSIONS,
open val isChecked: GetterSetter<Boolean> = GetterSetter.box(false) open val isChecked: Delegate<Boolean> = Delegate.Box(false)
) : AbstractButtonPanel<S>(screen, parent, x, y, width, height) { ) : AbstractButtonPanel<S>(screen, parent, x, y, width, height) {
open val IDLE_UNCHECKED: AbstractMatterySprite = Companion.IDLE_UNCHECKED open val IDLE_UNCHECKED: AbstractMatterySprite = Companion.IDLE_UNCHECKED
open val IDLE_CHECKED: AbstractMatterySprite = Companion.IDLE_CHECKED open val IDLE_CHECKED: AbstractMatterySprite = Companion.IDLE_CHECKED

View File

@ -4,13 +4,15 @@ import com.mojang.blaze3d.platform.InputConstants
import net.minecraft.ChatFormatting import net.minecraft.ChatFormatting
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import ru.dbotthepony.kommons.io.StreamCodec
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.kommons.util.value
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.IGUIRenderable import ru.dbotthepony.mc.otm.client.render.IGUIRenderable
import ru.dbotthepony.mc.otm.client.render.UVWindingOrder import ru.dbotthepony.mc.otm.client.render.UVWindingOrder
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.* import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.core.util.EnumValueCodec
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
import java.util.* import java.util.*
import java.util.function.Predicate import java.util.function.Predicate
@ -24,10 +26,10 @@ abstract class EnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
width: Float, width: Float,
height: Float, height: Float,
enum: Class<T>, enum: Class<T>,
val prop: GetterSetter<T>, val prop: Delegate<T>,
val defaultValue: T, val defaultValue: T,
) : RectangleButtonPanel<S>(screen, parent, x, y, width, height, null) { ) : RectangleButtonPanel<S>(screen, parent, x, y, width, height, null) {
val enum = EnumValueCodec.searchClass(enum) val enum = StreamCodec.Enum.searchClass(enum)
private val constants: Array<T> = enum.enumConstants private val constants: Array<T> = enum.enumConstants
private var isBuilding = true private var isBuilding = true
var predicate: Predicate<T> = Predicate { true } var predicate: Predicate<T> = Predicate { true }

View File

@ -2,10 +2,10 @@ package ru.dbotthepony.mc.otm.client.screen.panels.button
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.client.render.IGUIRenderable import ru.dbotthepony.mc.otm.client.render.IGUIRenderable
import ru.dbotthepony.mc.otm.client.render.Widgets18 import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.GetterSetter
open class LargeBooleanRectangleButtonPanel<out S : Screen>( open class LargeBooleanRectangleButtonPanel<out S : Screen>(
screen: S, screen: S,
@ -14,7 +14,7 @@ open class LargeBooleanRectangleButtonPanel<out S : Screen>(
y: Float = 0f, y: Float = 0f,
width: Float = SIZE, width: Float = SIZE,
height: Float = SIZE, height: Float = SIZE,
prop: GetterSetter<Boolean>, prop: Delegate<Boolean>,
iconActive: IGUIRenderable? = null, iconActive: IGUIRenderable? = null,
iconInactive: IGUIRenderable? = null, iconInactive: IGUIRenderable? = null,
onChange: ((newValue: Boolean) -> Unit)? = null, onChange: ((newValue: Boolean) -> Unit)? = null,

View File

@ -1,11 +1,9 @@
package ru.dbotthepony.mc.otm.client.screen.panels.button package ru.dbotthepony.mc.otm.client.screen.panels.button
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.client.render.Widgets18 import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
open class LargeEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>( open class LargeEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
screen: S, screen: S,
@ -15,7 +13,7 @@ open class LargeEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
width: Float = SIZE, width: Float = SIZE,
height: Float = SIZE, height: Float = SIZE,
enum: Class<T>, enum: Class<T>,
prop: GetterSetter<T>, prop: Delegate<T>,
defaultValue: T, defaultValue: T,
) : EnumRectangleButtonPanel<S, T>(screen, parent, x, y, width, height, enum, prop, defaultValue) { ) : EnumRectangleButtonPanel<S, T>(screen, parent, x, y, width, height, enum, prop, defaultValue) {
final override val IDLE = Widgets18.BUTTON_IDLE final override val IDLE = Widgets18.BUTTON_IDLE

View File

@ -7,7 +7,7 @@ import ru.dbotthepony.mc.otm.client.render.IGUIRenderable
import ru.dbotthepony.mc.otm.client.render.UVWindingOrder import ru.dbotthepony.mc.otm.client.render.UVWindingOrder
import ru.dbotthepony.mc.otm.client.render.Widgets18 import ru.dbotthepony.mc.otm.client.render.Widgets18
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.menu.MatteryMenu import ru.dbotthepony.mc.otm.menu.MatteryMenu
open class LargeRectangleButtonPanel<out S : Screen>( open class LargeRectangleButtonPanel<out S : Screen>(

View File

@ -1,10 +1,10 @@
package ru.dbotthepony.mc.otm.client.screen.panels.button package ru.dbotthepony.mc.otm.client.screen.panels.button
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.client.render.* import ru.dbotthepony.mc.otm.client.render.*
import ru.dbotthepony.mc.otm.client.render.sprites.AbstractMatterySprite import ru.dbotthepony.mc.otm.client.render.sprites.AbstractMatterySprite
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.GetterSetter
open class SmallBooleanRectangleButtonPanel<out S : Screen>( open class SmallBooleanRectangleButtonPanel<out S : Screen>(
screen: S, screen: S,
@ -13,7 +13,7 @@ open class SmallBooleanRectangleButtonPanel<out S : Screen>(
y: Float = 0f, y: Float = 0f,
width: Float = SIZE, width: Float = SIZE,
height: Float = SIZE, height: Float = SIZE,
prop: GetterSetter<Boolean>, prop: Delegate<Boolean>,
skinElementActive: AbstractMatterySprite? = null, skinElementActive: AbstractMatterySprite? = null,
skinElementInactive: AbstractMatterySprite? = null, skinElementInactive: AbstractMatterySprite? = null,
onChange: ((newValue: Boolean) -> Unit)? = null, onChange: ((newValue: Boolean) -> Unit)? = null,

View File

@ -1,9 +1,9 @@
package ru.dbotthepony.mc.otm.client.screen.panels.button package ru.dbotthepony.mc.otm.client.screen.panels.button
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.client.render.Widgets8 import ru.dbotthepony.mc.otm.client.render.Widgets8
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.GetterSetter
open class SmallEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>( open class SmallEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
screen: S, screen: S,
@ -13,7 +13,7 @@ open class SmallEnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
width: Float = SIZE, width: Float = SIZE,
height: Float = SIZE, height: Float = SIZE,
enum: Class<T>, enum: Class<T>,
prop: GetterSetter<T>, prop: Delegate<T>,
defaultValue: T, defaultValue: T,
) : EnumRectangleButtonPanel<S, T>(screen, parent, x, y, width, height, enum, prop, defaultValue) { ) : EnumRectangleButtonPanel<S, T>(screen, parent, x, y, width, height, enum, prop, defaultValue) {
final override val IDLE = Widgets8.BUTTON_IDLE final override val IDLE = Widgets8.BUTTON_IDLE

View File

@ -6,6 +6,7 @@ import ru.dbotthepony.mc.otm.client.CursorType
import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.menu.MatteryMenu import ru.dbotthepony.mc.otm.menu.MatteryMenu
import java.math.BigDecimal import java.math.BigDecimal
import java.util.function.BooleanSupplier import java.util.function.BooleanSupplier
@ -13,8 +14,8 @@ import java.util.function.BooleanSupplier
open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor( open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor(
screen: S, screen: S,
parent: EditablePanel<*>?, parent: EditablePanel<*>?,
val networkValue: () -> BigDecimal, val networkValue: () -> Decimal,
val callback: (BigDecimal) -> Unit, val callback: (Decimal) -> Unit,
val isEnabled: BooleanSupplier = BooleanSupplier { true }, val isEnabled: BooleanSupplier = BooleanSupplier { true },
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
@ -25,8 +26,8 @@ open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor(
constructor( constructor(
screen: S, screen: S,
parent: EditablePanel<*>?, parent: EditablePanel<*>?,
widget: MatteryMenu.PlayerInput<BigDecimal>, widget: MatteryMenu.PlayerInput<Decimal>,
networkValue: () -> BigDecimal, networkValue: () -> Decimal,
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
width: Float = 0f, width: Float = 0f,
@ -69,14 +70,14 @@ open class NetworkNumberInputPanel<out S : Screen> @JvmOverloads constructor(
} }
if (nextUpdateFromServer < System.currentTimeMillis()) { if (nextUpdateFromServer < System.currentTimeMillis()) {
getOrCreateWidget().value = networkValue.invoke().toPlainString() getOrCreateWidget().value = networkValue.invoke().toString()
inputStr = getOrCreateWidget().value inputStr = getOrCreateWidget().value
} else if (isEnabled.asBoolean) { } else if (isEnabled.asBoolean) {
if (inputStr != getOrCreateWidget().value) { if (inputStr != getOrCreateWidget().value) {
inputStr = getOrCreateWidget().value inputStr = getOrCreateWidget().value
try { try {
callback.invoke(BigDecimal(inputStr)) callback.invoke(Decimal(inputStr))
} catch (_: Throwable) { } } catch (_: Throwable) { }
} }
} }

View File

@ -2,19 +2,19 @@ package ru.dbotthepony.mc.otm.client.screen.panels.input
import com.mojang.blaze3d.platform.InputConstants import com.mojang.blaze3d.platform.InputConstants
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.client.render.Widgets import ru.dbotthepony.mc.otm.client.render.Widgets
import ru.dbotthepony.mc.otm.client.screen.panels.Dock import ru.dbotthepony.mc.otm.client.screen.panels.Dock
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.client.screen.panels.button.RectangleButtonPanel import ru.dbotthepony.mc.otm.client.screen.panels.button.RectangleButtonPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.HeightControls import ru.dbotthepony.mc.otm.client.screen.panels.util.HeightControls
import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
abstract class NumberInputPanel<out S : Screen, N : Number>( abstract class NumberInputPanel<out S : Screen, N : Number>(
screen: S, screen: S,
parent: EditablePanel<*>, parent: EditablePanel<*>,
val prop: GetterSetter<N>, val prop: Delegate<N>,
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
width: Float = WIDTH, width: Float = WIDTH,
@ -129,7 +129,7 @@ abstract class NumberInputPanel<out S : Screen, N : Number>(
abstract class LNumberInputPanel<out S : Screen, N : Number>( abstract class LNumberInputPanel<out S : Screen, N : Number>(
screen: S, screen: S,
parent: EditablePanel<*>, parent: EditablePanel<*>,
prop: GetterSetter<N>, prop: Delegate<N>,
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
width: Float = WIDTH, width: Float = WIDTH,
@ -157,7 +157,7 @@ abstract class LNumberInputPanel<out S : Screen, N : Number>(
open class IntInputPanel<out S : Screen>( open class IntInputPanel<out S : Screen>(
screen: S, screen: S,
parent: EditablePanel<*>, parent: EditablePanel<*>,
prop: GetterSetter<Int>, prop: Delegate<Int>,
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
width: Float = WIDTH, width: Float = WIDTH,
@ -185,7 +185,7 @@ open class IntInputPanel<out S : Screen>(
open class DecimalInputPanel<out S : Screen>( open class DecimalInputPanel<out S : Screen>(
screen: S, screen: S,
parent: EditablePanel<*>, parent: EditablePanel<*>,
prop: GetterSetter<Decimal>, prop: Delegate<Decimal>,
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
width: Float = WIDTH, width: Float = WIDTH,

View File

@ -28,7 +28,7 @@ import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.addAll import ru.dbotthepony.mc.otm.core.addAll
import ru.dbotthepony.mc.otm.core.collect.map import ru.dbotthepony.mc.otm.core.collect.map
import ru.dbotthepony.mc.otm.core.collect.reduce import ru.dbotthepony.mc.otm.core.collect.reduce
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.milliTime import ru.dbotthepony.mc.otm.milliTime
import java.util.function.Predicate import java.util.function.Predicate
import kotlin.math.roundToInt import kotlin.math.roundToInt

View File

@ -11,7 +11,7 @@ import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.render.WidgetLocation import ru.dbotthepony.mc.otm.client.render.WidgetLocation
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
abstract class AbstractSlotPanel<out S : MatteryScreen<*>>( abstract class AbstractSlotPanel<out S : MatteryScreen<*>>(
screen: S, screen: S,

View File

@ -1,14 +1,14 @@
package ru.dbotthepony.mc.otm.client.screen.panels.slot package ru.dbotthepony.mc.otm.client.screen.panels.slot
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.GetterSetter
open class FilterSlotPanel<out S : MatteryScreen<*>> @JvmOverloads constructor( open class FilterSlotPanel<out S : MatteryScreen<*>> @JvmOverloads constructor(
screen: S, screen: S,
parent: EditablePanel<*>?, parent: EditablePanel<*>?,
val slot: GetterSetter<ItemStack>, val slot: Delegate<ItemStack>,
x: Float = 0f, x: Float = 0f,
y: Float = 0f, y: Float = 0f,
width: Float = SIZE, width: Float = SIZE,

View File

@ -14,10 +14,12 @@ import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.playGuiClickSound import ru.dbotthepony.mc.otm.client.playGuiClickSound
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.menu.UserFilteredSlot import ru.dbotthepony.mc.otm.menu.UserFilteredSlot
abstract class UserFilteredSlotPanel<out S : MatteryScreen<*>, out T : Slot>( abstract class UserFilteredSlotPanel<out S : MatteryScreen<*>, out T : Slot>(
@ -122,7 +124,7 @@ abstract class UserFilteredSlotPanel<out S : MatteryScreen<*>, out T : Slot>(
y: Float = 0f, y: Float = 0f,
width: Float = SIZE, width: Float = SIZE,
height: Float = SIZE, height: Float = SIZE,
filter: GetterSetter<Item?> filter: Delegate<Item?>
): UserFilteredSlotPanel<S, T> { ): UserFilteredSlotPanel<S, T> {
return object : UserFilteredSlotPanel<S, T>(screen, parent, slot, x, y, width, height) { return object : UserFilteredSlotPanel<S, T>(screen, parent, slot, x, y, width, height) {
override var slotFilter: Item? by filter override var slotFilter: Item? by filter

View File

@ -4,6 +4,7 @@ import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items import net.minecraft.world.item.Items
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.client.render.ItemStackIcon import ru.dbotthepony.mc.otm.client.render.ItemStackIcon
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
@ -16,7 +17,6 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.FilterSlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.slot.SlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel
import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel
import ru.dbotthepony.mc.otm.core.asGetterSetter
import ru.dbotthepony.mc.otm.core.util.ItemStorageStackSorter import ru.dbotthepony.mc.otm.core.util.ItemStorageStackSorter
import ru.dbotthepony.mc.otm.item.PortableCondensationDriveItem import ru.dbotthepony.mc.otm.item.PortableCondensationDriveItem
import ru.dbotthepony.mc.otm.menu.storage.DriveViewerMenu import ru.dbotthepony.mc.otm.menu.storage.DriveViewerMenu
@ -35,7 +35,7 @@ class DriveViewerScreen(menu: DriveViewerMenu, inventory: Inventory, title: Comp
val controls = DeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, energyConfig = menu.energyConfig) val controls = DeviceControls(this, frame, redstoneConfig = menu.redstoneConfig, energyConfig = menu.energyConfig)
controls.sortingButtons(menu.settings::isAscending.asGetterSetter(), menu.settings::sorting.asGetterSetter(), ItemStorageStackSorter.DEFAULT) { controls.sortingButtons(Delegate.Of(menu.settings::isAscending), Delegate.Of(menu.settings::sorting), ItemStorageStackSorter.DEFAULT) {
for (v in ItemStorageStackSorter.entries) { for (v in ItemStorageStackSorter.entries) {
add(v, v.icon, v.title) add(v, v.icon, v.title)
} }

View File

@ -4,6 +4,7 @@ import net.minecraft.network.chat.Component
import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items import net.minecraft.world.item.Items
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.mc.otm.block.entity.storage.ItemMonitorPlayerSettings import ru.dbotthepony.mc.otm.block.entity.storage.ItemMonitorPlayerSettings
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
@ -23,7 +24,6 @@ import ru.dbotthepony.mc.otm.client.screen.panels.util.GridPanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.asGetterSetter
import ru.dbotthepony.mc.otm.core.util.ItemStorageStackSorter import ru.dbotthepony.mc.otm.core.util.ItemStorageStackSorter
import ru.dbotthepony.mc.otm.menu.storage.ItemMonitorMenu import ru.dbotthepony.mc.otm.menu.storage.ItemMonitorMenu
import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak import yalter.mousetweaks.api.MouseTweaksDisableWheelTweak
@ -52,7 +52,7 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
val controls = DeviceControls(this, frame) val controls = DeviceControls(this, frame)
controls.sortingButtons(menu.settings::ascendingSort.asGetterSetter(), menu.settings::sorting.asGetterSetter(), ItemStorageStackSorter.DEFAULT) { controls.sortingButtons(Delegate.Of(menu.settings::ascendingSort), Delegate.Of(menu.settings::sorting), ItemStorageStackSorter.DEFAULT) {
for (v in ItemStorageStackSorter.entries) { for (v in ItemStorageStackSorter.entries) {
add(v, skinElement = v.icon, tooltip = v.title) add(v, skinElement = v.icon, tooltip = v.title)
} }
@ -83,7 +83,7 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
SmallEnumRectangleButtonPanel(this, arrowLine, SmallEnumRectangleButtonPanel(this, arrowLine,
enum = ItemMonitorPlayerSettings.IngredientPriority::class.java, enum = ItemMonitorPlayerSettings.IngredientPriority::class.java,
prop = menu.settings::ingredientPriority.asGetterSetter(), prop = Delegate.Of(menu.settings::ingredientPriority),
defaultValue = ItemMonitorPlayerSettings.IngredientPriority.SYSTEM) defaultValue = ItemMonitorPlayerSettings.IngredientPriority.SYSTEM)
.also { .also {
it.tooltips.add(TranslatableComponent("otm.gui.item_monitor.refill_source.desc")) it.tooltips.add(TranslatableComponent("otm.gui.item_monitor.refill_source.desc"))
@ -104,7 +104,7 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
SmallEnumRectangleButtonPanel(this, resultAndButtons, y = 38f, SmallEnumRectangleButtonPanel(this, resultAndButtons, y = 38f,
enum = ItemMonitorPlayerSettings.ResultTarget::class.java, enum = ItemMonitorPlayerSettings.ResultTarget::class.java,
prop = menu.settings::resultTarget.asGetterSetter(), prop = Delegate.Of(menu.settings::resultTarget),
defaultValue = ItemMonitorPlayerSettings.ResultTarget.MIXED) defaultValue = ItemMonitorPlayerSettings.ResultTarget.MIXED)
.also { .also {
it.tooltips.add(TranslatableComponent("otm.gui.item_monitor.result_target.desc")) it.tooltips.add(TranslatableComponent("otm.gui.item_monitor.result_target.desc"))
@ -116,7 +116,7 @@ class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Comp
SmallEnumRectangleButtonPanel(this, resultAndButtons, x = 10f, y = 38f, SmallEnumRectangleButtonPanel(this, resultAndButtons, x = 10f, y = 38f,
enum = ItemMonitorPlayerSettings.Amount::class.java, enum = ItemMonitorPlayerSettings.Amount::class.java,
prop = menu.settings::craftingAmount.asGetterSetter(), prop = Delegate.Of(menu.settings::craftingAmount),
defaultValue = ItemMonitorPlayerSettings.Amount.STACK) defaultValue = ItemMonitorPlayerSettings.Amount.STACK)
.also { .also {
it.tooltips.add(TranslatableComponent("otm.gui.item_monitor.amount.desc")) it.tooltips.add(TranslatableComponent("otm.gui.item_monitor.amount.desc"))

View File

@ -31,7 +31,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.slot.EquipmentBatterySlotPanel
import ru.dbotthepony.mc.otm.client.screen.panels.util.DraggableCanvasPanel import ru.dbotthepony.mc.otm.client.screen.panels.util.DraggableCanvasPanel
import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.WideProfiledPowerGaugePanel
import ru.dbotthepony.mc.otm.config.MachinesConfig import ru.dbotthepony.mc.otm.config.MachinesConfig
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.core.ifPresentK
import ru.dbotthepony.mc.otm.menu.tech.AndroidStationMenu import ru.dbotthepony.mc.otm.menu.tech.AndroidStationMenu
import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel

View File

@ -22,7 +22,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.isNotEmpty import ru.dbotthepony.mc.otm.core.isNotEmpty
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.linearInterpolation import ru.dbotthepony.mc.otm.core.math.linearInterpolation
import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.core.util.formatFluidLevel import ru.dbotthepony.mc.otm.core.util.formatFluidLevel

View File

@ -10,6 +10,7 @@ import net.minecraft.client.gui.screens.Screen
import net.minecraft.client.renderer.GameRenderer import net.minecraft.client.renderer.GameRenderer
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL11
import ru.dbotthepony.kommons.util.value
import ru.dbotthepony.mc.otm.capability.AbstractProfiledStorage import ru.dbotthepony.mc.otm.capability.AbstractProfiledStorage
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.ShiftPressedCond import ru.dbotthepony.mc.otm.client.ShiftPressedCond

View File

@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.ints.IntArrayList
import net.minecraft.ChatFormatting import net.minecraft.ChatFormatting
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import ru.dbotthepony.kommons.util.value
import ru.dbotthepony.mc.otm.capability.AbstractProfiledStorage import ru.dbotthepony.mc.otm.capability.AbstractProfiledStorage
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
import ru.dbotthepony.mc.otm.client.ShiftPressedCond import ru.dbotthepony.mc.otm.client.ShiftPressedCond

View File

@ -2,7 +2,7 @@ package ru.dbotthepony.mc.otm.compat.jade
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
import ru.dbotthepony.mc.otm.OverdriveThatMatters.loc import ru.dbotthepony.mc.otm.OverdriveThatMatters.loc
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
object JadeUids { object JadeUids {
val MATTERY_ENERGY: ResourceLocation = loc("mattery_energy") val MATTERY_ENERGY: ResourceLocation = loc("mattery_energy")

View File

@ -7,7 +7,7 @@ import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity
import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys
import ru.dbotthepony.mc.otm.compat.jade.JadeUids import ru.dbotthepony.mc.otm.compat.jade.JadeUids
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import snownee.jade.api.BlockAccessor import snownee.jade.api.BlockAccessor
import snownee.jade.api.IBlockComponentProvider import snownee.jade.api.IBlockComponentProvider
import snownee.jade.api.IServerDataProvider import snownee.jade.api.IServerDataProvider

View File

@ -6,7 +6,7 @@ import ru.dbotthepony.mc.otm.block.entity.matter.MatterReconstructorBlockEntity
import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys
import ru.dbotthepony.mc.otm.compat.jade.JadeUids import ru.dbotthepony.mc.otm.compat.jade.JadeUids
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import snownee.jade.api.BlockAccessor import snownee.jade.api.BlockAccessor
import snownee.jade.api.IBlockComponentProvider import snownee.jade.api.IBlockComponentProvider
import snownee.jade.api.IServerDataProvider import snownee.jade.api.IServerDataProvider

View File

@ -12,7 +12,7 @@ import ru.dbotthepony.mc.otm.compat.jade.JadeUids
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.core.ifPresentK
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.getDecimal import ru.dbotthepony.mc.otm.core.math.getDecimal
import ru.dbotthepony.mc.otm.core.math.putDecimal import ru.dbotthepony.mc.otm.core.math.putDecimal
import ru.dbotthepony.mc.otm.core.util.formatMatter import ru.dbotthepony.mc.otm.core.util.formatMatter

View File

@ -12,7 +12,7 @@ import ru.dbotthepony.mc.otm.compat.jade.JadeUids
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.ifPresentK import ru.dbotthepony.mc.otm.core.ifPresentK
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.getDecimal import ru.dbotthepony.mc.otm.core.math.getDecimal
import ru.dbotthepony.mc.otm.core.math.putDecimal import ru.dbotthepony.mc.otm.core.math.putDecimal
import ru.dbotthepony.mc.otm.core.util.formatPower import ru.dbotthepony.mc.otm.core.util.formatPower

View File

@ -7,7 +7,7 @@ import ru.dbotthepony.mc.otm.block.entity.ItemJob
import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryWorkerBlockEntity
import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys import ru.dbotthepony.mc.otm.compat.jade.JadeTagKeys
import ru.dbotthepony.mc.otm.compat.jade.JadeUids import ru.dbotthepony.mc.otm.compat.jade.JadeUids
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.nbt.getCompoundList import ru.dbotthepony.mc.otm.core.nbt.getCompoundList
import ru.dbotthepony.mc.otm.core.nbt.getItemStack import ru.dbotthepony.mc.otm.core.nbt.getItemStack
import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.nbt.set

View File

@ -18,7 +18,7 @@ import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.RenderGravity import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.recipe.MicrowaveRecipe import ru.dbotthepony.mc.otm.recipe.MicrowaveRecipe

View File

@ -18,7 +18,7 @@ import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.render.RenderGravity import ru.dbotthepony.mc.otm.client.render.RenderGravity
import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel import ru.dbotthepony.mc.otm.client.screen.panels.slot.AbstractSlotPanel
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
import ru.dbotthepony.mc.otm.core.math.RGBAColor import ru.dbotthepony.kommons.math.RGBAColor
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.registryName import ru.dbotthepony.mc.otm.core.registryName
import ru.dbotthepony.mc.otm.recipe.PlatePressRecipe import ru.dbotthepony.mc.otm.recipe.PlatePressRecipe

View File

@ -11,6 +11,7 @@ import net.minecraft.world.inventory.MenuType
import net.minecraftforge.eventbus.api.IEventBus import net.minecraftforge.eventbus.api.IEventBus
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent
import net.minecraftforge.registries.DeferredRegister import net.minecraftforge.registries.DeferredRegister
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.core.getValue import ru.dbotthepony.mc.otm.core.getValue
import ru.dbotthepony.mc.otm.menu.MatteryMenu import ru.dbotthepony.mc.otm.menu.MatteryMenu

View File

@ -3,8 +3,9 @@ package ru.dbotthepony.mc.otm.config
import net.minecraftforge.common.ForgeConfigSpec import net.minecraftforge.common.ForgeConfigSpec
import net.minecraftforge.fml.ModLoadingContext import net.minecraftforge.fml.ModLoadingContext
import net.minecraftforge.fml.config.ModConfig import net.minecraftforge.fml.config.ModConfig
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.mc.otm.OverdriveThatMatters import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.core.GetterSetter
import ru.dbotthepony.mc.otm.core.getValue import ru.dbotthepony.mc.otm.core.getValue
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.core.math.defineDecimal
@ -59,10 +60,10 @@ abstract class AbstractConfig(private val configName: String, private val type:
val obj = object : WorkerBalanceValues { val obj = object : WorkerBalanceValues {
override val energyCapacity: Decimal by builder.defineDecimal("ENERGY_CAPACITY", energyStorage, minimum = Decimal.ONE) override val energyCapacity: Decimal by builder.defineDecimal("ENERGY_CAPACITY", energyStorage, minimum = Decimal.ONE)
override val energyThroughput: Decimal by builder.defineDecimal("ENERGY_THROUGHPUT", energyThroughput, minimum = Decimal.ONE) override val energyThroughput: Decimal by builder.defineDecimal("ENERGY_THROUGHPUT", energyThroughput, minimum = Decimal.ONE)
override val energyConsumption: Decimal by (if (energyConsumption == null) GetterSetter.box(Decimal.ZERO) else builder.defineDecimal("ENERGY_CONSUMPTION", energyConsumption, minimum = Decimal.ONE)) override val energyConsumption: Decimal by (if (energyConsumption == null) Delegate.Box(Decimal.ZERO) else builder.defineDecimal("ENERGY_CONSUMPTION", energyConsumption, minimum = Decimal.ONE))
override val matterCapacity: Decimal by (if (matterCapacity == null) GetterSetter.box(Decimal.ZERO) else builder.defineDecimal("MATTER_CAPACITY", matterCapacity, minimum = Decimal.ONE)) override val matterCapacity: Decimal by (if (matterCapacity == null) Delegate.Box(Decimal.ZERO) else builder.defineDecimal("MATTER_CAPACITY", matterCapacity, minimum = Decimal.ONE))
override val workTimeMultiplier: Double by (if (workTimeMultiplier == null) GetterSetter.box(1.0) else builder.defineInRange("WORK_TIME_MULTIPLIER", workTimeMultiplier, 0.0)) override val workTimeMultiplier: Double by (if (workTimeMultiplier == null) Delegate.Box(1.0) else builder.defineInRange("WORK_TIME_MULTIPLIER", workTimeMultiplier, 0.0))
override val maxExperienceStored: Double by (if (maxExperience == null) GetterSetter.box(Double.POSITIVE_INFINITY) else builder.defineInRange("MAX_EXPERIENCE_STORED", maxExperience, 0.0)) override val maxExperienceStored: Double by (if (maxExperience == null) Delegate.Box(Double.POSITIVE_INFINITY) else builder.defineInRange("MAX_EXPERIENCE_STORED", maxExperience, 0.0))
} }
configurator.invoke(builder) configurator.invoke(builder)

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.config package ru.dbotthepony.mc.otm.config
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.core.math.defineDecimal

View File

@ -1,5 +1,7 @@
package ru.dbotthepony.mc.otm.config package ru.dbotthepony.mc.otm.config
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.core.math.defineDecimal

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.config package ru.dbotthepony.mc.otm.config
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.core.math.defineDecimal

View File

@ -1,5 +1,6 @@
package ru.dbotthepony.mc.otm.config package ru.dbotthepony.mc.otm.config
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.math.defineDecimal import ru.dbotthepony.mc.otm.core.math.defineDecimal
import ru.dbotthepony.mc.otm.registry.MNames import ru.dbotthepony.mc.otm.registry.MNames

Some files were not shown because too many files have changed in this diff Show More