Update "nullable" usage of stream codec

This commit is contained in:
DBotThePony 2024-05-16 17:25:44 +07:00
parent 728a7de0bf
commit 3d8e5fb774
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 11 additions and 8 deletions

View File

@ -69,6 +69,7 @@ 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.io.nullable
import ru.dbotthepony.kommons.util.ListenableDelegate
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
@ -254,7 +255,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
*/
var exopackGlows by publicSyncher.boolean(true)
var exopackColor by publicSyncher.add(ListenableDelegate.Box(null), RGBCodec.nullable)
var exopackColor by publicSyncher.add(ListenableDelegate.Box(null), RGBCodec.nullable())
/**
* Tick event schedulers
@ -286,7 +287,7 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
}, backingMap = this.exopackSlotModifierMap.delegate)
val regularSlotFilters = immutableList(Inventory.INVENTORY_SIZE) {
syncher.add(null, ItemValueCodec.nullable)
syncher.add(null, ItemValueCodec.nullable())
}
val slotsChargeFlag = syncher.SetSlot(

View File

@ -31,6 +31,7 @@ import ru.dbotthepony.kommons.io.FloatValueCodec
import ru.dbotthepony.kommons.io.NullValueCodec
import ru.dbotthepony.kommons.io.StreamCodec
import ru.dbotthepony.kommons.io.VarIntValueCodec
import ru.dbotthepony.kommons.io.nullable
import ru.dbotthepony.kommons.util.Delegate
import ru.dbotthepony.kommons.util.getValue
import ru.dbotthepony.kommons.util.setValue
@ -192,7 +193,7 @@ abstract class MatteryMenu(
fun booleanInput(allowSpectators: Boolean = false, handler: (Boolean) -> Unit) = PlayerInput(BooleanValueCodec, allowSpectators, handler)
fun itemInput(allowSpectators: Boolean = false, handler: (Item) -> Unit) = PlayerInput(ItemValueCodec, allowSpectators, handler)
fun itemStackInput(allowSpectators: Boolean = false, handler: (ItemStack) -> Unit) = PlayerInput(ItemStackValueCodec, allowSpectators, handler)
fun nullableItemInput(allowSpectators: Boolean = false, handler: (Item?) -> Unit) = PlayerInput(ItemValueCodec.nullable, allowSpectators, handler)
fun nullableItemInput(allowSpectators: Boolean = false, handler: (Item?) -> Unit) = PlayerInput(ItemValueCodec.nullable(), allowSpectators, handler)
fun stringInput(allowSpectators: Boolean = false, handler: (String) -> Unit) = PlayerInput(BinaryStringCodec, allowSpectators, handler)
fun floatInput(allowSpectators: Boolean = false, handler: (Float) -> Unit) = PlayerInput(FloatValueCodec, allowSpectators, handler)
fun intInput(allowSpectators: Boolean = false, handler: (Int) -> Unit) = PlayerInput(VarIntValueCodec, allowSpectators, handler)
@ -441,11 +442,11 @@ abstract class MatteryMenu(
val field: Delegate<Item?>
if (container is IMatteryContainer) {
input = PlayerInput(ItemValueCodec.nullable, handler = { container.setSlotFilter(pSlot.slotIndex, it) })
field = mSynchronizer.add(delegate = { container.getSlotFilter(pSlot.slotIndex) }, ItemValueCodec.nullable)
input = PlayerInput(ItemValueCodec.nullable(), handler = { container.setSlotFilter(pSlot.slotIndex, it) })
field = mSynchronizer.add(delegate = { container.getSlotFilter(pSlot.slotIndex) }, ItemValueCodec.nullable())
} else {
input = PlayerInput(ItemValueCodec.nullable, handler = { throw UnsupportedOperationException() })
field = mSynchronizer.add(delegate = { null }, ItemValueCodec.nullable)
input = PlayerInput(ItemValueCodec.nullable(), handler = { throw UnsupportedOperationException() })
field = mSynchronizer.add(delegate = { null }, ItemValueCodec.nullable())
}
pSlot.filter = Delegate.Of(getter = field::get, setter = input::accept)

View File

@ -9,6 +9,7 @@ import net.minecraft.world.level.material.Fluids
import net.minecraftforge.common.capabilities.ForgeCapabilities
import net.minecraftforge.fluids.FluidStack
import net.minecraftforge.fluids.capability.IFluidHandler
import ru.dbotthepony.kommons.io.nullable
import ru.dbotthepony.kommons.util.Listenable
import ru.dbotthepony.kommons.util.ListenableDelegate
import ru.dbotthepony.kommons.util.getValue
@ -46,7 +47,7 @@ class PainterMenu(
val inputContainer = MatteryContainer(::rescan, 1)
val outputContainer = MatteryContainer(1)
private var lastRecipe: RecipeHolder<out AbstractPainterRecipe>? = null
var selectedRecipe by mSynchronizer.Slot(ListenableDelegate.Box(null), ResourceLocationValueCodec.nullable).also { it.addListener(Runnable { rescan() }) }
var selectedRecipe by mSynchronizer.Slot(ListenableDelegate.Box(null), ResourceLocationValueCodec.nullable()).also { it.addListener(Runnable { rescan() }) }
val isBulk = BooleanInputWithFeedback(this, tile?.let { it::isBulk })