Resolve more misc compilation errors
This commit is contained in:
parent
333238fde5
commit
ce119269e0
src/main/kotlin/ru/dbotthepony/mc/otm
block
capability
client/screen
compat/cos
config
container
core/util
item
menu
data
input
matter
storage
tech
widget
network
@ -59,8 +59,7 @@ abstract class CableBlock(properties: Properties) : MatteryBlock(properties) {
|
|||||||
return getShapeForEachStateMattery { getShapeFor(it, halfCoreSize) }
|
return getShapeForEachStateMattery { getShapeFor(it, halfCoreSize) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("OVERRIDE_DEPRECATION")
|
override fun useWithoutItem(blockState: BlockState, level: Level, blockPos: BlockPos, ply: Player, blockHitResult: BlockHitResult): InteractionResult {
|
||||||
override fun use(blockState: BlockState, level: Level, blockPos: BlockPos, ply: Player, hand: InteractionHand, blockHitResult: BlockHitResult): InteractionResult {
|
|
||||||
return InteractionResult.PASS
|
return InteractionResult.PASS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
package ru.dbotthepony.mc.otm.block
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
|
||||||
import net.minecraft.world.level.Level
|
|
||||||
import net.minecraft.world.level.block.Block
|
|
||||||
import net.minecraft.world.level.block.EntityBlock
|
|
||||||
import net.minecraft.world.level.block.SoundType
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityTicker
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType
|
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
|
||||||
import net.minecraft.world.level.material.PushReaction
|
|
||||||
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityExplosionDebugger
|
|
||||||
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntitySphereDebugger
|
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
|
||||||
|
|
||||||
class BlockExplosionDebugger : Block(Properties.of().sound(SoundType.STONE).pushReaction(PushReaction.BLOCK)), EntityBlock {
|
|
||||||
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
|
|
||||||
return BlockEntityExplosionDebugger(p_153215_, p_153216_)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <T : BlockEntity?> getTicker(
|
|
||||||
p_153212_: Level,
|
|
||||||
p_153213_: BlockState,
|
|
||||||
p_153214_: BlockEntityType<T>
|
|
||||||
): BlockEntityTicker<T>? {
|
|
||||||
if (!p_153212_.isClientSide && p_153214_ === MBlockEntities.DEBUG_EXPLOSION_SMALL) {
|
|
||||||
return BlockEntityTicker {_, _, _, t -> if (t is BlockEntityExplosionDebugger) t.tick()}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BlockSphereDebugger : Block(Properties.of()), EntityBlock {
|
|
||||||
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
|
|
||||||
return BlockEntitySphereDebugger(p_153215_, p_153216_)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <T : BlockEntity?> getTicker(
|
|
||||||
p_153212_: Level,
|
|
||||||
p_153213_: BlockState,
|
|
||||||
p_153214_: BlockEntityType<T>
|
|
||||||
): BlockEntityTicker<T>? {
|
|
||||||
if (!p_153212_.isClientSide && p_153214_ === MBlockEntities.DEBUG_SPHERE_POINTS) {
|
|
||||||
return BlockEntityTicker {_, _, _, t -> if (t is BlockEntitySphereDebugger) t.tick()}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.block.decorative
|
|||||||
import net.minecraft.ChatFormatting
|
import net.minecraft.ChatFormatting
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.world.item.Item
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.item.TooltipFlag
|
import net.minecraft.world.item.TooltipFlag
|
||||||
import net.minecraft.world.level.BlockGetter
|
import net.minecraft.world.level.BlockGetter
|
||||||
@ -21,11 +22,11 @@ import ru.dbotthepony.mc.otm.shapes.BlockShapes
|
|||||||
class EngineBlock : RotatableMatteryBlock(Properties.of().mapColor(MapColor.COLOR_ORANGE).sound(SoundType.METAL).explosionResistance(14f).destroyTime(2.5f).requiresCorrectToolForDrops().pushReaction(PushReaction.NORMAL)) {
|
class EngineBlock : RotatableMatteryBlock(Properties.of().mapColor(MapColor.COLOR_ORANGE).sound(SoundType.METAL).explosionResistance(14f).destroyTime(2.5f).requiresCorrectToolForDrops().pushReaction(PushReaction.NORMAL)) {
|
||||||
override fun appendHoverText(
|
override fun appendHoverText(
|
||||||
itemStack: ItemStack,
|
itemStack: ItemStack,
|
||||||
blockAccessor: BlockGetter?,
|
context: Item.TooltipContext,
|
||||||
components: MutableList<Component>,
|
components: MutableList<Component>,
|
||||||
tooltipType: TooltipFlag
|
tooltipType: TooltipFlag
|
||||||
) {
|
) {
|
||||||
super.appendHoverText(itemStack, blockAccessor, components, tooltipType)
|
super.appendHoverText(itemStack, context, components, tooltipType)
|
||||||
components.add(TranslatableComponent("$descriptionId.desc").withStyle(ChatFormatting.DARK_GRAY))
|
components.add(TranslatableComponent("$descriptionId.desc").withStyle(ChatFormatting.DARK_GRAY))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ package ru.dbotthepony.mc.otm.block.decorative
|
|||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
import net.minecraft.world.InteractionHand
|
import net.minecraft.world.InteractionHand
|
||||||
import net.minecraft.world.InteractionResult
|
import net.minecraft.world.InteractionResult
|
||||||
|
import net.minecraft.world.ItemInteractionResult
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.level.BlockGetter
|
import net.minecraft.world.level.BlockGetter
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.block.EntityBlock
|
import net.minecraft.world.level.block.EntityBlock
|
||||||
@ -33,13 +35,12 @@ class FluidTankBlock : RotatableMatteryBlock(DEFAULT_MACHINE_PROPERTIES), Entity
|
|||||||
return BlockEntityTicker { _, _, _, pBlockEntity -> if (pBlockEntity is FluidTankBlockEntity) pBlockEntity.tick() }
|
return BlockEntityTicker { _, _, _, pBlockEntity -> if (pBlockEntity is FluidTankBlockEntity) pBlockEntity.tick() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("OVERRIDE_DEPRECATION")
|
override fun useItemOn(item: ItemStack, blockState: BlockState, level: Level, blockPos: BlockPos, ply: Player, hand: InteractionHand, blockHitResult: BlockHitResult): ItemInteractionResult {
|
||||||
override fun use(blockState: BlockState, level: Level, blockPos: BlockPos, ply: Player, hand: InteractionHand, blockHitResult: BlockHitResult): InteractionResult {
|
|
||||||
if (FluidUtil.interactWithFluidHandler(ply, hand, level, blockPos, blockHitResult.direction)) {
|
if (FluidUtil.interactWithFluidHandler(ply, hand, level, blockPos, blockHitResult.direction)) {
|
||||||
return InteractionResult.sidedSuccess(level.isClientSide)
|
return ItemInteractionResult.sidedSuccess(level.isClientSide)
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.use(blockState, level, blockPos, ply, hand, blockHitResult)
|
return super.useItemOn(item, blockState, level, blockPos, ply, hand, blockHitResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val shapes = getShapeForEachState(rotationProperty) { BlockShapes.FLUID_TANK.rotateFromNorth(it[rotationProperty]).computeShape() }
|
private val shapes = getShapeForEachState(rotationProperty) { BlockShapes.FLUID_TANK.rotateFromNorth(it[rotationProperty]).computeShape() }
|
||||||
|
@ -37,7 +37,6 @@ 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
|
||||||
|
@ -22,8 +22,8 @@ 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.get
|
import ru.dbotthepony.mc.otm.container.get
|
||||||
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
||||||
import ru.dbotthepony.mc.otm.core.util.FluidStackValueCodec
|
|
||||||
import ru.dbotthepony.mc.otm.menu.decorative.FluidTankMenu
|
import ru.dbotthepony.mc.otm.menu.decorative.FluidTankMenu
|
||||||
|
import ru.dbotthepony.mc.otm.network.wrap
|
||||||
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) {
|
||||||
@ -34,7 +34,7 @@ class FluidTankBlockEntity(blockPos: BlockPos, blockState: BlockState) : Mattery
|
|||||||
if (level is ServerLevel) {
|
if (level is ServerLevel) {
|
||||||
markDirtyFast()
|
markDirtyFast()
|
||||||
}
|
}
|
||||||
}), FluidStackValueCodec))
|
}), FluidStack.STREAM_CODEC.wrap()))
|
||||||
|
|
||||||
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)
|
||||||
|
@ -29,7 +29,6 @@ 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
|
||||||
|
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.block.entity.matter
|
|||||||
import com.mojang.serialization.Codec
|
import com.mojang.serialization.Codec
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
|
import net.minecraft.core.UUIDUtil
|
||||||
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
|
||||||
@ -28,7 +29,6 @@ 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.minRange
|
import ru.dbotthepony.mc.otm.data.minRange
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.MatterNode
|
import ru.dbotthepony.mc.otm.graph.matter.MatterNode
|
||||||
@ -56,7 +56,7 @@ class MatterReplicatorBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
|||||||
it.group(
|
it.group(
|
||||||
ItemStack.CODEC.fieldOf("Item").forGetter(ReplicatorJob::itemStack),
|
ItemStack.CODEC.fieldOf("Item").forGetter(ReplicatorJob::itemStack),
|
||||||
DecimalCodec.minRange(Decimal.ZERO).fieldOf("matterPerTick").forGetter(ReplicatorJob::matterPerTick),
|
DecimalCodec.minRange(Decimal.ZERO).fieldOf("matterPerTick").forGetter(ReplicatorJob::matterPerTick),
|
||||||
UUIDCodec.fieldOf("task").forGetter(ReplicatorJob::task),
|
UUIDUtil.CODEC.fieldOf("task").forGetter(ReplicatorJob::task),
|
||||||
DecimalCodec.minRange(Decimal.ZERO).fieldOf("matterValue").forGetter(ReplicatorJob::matterValue),
|
DecimalCodec.minRange(Decimal.ZERO).fieldOf("matterValue").forGetter(ReplicatorJob::matterValue),
|
||||||
PatternState.CODEC.optionalFieldOf("pattern").forGetter(ReplicatorJob::pattern),
|
PatternState.CODEC.optionalFieldOf("pattern").forGetter(ReplicatorJob::pattern),
|
||||||
Codec.BOOL.fieldOf("asDust").forGetter(ReplicatorJob::asDust),
|
Codec.BOOL.fieldOf("asDust").forGetter(ReplicatorJob::asDust),
|
||||||
|
@ -23,7 +23,6 @@ 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
|
||||||
|
@ -36,7 +36,6 @@ 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.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
|
||||||
|
@ -27,7 +27,6 @@ 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.*
|
||||||
|
@ -33,18 +33,17 @@ class AndroidStationBlock(val color: DyeColor?) : MatteryBlock(DEFAULT_MACHINE_P
|
|||||||
tooltips.blockEntityEnergy()
|
tooltips.blockEntityEnergy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun use(
|
override fun useWithoutItem(
|
||||||
blockState: BlockState,
|
blockState: BlockState,
|
||||||
level: Level,
|
level: Level,
|
||||||
blockPos: BlockPos,
|
blockPos: BlockPos,
|
||||||
ply: Player,
|
ply: Player,
|
||||||
hand: InteractionHand,
|
|
||||||
blockHitResult: BlockHitResult
|
blockHitResult: BlockHitResult
|
||||||
): InteractionResult {
|
): InteractionResult {
|
||||||
if (!ply.matteryPlayer.isAndroid)
|
if (!ply.matteryPlayer.isAndroid)
|
||||||
return InteractionResult.FAIL
|
return InteractionResult.FAIL
|
||||||
|
|
||||||
return super.use(blockState, level, blockPos, ply, hand, blockHitResult)
|
return super.useWithoutItem(blockState, level, blockPos, ply, blockHitResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
|
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
|
||||||
|
@ -5,8 +5,10 @@ import net.minecraft.core.BlockPos
|
|||||||
import net.minecraft.nbt.LongTag
|
import net.minecraft.nbt.LongTag
|
||||||
import net.minecraft.world.InteractionHand
|
import net.minecraft.world.InteractionHand
|
||||||
import net.minecraft.world.InteractionResult
|
import net.minecraft.world.InteractionResult
|
||||||
|
import net.minecraft.world.ItemInteractionResult
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.item.DyeColor
|
import net.minecraft.world.item.DyeColor
|
||||||
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraft.world.level.BlockGetter
|
import net.minecraft.world.level.BlockGetter
|
||||||
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
|
||||||
@ -63,13 +65,12 @@ class EssenceStorageBlock(val color: DyeColor?) : RotatableMatteryBlock(Properti
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("OVERRIDE_DEPRECATION")
|
override fun useItemOn(itemStack: ItemStack, blockState: BlockState, level: Level, blockPos: BlockPos, ply: Player, hand: InteractionHand, blockHitResult: BlockHitResult): ItemInteractionResult {
|
||||||
override fun use(blockState: BlockState, level: Level, blockPos: BlockPos, ply: Player, hand: InteractionHand, blockHitResult: BlockHitResult): InteractionResult {
|
if (itemStack.item == MItems.ESSENCE_SERVO) {
|
||||||
if (ply.getItemInHand(hand).item == MItems.ESSENCE_SERVO) {
|
|
||||||
return MItems.ESSENCE_SERVO.useServo(ply, blockPos)
|
return MItems.ESSENCE_SERVO.useServo(ply, blockPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.use(blockState, level, blockPos, ply, hand, blockHitResult)
|
return super.useItemOn(itemStack, blockState, level, blockPos, ply, hand, blockHitResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
|
override fun createBlockStateDefinition(builder: StateDefinition.Builder<Block, BlockState>) {
|
||||||
|
@ -17,8 +17,6 @@ import ru.dbotthepony.mc.otm.capability.receiveEnergy
|
|||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.getDecimal
|
import ru.dbotthepony.mc.otm.core.math.getDecimal
|
||||||
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.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
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.capability.matter
|
|||||||
|
|
||||||
import com.mojang.serialization.Codec
|
import com.mojang.serialization.Codec
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||||
|
import net.minecraft.core.UUIDUtil
|
||||||
import net.minecraft.core.registries.BuiltInRegistries
|
import net.minecraft.core.registries.BuiltInRegistries
|
||||||
import net.minecraft.network.FriendlyByteBuf
|
import net.minecraft.network.FriendlyByteBuf
|
||||||
import net.minecraft.world.item.Item
|
import net.minecraft.world.item.Item
|
||||||
@ -35,7 +36,7 @@ data class PatternState(
|
|||||||
val CODEC: Codec<PatternState> by lazy {
|
val CODEC: Codec<PatternState> by lazy {
|
||||||
RecordCodecBuilder.create {
|
RecordCodecBuilder.create {
|
||||||
it.group(
|
it.group(
|
||||||
UUIDCodec.fieldOf("id").forGetter(PatternState::id),
|
UUIDUtil.CODEC.fieldOf("id").forGetter(PatternState::id),
|
||||||
BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(PatternState::item),
|
BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(PatternState::item),
|
||||||
Codec.doubleRange(0.0, 1.0).fieldOf("researchPercent").forGetter(PatternState::researchPercent)
|
Codec.doubleRange(0.0, 1.0).fieldOf("researchPercent").forGetter(PatternState::researchPercent)
|
||||||
).apply(it, ::PatternState)
|
).apply(it, ::PatternState)
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.mc.otm.capability.matter
|
|||||||
|
|
||||||
import com.mojang.serialization.Codec
|
import com.mojang.serialization.Codec
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||||
|
import net.minecraft.core.UUIDUtil
|
||||||
import net.minecraft.core.registries.BuiltInRegistries
|
import net.minecraft.core.registries.BuiltInRegistries
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.nbt.NbtOps
|
import net.minecraft.nbt.NbtOps
|
||||||
@ -66,8 +67,8 @@ data class ReplicationTask(
|
|||||||
val CODEC: Codec<ReplicationTask> by lazy {
|
val CODEC: Codec<ReplicationTask> by lazy {
|
||||||
RecordCodecBuilder.create {
|
RecordCodecBuilder.create {
|
||||||
it.group(
|
it.group(
|
||||||
UUIDCodec.fieldOf("id").forGetter(ReplicationTask::id),
|
UUIDUtil.CODEC.fieldOf("id").forGetter(ReplicationTask::id),
|
||||||
UUIDCodec.optionalFieldOf("patternId").forGetter(ReplicationTask::patternId),
|
UUIDUtil.CODEC.optionalFieldOf("patternId").forGetter(ReplicationTask::patternId),
|
||||||
BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(ReplicationTask::item),
|
BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(ReplicationTask::item),
|
||||||
Codec.intRange(0, Int.MAX_VALUE).fieldOf("inProgress").forGetter(ReplicationTask::inProgress),
|
Codec.intRange(0, Int.MAX_VALUE).fieldOf("inProgress").forGetter(ReplicationTask::inProgress),
|
||||||
Codec.intRange(0, Int.MAX_VALUE).fieldOf("finished").forGetter(ReplicationTask::finished),
|
Codec.intRange(0, Int.MAX_VALUE).fieldOf("finished").forGetter(ReplicationTask::finished),
|
||||||
|
@ -152,7 +152,7 @@ open class EffectListPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected val effectButtons: MutableMap<Holder<MobEffect>, EffectSquare> = Object2ObjectArrayMap()
|
protected val effectButtons: MutableMap<Holder<MobEffect>, EffectListPanel<*>.EffectSquare> = Object2ObjectArrayMap()
|
||||||
|
|
||||||
fun calculateMaxScroll(scrollBarPanel: DiscreteScrollBarPanel<*>): Int {
|
fun calculateMaxScroll(scrollBarPanel: DiscreteScrollBarPanel<*>): Int {
|
||||||
return integerDivisionDown(entity.activeEffects.size, gridWidth)
|
return integerDivisionDown(entity.activeEffects.size, gridWidth)
|
||||||
|
@ -238,7 +238,7 @@ open class FramePanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected val tabs: java.util.ArrayList<Tab> = ArrayList()
|
protected val tabs: ArrayList<FramePanel<*>.Tab> = ArrayList()
|
||||||
|
|
||||||
override fun performLayout() {
|
override fun performLayout() {
|
||||||
for ((i, tab) in tabs.withIndex()) {
|
for ((i, tab) in tabs.withIndex()) {
|
||||||
|
@ -434,7 +434,7 @@ class DeviceControls<out S : MatteryScreen<*>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var isDisabled: Boolean
|
override var isDisabled: Boolean
|
||||||
get() = !input.input.test(minecraft.player)
|
get() { return !input.input.test(minecraft.player ?: return false) }
|
||||||
set(value) {}
|
set(value) {}
|
||||||
|
|
||||||
private fun makeButtons() {
|
private fun makeButtons() {
|
||||||
|
@ -4,7 +4,6 @@ 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.Delegate
|
||||||
import ru.dbotthepony.kommons.util.value
|
import ru.dbotthepony.kommons.util.value
|
||||||
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
import ru.dbotthepony.mc.otm.client.render.MGUIGraphics
|
||||||
@ -14,6 +13,7 @@ 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.menu.input.IPlayerInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
|
||||||
|
import ru.dbotthepony.mc.otm.network.MatteryStreamCodec
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
@ -29,7 +29,7 @@ abstract class EnumRectangleButtonPanel<out S : Screen, T : Enum<T>>(
|
|||||||
val prop: Delegate<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 = StreamCodec.Enum.searchClass(enum)
|
val enum = MatteryStreamCodec.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 }
|
||||||
|
@ -57,7 +57,7 @@ open class LargeRectangleButtonPanel<out S : Screen>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var isDisabled: Boolean
|
override var isDisabled: Boolean
|
||||||
get() = !input.test(minecraft.player)
|
get() { return !input.test(minecraft.player ?: return false) }
|
||||||
set(value) {}
|
set(value) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,11 @@ package ru.dbotthepony.mc.otm.client.screen.storage
|
|||||||
|
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
|
||||||
import ru.dbotthepony.mc.otm.client.render.Widgets18
|
|
||||||
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
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.DeviceControls
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.DeviceControls
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.LargeEnumRectangleButtonPanel
|
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.input.IntInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.input.IntInputPanel
|
||||||
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.panels.slot.FilterSlotPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.slot.FilterSlotPanel
|
||||||
@ -29,7 +26,7 @@ class StorageBusScreen(menu: StorageBusMenu, inventory: Inventory, title: Compon
|
|||||||
grid.dock = Dock.TOP
|
grid.dock = Dock.TOP
|
||||||
grid.dockBottom = 2f
|
grid.dockBottom = 2f
|
||||||
|
|
||||||
for (slot in menu.busFilterSlots)
|
for (slot in menu.filter.slots)
|
||||||
FilterSlotPanel(this, grid, slot)
|
FilterSlotPanel(this, grid, slot)
|
||||||
|
|
||||||
IntInputPanel(this, right, menu.insertPriority).also {
|
IntInputPanel(this, right, menu.insertPriority).also {
|
||||||
@ -46,7 +43,7 @@ class StorageBusScreen(menu: StorageBusMenu, inventory: Inventory, title: Compon
|
|||||||
it.childrenOrder = -2
|
it.childrenOrder = -2
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckBoxLabelInputPanel(this, right, menu.busFilterState, TranslatableComponent("otm.gui.filter.is_whitelist")).also {
|
CheckBoxLabelInputPanel(this, right, menu.filter.isWhitelist, TranslatableComponent("otm.gui.filter.is_whitelist")).also {
|
||||||
it.dock = Dock.BOTTOM
|
it.dock = Dock.BOTTOM
|
||||||
it.childrenOrder = -3
|
it.childrenOrder = -3
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ class EssenceStorageScreen(menu: EssenceStorageMenu, inventory: Inventory, title
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var isDisabled: Boolean
|
override var isDisabled: Boolean
|
||||||
get() = !menu.storeLevels.test(minecraft?.player)
|
get() = !menu.storeLevels.test(minecraft!!.player!!)
|
||||||
set(value) {}
|
set(value) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ class EssenceStorageScreen(menu: EssenceStorageMenu, inventory: Inventory, title
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var isDisabled: Boolean
|
override var isDisabled: Boolean
|
||||||
get() = !menu.storeLevels.test(minecraft?.player)
|
get() = !menu.storeLevels.test(minecraft!!.player!!)
|
||||||
set(value) {}
|
set(value) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ class EssenceStorageScreen(menu: EssenceStorageMenu, inventory: Inventory, title
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var isDisabled: Boolean
|
override var isDisabled: Boolean
|
||||||
get() = !menu.dispenseLevels.test(minecraft?.player) && !menu.storeLevels.test(minecraft?.player)
|
get() = !menu.dispenseLevels.test(minecraft!!.player!!) && !menu.storeLevels.test(minecraft!!.player!!)
|
||||||
set(value) {}
|
set(value) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import net.minecraft.world.entity.player.Player
|
|||||||
import net.minecraft.world.inventory.InventoryMenu
|
import net.minecraft.world.inventory.InventoryMenu
|
||||||
import net.minecraft.world.inventory.Slot
|
import net.minecraft.world.inventory.Slot
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import net.minecraftforge.fml.ModList
|
|
||||||
import net.neoforged.fml.ModList
|
import net.neoforged.fml.ModList
|
||||||
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
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package ru.dbotthepony.mc.otm.config
|
package ru.dbotthepony.mc.otm.config
|
||||||
|
|
||||||
import net.minecraftforge.fml.config.ModConfig
|
import net.neoforged.fml.config.ModConfig
|
||||||
|
|
||||||
object ClientConfig : AbstractConfig("client", ModConfig.Type.CLIENT) {
|
object ClientConfig : AbstractConfig("client", ModConfig.Type.CLIENT) {
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ import net.neoforged.neoforge.common.util.INBTSerializable
|
|||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.kommons.collect.ListenableMap
|
import ru.dbotthepony.kommons.collect.ListenableMap
|
||||||
import ru.dbotthepony.mc.otm.network.DelegateSyncher
|
import ru.dbotthepony.mc.otm.network.DelegateSyncher
|
||||||
import ru.dbotthepony.kommons.io.VarIntValueCodec
|
|
||||||
import ru.dbotthepony.mc.otm.container.util.IContainerSlot
|
import ru.dbotthepony.mc.otm.container.util.IContainerSlot
|
||||||
import ru.dbotthepony.mc.otm.core.addSorted
|
import ru.dbotthepony.mc.otm.core.addSorted
|
||||||
import ru.dbotthepony.mc.otm.core.collect.any
|
import ru.dbotthepony.mc.otm.core.collect.any
|
||||||
@ -36,8 +35,8 @@ import ru.dbotthepony.mc.otm.core.collect.map
|
|||||||
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||||
import ru.dbotthepony.mc.otm.core.registryName
|
import ru.dbotthepony.mc.otm.core.registryName
|
||||||
import ru.dbotthepony.mc.otm.core.util.ItemValueCodec
|
|
||||||
import ru.dbotthepony.mc.otm.data.minRange
|
import ru.dbotthepony.mc.otm.data.minRange
|
||||||
|
import ru.dbotthepony.mc.otm.network.StreamCodecs
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
@ -124,8 +123,8 @@ open class MatteryContainer(var listener: ContainerListener, private val size: I
|
|||||||
|
|
||||||
val field = synchronizer.MapSlot(
|
val field = synchronizer.MapSlot(
|
||||||
ListenableMap<Int, Item>(Int2ObjectOpenHashMap()),
|
ListenableMap<Int, Item>(Int2ObjectOpenHashMap()),
|
||||||
keyCodec = VarIntValueCodec,
|
keyCodec = StreamCodecs.VAR_INT,
|
||||||
valueCodec = ItemValueCodec,
|
valueCodec = StreamCodecs.ITEM_TYPE,
|
||||||
)
|
)
|
||||||
|
|
||||||
for ((i, filter) in filters.withIndex()) {
|
for ((i, filter) in filters.withIndex()) {
|
||||||
|
@ -37,80 +37,6 @@ fun InputStream.readNbt(): CompoundTag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun OutputStream.writeItem(itemStack: ItemStack, limitedTag: Boolean = true) {
|
|
||||||
if (itemStack.isEmpty) {
|
|
||||||
write(0)
|
|
||||||
} else {
|
|
||||||
write(1)
|
|
||||||
val id = BuiltInRegistries.ITEM.getId(itemStack.item)
|
|
||||||
|
|
||||||
writeInt(id)
|
|
||||||
writeInt(itemStack.count)
|
|
||||||
|
|
||||||
var compoundtag: CompoundTag? = null
|
|
||||||
|
|
||||||
if (itemStack.item.isDamageable(itemStack)) {
|
|
||||||
compoundtag = if (limitedTag) itemStack.shareTag else itemStack.tag
|
|
||||||
}
|
|
||||||
|
|
||||||
write(if (compoundtag != null) 1 else 0)
|
|
||||||
|
|
||||||
if (compoundtag != null) {
|
|
||||||
writeNbt(compoundtag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun InputStream.readItem(): ItemStack {
|
|
||||||
if (read() == 0) {
|
|
||||||
return ItemStack.EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
val item = BuiltInRegistries.ITEM.byId(readInt())
|
|
||||||
val itemStack = ItemStack(item, readInt())
|
|
||||||
|
|
||||||
if (read() != 0) {
|
|
||||||
itemStack.readShareTag(readNbt())
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemStack
|
|
||||||
}
|
|
||||||
|
|
||||||
fun OutputStream.writeFluidStack(value: FluidStack) {
|
|
||||||
if (value.isEmpty) {
|
|
||||||
write(0)
|
|
||||||
} else {
|
|
||||||
write(1)
|
|
||||||
|
|
||||||
val id = (ForgeRegistries.FLUIDS as ForgeRegistry<Fluid>).getID(value.fluid)
|
|
||||||
writeVarIntLE(id)
|
|
||||||
writeInt(value.amount)
|
|
||||||
|
|
||||||
if (value.hasTag()) {
|
|
||||||
write(1)
|
|
||||||
writeNbt(value.tag!!)
|
|
||||||
} else {
|
|
||||||
write(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun InputStream.readFluidStack(): FluidStack {
|
|
||||||
if (read() == 0) {
|
|
||||||
return FluidStack.EMPTY
|
|
||||||
} else {
|
|
||||||
val id = readVarIntLE()
|
|
||||||
val fluid = (ForgeRegistries.FLUIDS as ForgeRegistry<Fluid>).getValue(id) ?: return FluidStack.EMPTY
|
|
||||||
val amount = readInt()
|
|
||||||
|
|
||||||
if (read() > 0) {
|
|
||||||
return FluidStack(fluid, amount, readNbt())
|
|
||||||
} else {
|
|
||||||
return FluidStack(fluid, amount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun OutputStream.writeBigDecimal(value: BigDecimal) {
|
fun OutputStream.writeBigDecimal(value: BigDecimal) {
|
||||||
writeInt(value.scale())
|
writeInt(value.scale())
|
||||||
val bytes = value.unscaledValue().toByteArray()
|
val bytes = value.unscaledValue().toByteArray()
|
||||||
|
@ -13,6 +13,7 @@ import net.minecraft.world.entity.player.Player
|
|||||||
import net.minecraft.world.item.*
|
import net.minecraft.world.item.*
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.neoforged.neoforge.capabilities.Capabilities
|
import net.neoforged.neoforge.capabilities.Capabilities
|
||||||
|
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent
|
||||||
import ru.dbotthepony.mc.otm.config.BatteryBalanceValues
|
import ru.dbotthepony.mc.otm.config.BatteryBalanceValues
|
||||||
import ru.dbotthepony.mc.otm.capability.*
|
import ru.dbotthepony.mc.otm.capability.*
|
||||||
import ru.dbotthepony.mc.otm.capability.energy.EnergyCapacitorItem
|
import ru.dbotthepony.mc.otm.capability.energy.EnergyCapacitorItem
|
||||||
@ -22,12 +23,13 @@ import ru.dbotthepony.mc.otm.client.minecraft
|
|||||||
import ru.dbotthepony.mc.otm.config.ItemsConfig
|
import ru.dbotthepony.mc.otm.config.ItemsConfig
|
||||||
import ru.dbotthepony.mc.otm.core.*
|
import ru.dbotthepony.mc.otm.core.*
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
|
import ru.dbotthepony.mc.otm.registry.CapabilitiesRegisterListener
|
||||||
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
|
||||||
import ru.dbotthepony.mc.otm.runIfClient
|
import ru.dbotthepony.mc.otm.runIfClient
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
open class BatteryItem : MatteryItem {
|
open class BatteryItem : MatteryItem, CapabilitiesRegisterListener {
|
||||||
val _capacity: () -> Decimal
|
val _capacity: () -> Decimal
|
||||||
val _receive: () -> Decimal
|
val _receive: () -> Decimal
|
||||||
val _extract: () -> Decimal
|
val _extract: () -> Decimal
|
||||||
@ -105,10 +107,14 @@ open class BatteryItem : MatteryItem {
|
|||||||
tooltips.itemEnergy()
|
tooltips.itemEnergy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initCapabilities(stack: ItemStack, nbt: CompoundTag?): ICapabilityProvider {
|
private fun capFor(stack: ItemStack): EnergyCapacitorItem {
|
||||||
stack.getCapability()
|
|
||||||
return EnergyCapacitorItem(stack, this@BatteryItem.capacity, this@BatteryItem.receive, this@BatteryItem.extract, initialBatteryLevel = this@BatteryItem.initialBatteryLevel)
|
return EnergyCapacitorItem(stack, this@BatteryItem.capacity, this@BatteryItem.receive, this@BatteryItem.extract, initialBatteryLevel = this@BatteryItem.initialBatteryLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun registerCapabilities(event: RegisterCapabilitiesEvent) {
|
||||||
|
event.registerItem(MatteryCapability.ITEM_ENERGY, { o, _ -> capFor(o) }, this)
|
||||||
|
event.registerItem(Capabilities.EnergyStorage.ITEM, { o, _ -> capFor(o) }, this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CrudeBatteryItem : BatteryItem(ItemsConfig.Batteries.CRUDE) {
|
class CrudeBatteryItem : BatteryItem(ItemsConfig.Batteries.CRUDE) {
|
||||||
@ -132,7 +138,7 @@ class CrudeBatteryItem : BatteryItem(ItemsConfig.Batteries.CRUDE) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun use(level: Level, player: Player, hand: InteractionHand): InteractionResultHolder<ItemStack> {
|
override fun use(level: Level, player: Player, hand: InteractionHand): InteractionResultHolder<ItemStack> {
|
||||||
if (player.matteryPlayer?.isAndroid == true) {
|
if (player.matteryPlayer.isAndroid) {
|
||||||
player.startUsingItem(hand)
|
player.startUsingItem(hand)
|
||||||
return InteractionResultHolder.consume(player.getItemInHand(hand))
|
return InteractionResultHolder.consume(player.getItemInHand(hand))
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import net.minecraft.core.BlockPos
|
|||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.server.level.ServerPlayer
|
import net.minecraft.server.level.ServerPlayer
|
||||||
import net.minecraft.world.InteractionResult
|
import net.minecraft.world.InteractionResult
|
||||||
|
import net.minecraft.world.ItemInteractionResult
|
||||||
import net.minecraft.world.entity.player.Player
|
import net.minecraft.world.entity.player.Player
|
||||||
import net.minecraft.world.item.Item
|
import net.minecraft.world.item.Item
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
@ -20,13 +21,13 @@ class EssenceServoItem : MatteryItem(Properties().stacksTo(64)) {
|
|||||||
addSimpleDescription(formatting = ChatFormatting.DARK_GRAY)
|
addSimpleDescription(formatting = ChatFormatting.DARK_GRAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun useServo(player: Player, pos: BlockPos): InteractionResult {
|
fun useServo(player: Player, pos: BlockPos): ItemInteractionResult {
|
||||||
val block = player.level().getBlockEntity(pos) ?: return InteractionResult.FAIL
|
val block = player.level().getBlockEntity(pos) ?: return ItemInteractionResult.FAIL
|
||||||
|
|
||||||
// TODO: опыт как жидкость
|
// TODO: опыт как жидкость
|
||||||
if (block is EssenceStorageBlockEntity) {
|
if (block is EssenceStorageBlockEntity) {
|
||||||
if (player.level().isClientSide) return InteractionResult.SUCCESS
|
if (player.level().isClientSide) return ItemInteractionResult.SUCCESS
|
||||||
if (player !is ServerPlayer) return InteractionResult.FAIL
|
if (player !is ServerPlayer) return ItemInteractionResult.FAIL
|
||||||
|
|
||||||
if (player.isCrouching) { // выгружаем в блок
|
if (player.isCrouching) { // выгружаем в блок
|
||||||
storeLevel(player, block)
|
storeLevel(player, block)
|
||||||
@ -34,15 +35,15 @@ class EssenceServoItem : MatteryItem(Properties().stacksTo(64)) {
|
|||||||
dispenseLevel(player, block)
|
dispenseLevel(player, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
return InteractionResult.SUCCESS
|
return ItemInteractionResult.SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
return InteractionResult.FAIL
|
return ItemInteractionResult.FAIL
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun useOn(pContext: UseOnContext): InteractionResult {
|
override fun useOn(pContext: UseOnContext): InteractionResult {
|
||||||
val player = pContext.player ?: return InteractionResult.FAIL
|
val player = pContext.player ?: return InteractionResult.FAIL
|
||||||
return useServo(player, pContext.clickedPos)
|
return useServo(player, pContext.clickedPos).result()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -30,8 +30,8 @@ abstract class AbstractExopackSlotUpgradeItem(properties: Properties = defaultPr
|
|||||||
abstract fun slotCount(itemStack: ItemStack): Int
|
abstract fun slotCount(itemStack: ItemStack): Int
|
||||||
abstract fun uuid(itemStack: ItemStack): UUID?
|
abstract fun uuid(itemStack: ItemStack): UUID?
|
||||||
|
|
||||||
override fun canBeHurtBy(p_41387_: DamageSource): Boolean {
|
override fun canBeHurtBy(stack: ItemStack, source: DamageSource): Boolean {
|
||||||
return super.canBeHurtBy(p_41387_) && !p_41387_.isExplosion && !p_41387_.isFire
|
return super.canBeHurtBy(stack, source) && !source.isExplosion && !source.isFire
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUseDuration(p_41454_: ItemStack, p_344979_: LivingEntity): Int {
|
override fun getUseDuration(p_41454_: ItemStack, p_344979_: LivingEntity): Int {
|
||||||
|
@ -46,8 +46,8 @@ import ru.dbotthepony.mc.otm.triggers.NailedEntityTrigger
|
|||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
|
|
||||||
class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1).fireResistant().durability(durability)) {
|
class ExplosiveHammerItem(durability: Int = 512) : Item(Properties().stacksTo(1).fireResistant().durability(durability)) {
|
||||||
override fun canBeHurtBy(pDamageSource: DamageSource): Boolean {
|
override fun canBeHurtBy(stack: ItemStack, pDamageSource: DamageSource): Boolean {
|
||||||
return super.canBeHurtBy(pDamageSource) && !pDamageSource.isExplosion
|
return super.canBeHurtBy(stack, pDamageSource) && !pDamageSource.isExplosion
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isPrimed(itemStack: ItemStack): Boolean {
|
fun isPrimed(itemStack: ItemStack): Boolean {
|
||||||
|
@ -6,6 +6,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
|
|||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import net.minecraft.network.FriendlyByteBuf
|
import net.minecraft.network.FriendlyByteBuf
|
||||||
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
import net.minecraft.network.codec.StreamCodec
|
import net.minecraft.network.codec.StreamCodec
|
||||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload
|
||||||
import net.minecraft.server.level.ServerPlayer
|
import net.minecraft.server.level.ServerPlayer
|
||||||
@ -107,7 +108,7 @@ object ClearItemViewPacket : NetworkedItemViewPacket() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class StackAddPacket(val stackId: Int, val stack: ItemStorageStack) : NetworkedItemViewPacket() {
|
class StackAddPacket(val stackId: Int, val stack: ItemStorageStack) : NetworkedItemViewPacket() {
|
||||||
fun write(buff: FriendlyByteBuf) {
|
fun write(buff: RegistryFriendlyByteBuf) {
|
||||||
buff.writeInt(stackId)
|
buff.writeInt(stackId)
|
||||||
stack.write(buff)
|
stack.write(buff)
|
||||||
}
|
}
|
||||||
@ -134,10 +135,10 @@ class StackAddPacket(val stackId: Int, val stack: ItemStorageStack) : NetworkedI
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
val CODEC: StreamCodec<FriendlyByteBuf, StackAddPacket> =
|
val CODEC: StreamCodec<RegistryFriendlyByteBuf, StackAddPacket> =
|
||||||
StreamCodec.ofMember(StackAddPacket::write, ::read)
|
StreamCodec.ofMember(StackAddPacket::write, ::read)
|
||||||
|
|
||||||
fun read(buffer: FriendlyByteBuf): StackAddPacket {
|
fun read(buffer: RegistryFriendlyByteBuf): StackAddPacket {
|
||||||
val id = buffer.readInt()
|
val id = buffer.readInt()
|
||||||
val item = StorageStack.ITEMS.read(buffer)
|
val item = StorageStack.ITEMS.read(buffer)
|
||||||
return StackAddPacket(id, item)
|
return StackAddPacket(id, item)
|
||||||
|
@ -15,7 +15,7 @@ import kotlin.reflect.KMutableProperty0
|
|||||||
*
|
*
|
||||||
* Getting and setting values should ONLY be done clientside
|
* Getting and setting values should ONLY be done clientside
|
||||||
*/
|
*/
|
||||||
interface IPlayerInputWithFeedback<V> : ListenableDelegate<V>, Predicate<Player?>
|
interface IPlayerInputWithFeedback<V> : ListenableDelegate<V>, Predicate<Player>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents Server to Client synchronization and Client to Server input
|
* Represents Server to Client synchronization and Client to Server input
|
||||||
@ -40,7 +40,7 @@ abstract class AbstractPlayerInputWithFeedback<V> : IPlayerInputWithFeedback<V>
|
|||||||
input.accept(t)
|
input.accept(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun test(player: Player?) = input.test(player)
|
override fun test(player: Player) = input.test(player)
|
||||||
fun filter(filter: Predicate<Player>) = input.filter(filter)
|
fun filter(filter: Predicate<Player>) = input.filter(filter)
|
||||||
|
|
||||||
var supplier: (() -> V)? = null
|
var supplier: (() -> V)? = null
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package ru.dbotthepony.mc.otm.menu.input
|
package ru.dbotthepony.mc.otm.menu.input
|
||||||
|
|
||||||
import ru.dbotthepony.kommons.io.StreamCodec
|
import net.minecraft.network.RegistryFriendlyByteBuf
|
||||||
import ru.dbotthepony.kommons.util.Delegate
|
import ru.dbotthepony.kommons.util.Delegate
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
|
import ru.dbotthepony.mc.otm.network.MatteryStreamCodec
|
||||||
import kotlin.reflect.KMutableProperty0
|
import kotlin.reflect.KMutableProperty0
|
||||||
|
|
||||||
inline fun <reified E : Enum<E>> EnumInputWithFeedback(menu: MatteryMenu, allowedValues: Set<E>? = null) = EnumInputWithFeedback(menu, E::class.java, allowedValues = allowedValues)
|
inline fun <reified E : Enum<E>> EnumInputWithFeedback(menu: MatteryMenu, allowedValues: Set<E>? = null) = EnumInputWithFeedback(menu, E::class.java, allowedValues = allowedValues)
|
||||||
@ -14,7 +15,7 @@ inline fun <reified E : Enum<E>> EnumInputWithFeedback(menu: MatteryMenu, allowS
|
|||||||
inline fun <reified E : Enum<E>> EnumInputWithFeedback(menu: MatteryMenu, allowSpectators: Boolean, state: Delegate<E>?, allowedValues: Set<E>? = null) = EnumInputWithFeedback(menu, E::class.java, allowSpectators, state, allowedValues = allowedValues)
|
inline fun <reified E : Enum<E>> EnumInputWithFeedback(menu: MatteryMenu, allowSpectators: Boolean, state: Delegate<E>?, allowedValues: Set<E>? = null) = EnumInputWithFeedback(menu, E::class.java, allowSpectators, state, allowedValues = allowedValues)
|
||||||
|
|
||||||
class EnumInputWithFeedback<E : Enum<E>>(menu: MatteryMenu, clazz: Class<E>, allowSpectators: Boolean = false, val allowedValues: Set<E>? = null) : AbstractPlayerInputWithFeedback<E>() {
|
class EnumInputWithFeedback<E : Enum<E>>(menu: MatteryMenu, clazz: Class<E>, allowSpectators: Boolean = false, val allowedValues: Set<E>? = null) : AbstractPlayerInputWithFeedback<E>() {
|
||||||
val codec = StreamCodec.Enum(clazz)
|
val codec = MatteryStreamCodec.Enum<RegistryFriendlyByteBuf, E>(clazz)
|
||||||
private val default = codec.values.first()
|
private val default = codec.values.first()
|
||||||
|
|
||||||
override val input = menu.PlayerInput(codec, allowSpectators) { if (allowedValues == null || it in allowedValues) consumer?.invoke(it) }
|
override val input = menu.PlayerInput(codec, allowSpectators) { if (allowedValues == null || it in allowedValues) consumer?.invoke(it) }
|
||||||
|
@ -10,7 +10,6 @@ import net.minecraft.world.item.Item
|
|||||||
import net.neoforged.neoforge.network.PacketDistributor
|
import net.neoforged.neoforge.network.PacketDistributor
|
||||||
import net.neoforged.neoforge.network.handling.IPayloadContext
|
import net.neoforged.neoforge.network.handling.IPayloadContext
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.kommons.io.NullValueCodec
|
|
||||||
import ru.dbotthepony.kommons.util.getValue
|
import ru.dbotthepony.kommons.util.getValue
|
||||||
import ru.dbotthepony.kommons.util.setValue
|
import ru.dbotthepony.kommons.util.setValue
|
||||||
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
import ru.dbotthepony.mc.otm.OverdriveThatMatters
|
||||||
@ -21,14 +20,13 @@ import ru.dbotthepony.mc.otm.core.ResourceLocation
|
|||||||
import ru.dbotthepony.mc.otm.core.addSorted
|
import ru.dbotthepony.mc.otm.core.addSorted
|
||||||
import ru.dbotthepony.mc.otm.core.map
|
import ru.dbotthepony.mc.otm.core.map
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.util.DecimalValueCodec
|
|
||||||
import ru.dbotthepony.mc.otm.core.util.writeCollection
|
import ru.dbotthepony.mc.otm.core.util.writeCollection
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphListener
|
import ru.dbotthepony.mc.otm.graph.matter.IMatterGraphListener
|
||||||
import ru.dbotthepony.mc.otm.graph.matter.MatterGraph
|
import ru.dbotthepony.mc.otm.graph.matter.MatterGraph
|
||||||
import ru.dbotthepony.mc.otm.menu.IItemSortingSettings
|
import ru.dbotthepony.mc.otm.menu.IItemSortingSettings
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.network.*
|
import ru.dbotthepony.mc.otm.network.StreamCodecs
|
||||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.function.Predicate
|
import java.util.function.Predicate
|
||||||
@ -201,11 +199,11 @@ class MatterPanelMenu(
|
|||||||
val settings = IItemSortingSettings.inputs(this, tile?.getPlayerSettings(player), ::updateComparators)
|
val settings = IItemSortingSettings.inputs(this, tile?.getPlayerSettings(player), ::updateComparators)
|
||||||
|
|
||||||
var isProvidingTasks by BooleanInputWithFeedback(this, tile?.let { it::isProvidingTasks })
|
var isProvidingTasks by BooleanInputWithFeedback(this, tile?.let { it::isProvidingTasks })
|
||||||
val cancelAll = PlayerInput(NullValueCodec) { tile?.dropAllTasks() }
|
val cancelAll = PlayerInput(StreamCodecs.NOTHING) { tile?.dropAllTasks() }
|
||||||
|
|
||||||
val totalMatterStored: Decimal by mSynchronizer.computed(
|
val totalMatterStored: Decimal by mSynchronizer.computed(
|
||||||
delegate = { tile?.matterNode?.graph?.getMatterStorageLevel() ?: Decimal.ZERO },
|
delegate = { tile?.matterNode?.graph?.getMatterStorageLevel() ?: Decimal.ZERO },
|
||||||
codec = DecimalValueCodec,
|
codec = StreamCodecs.DECIMAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
var filter: Predicate<Item> = Predicate { true }
|
var filter: Predicate<Item> = Predicate { true }
|
||||||
|
@ -4,7 +4,7 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.mc.otm.block.entity.storage.StorageBusBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.storage.StorageBusBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
import ru.dbotthepony.mc.otm.capability.FlowDirection
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.addFilterControls
|
||||||
import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput
|
import ru.dbotthepony.mc.otm.menu.input.EnergyConfigPlayerInput
|
||||||
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.menu.input.IntInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.IntInputWithFeedback
|
||||||
@ -16,8 +16,7 @@ class StorageBusMenu(
|
|||||||
inventory: Inventory,
|
inventory: Inventory,
|
||||||
tile: StorageBusBlockEntity? = null
|
tile: StorageBusBlockEntity? = null
|
||||||
) : MatteryPoweredMenu(MMenus.STORAGE_BUS, containerId, inventory, tile) {
|
) : MatteryPoweredMenu(MMenus.STORAGE_BUS, containerId, inventory, tile) {
|
||||||
val busFilterSlots = addFilterSlots(tile?.filter, StorageBusBlockEntity.MAX_FILTERS)
|
val filter = addFilterControls(tile?.let { it::filter }, StorageBusBlockEntity.MAX_FILTERS)
|
||||||
val busFilterState = BooleanInputWithFeedback(this, tile?.let { it.filter::isWhitelist })
|
|
||||||
val insertPriority = IntInputWithFeedback(this, tile?.let { it::insertPriority })
|
val insertPriority = IntInputWithFeedback(this, tile?.let { it::insertPriority })
|
||||||
val extractPriority = IntInputWithFeedback(this, tile?.let { it::extractPriority })
|
val extractPriority = IntInputWithFeedback(this, tile?.let { it::extractPriority })
|
||||||
val profiledEnergy = ProfiledLevelGaugeWidget(this, tile?.energy, energyWidget)
|
val profiledEnergy = ProfiledLevelGaugeWidget(this, tile?.energy, energyWidget)
|
||||||
|
@ -4,7 +4,6 @@ import net.minecraft.world.entity.player.Inventory
|
|||||||
import ru.dbotthepony.kommons.util.getValue
|
import ru.dbotthepony.kommons.util.getValue
|
||||||
import ru.dbotthepony.kommons.util.setValue
|
import ru.dbotthepony.kommons.util.setValue
|
||||||
import ru.dbotthepony.mc.otm.block.entity.storage.StoragePowerSupplierBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.storage.StoragePowerSupplierBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.core.util.decimal
|
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||||
|
|
||||||
|
@ -11,13 +11,12 @@ import ru.dbotthepony.mc.otm.block.tech.EnergyCounterBlock
|
|||||||
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyCounterBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.tech.EnergyCounterBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.math.toDecimal
|
import ru.dbotthepony.mc.otm.core.math.toDecimal
|
||||||
import ru.dbotthepony.mc.otm.core.util.decimal
|
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.EnumInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.registry.MMenus
|
import ru.dbotthepony.mc.otm.registry.MMenus
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
class EnergyCounterMenu @JvmOverloads constructor(
|
class EnergyCounterMenu(
|
||||||
p_38852_: Int,
|
p_38852_: Int,
|
||||||
inventory: Inventory,
|
inventory: Inventory,
|
||||||
tile: EnergyCounterBlockEntity? = null
|
tile: EnergyCounterBlockEntity? = null
|
||||||
|
@ -4,6 +4,8 @@ import net.minecraft.server.level.ServerPlayer
|
|||||||
import net.minecraft.world.SimpleContainer
|
import net.minecraft.world.SimpleContainer
|
||||||
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.enchantment.EnchantmentEffectComponents
|
||||||
|
import net.minecraft.world.item.enchantment.EnchantmentHelper
|
||||||
import net.minecraft.world.item.enchantment.Enchantments
|
import net.minecraft.world.item.enchantment.Enchantments
|
||||||
import ru.dbotthepony.kommons.util.getValue
|
import ru.dbotthepony.kommons.util.getValue
|
||||||
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
import ru.dbotthepony.mc.otm.block.entity.RedstoneSetting
|
||||||
@ -44,7 +46,7 @@ class EssenceStorageMenu(
|
|||||||
|
|
||||||
val mendingSlot = object : MatterySlot(tile?.mendingContainer ?: SimpleContainer(1), 0) {
|
val mendingSlot = object : MatterySlot(tile?.mendingContainer ?: SimpleContainer(1), 0) {
|
||||||
override fun mayPlace(itemStack: ItemStack): Boolean {
|
override fun mayPlace(itemStack: ItemStack): Boolean {
|
||||||
return itemStack.isDamaged && itemStack.getEnchantmentLevel(Enchantments.MENDING) > 0
|
return itemStack.isDamaged && EnchantmentHelper.has(itemStack, EnchantmentEffectComponents.REPAIR_WITH_XP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ import net.neoforged.neoforge.fluids.capability.IFluidHandler
|
|||||||
import ru.dbotthepony.mc.otm.network.DelegateSyncher
|
import ru.dbotthepony.mc.otm.network.DelegateSyncher
|
||||||
import ru.dbotthepony.kommons.util.getValue
|
import ru.dbotthepony.kommons.util.getValue
|
||||||
import ru.dbotthepony.mc.otm.container.get
|
import ru.dbotthepony.mc.otm.container.get
|
||||||
import ru.dbotthepony.mc.otm.core.util.FluidStackValueCodec
|
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
|
import ru.dbotthepony.mc.otm.network.wrap
|
||||||
import java.util.function.IntSupplier
|
import java.util.function.IntSupplier
|
||||||
import java.util.function.Supplier
|
import java.util.function.Supplier
|
||||||
|
|
||||||
@ -14,10 +14,10 @@ class FluidGaugeWidget(synchronizer: DelegateSyncher) {
|
|||||||
constructor(menu: MatteryMenu) : this(menu.mSynchronizer)
|
constructor(menu: MatteryMenu) : this(menu.mSynchronizer)
|
||||||
|
|
||||||
var maxCapacitySupplier = IntSupplier { 0 }
|
var maxCapacitySupplier = IntSupplier { 0 }
|
||||||
var fluidSupplier = Supplier { FluidStack.EMPTY!! }
|
var fluidSupplier = Supplier { FluidStack.EMPTY }
|
||||||
|
|
||||||
val maxCapacity by synchronizer.computedInt(IntSupplier { maxCapacitySupplier.asInt })
|
val maxCapacity by synchronizer.computedInt(IntSupplier { maxCapacitySupplier.asInt })
|
||||||
val fluid by synchronizer.computed({ fluidSupplier.get() }, FluidStackValueCodec)
|
val fluid by synchronizer.computed({ fluidSupplier.get() }, FluidStack.STREAM_CODEC.wrap())
|
||||||
|
|
||||||
val percentage: Float get() {
|
val percentage: Float get() {
|
||||||
if (maxCapacity <= 0 || fluid.isEmpty) {
|
if (maxCapacity <= 0 || fluid.isEmpty) {
|
||||||
|
@ -6,8 +6,8 @@ import ru.dbotthepony.mc.otm.capability.energy.IMatteryEnergyStorage
|
|||||||
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.IPatternStorage
|
import ru.dbotthepony.mc.otm.capability.matter.IPatternStorage
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.util.DecimalValueCodec
|
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
|
import ru.dbotthepony.mc.otm.network.StreamCodecs
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
class LevelGaugeWidget(synchronizer: DelegateSyncher) {
|
class LevelGaugeWidget(synchronizer: DelegateSyncher) {
|
||||||
@ -16,8 +16,8 @@ class LevelGaugeWidget(synchronizer: DelegateSyncher) {
|
|||||||
var levelProvider = { Decimal.ONE }
|
var levelProvider = { Decimal.ONE }
|
||||||
var maxLevelProvider = { Decimal.ONE }
|
var maxLevelProvider = { Decimal.ONE }
|
||||||
|
|
||||||
val level by synchronizer.computed(delegate = { levelProvider.invoke() }, codec = DecimalValueCodec)
|
val level by synchronizer.computed(delegate = { levelProvider.invoke() }, codec = StreamCodecs.DECIMAL)
|
||||||
val maxLevel by synchronizer.computed(delegate = { maxLevelProvider.invoke() }, codec = DecimalValueCodec)
|
val maxLevel by synchronizer.computed(delegate = { maxLevelProvider.invoke() }, codec = StreamCodecs.DECIMAL)
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
menu: MatteryMenu,
|
menu: MatteryMenu,
|
||||||
|
@ -8,9 +8,9 @@ import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage
|
|||||||
import ru.dbotthepony.mc.otm.core.collect.SupplierList
|
import ru.dbotthepony.mc.otm.core.collect.SupplierList
|
||||||
import ru.dbotthepony.mc.otm.core.immutableList
|
import ru.dbotthepony.mc.otm.core.immutableList
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.core.util.DecimalValueCodec
|
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
|
||||||
|
import ru.dbotthepony.mc.otm.network.StreamCodecs
|
||||||
import java.util.function.IntSupplier
|
import java.util.function.IntSupplier
|
||||||
|
|
||||||
class ProfiledLevelGaugeWidget<P : AbstractProfiledStorage<*>>(synchronizer: DelegateSyncher, val gauge: LevelGaugeWidget = LevelGaugeWidget(synchronizer)) {
|
class ProfiledLevelGaugeWidget<P : AbstractProfiledStorage<*>>(synchronizer: DelegateSyncher, val gauge: LevelGaugeWidget = LevelGaugeWidget(synchronizer)) {
|
||||||
@ -18,19 +18,19 @@ class ProfiledLevelGaugeWidget<P : AbstractProfiledStorage<*>>(synchronizer: Del
|
|||||||
private set
|
private set
|
||||||
|
|
||||||
val historyReceive = immutableList(AbstractProfiledStorage.HISTORY_SIZE) {
|
val historyReceive = immutableList(AbstractProfiledStorage.HISTORY_SIZE) {
|
||||||
synchronizer.computed({ parent?.historyReceive?.get(it) ?: Decimal.ZERO }, DecimalValueCodec)
|
synchronizer.computed({ parent?.historyReceive?.get(it) ?: Decimal.ZERO }, StreamCodecs.DECIMAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
val historyTransfer = immutableList(AbstractProfiledStorage.HISTORY_SIZE) {
|
val historyTransfer = immutableList(AbstractProfiledStorage.HISTORY_SIZE) {
|
||||||
synchronizer.computed({ parent?.historyTransfer?.get(it) ?: Decimal.ZERO }, DecimalValueCodec)
|
synchronizer.computed({ parent?.historyTransfer?.get(it) ?: Decimal.ZERO }, StreamCodecs.DECIMAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
val directHistoryReceive = SupplierList(historyReceive)
|
val directHistoryReceive = SupplierList(historyReceive)
|
||||||
val directHistoryTransfer = SupplierList(historyTransfer)
|
val directHistoryTransfer = SupplierList(historyTransfer)
|
||||||
|
|
||||||
val tick by synchronizer.computedInt(IntSupplier { parent?.tick ?: 0 })
|
val tick by synchronizer.computedInt(IntSupplier { parent?.tick ?: 0 })
|
||||||
val lastTickReceive by synchronizer.computed({ parent?.lastTickReceive ?: Decimal.ZERO }, DecimalValueCodec)
|
val lastTickReceive by synchronizer.computed({ parent?.lastTickReceive ?: Decimal.ZERO }, StreamCodecs.DECIMAL)
|
||||||
val lastTickTransfer by synchronizer.computed({ parent?.lastTickTransfer ?: Decimal.ZERO }, DecimalValueCodec)
|
val lastTickTransfer by synchronizer.computed({ parent?.lastTickTransfer ?: Decimal.ZERO }, StreamCodecs.DECIMAL)
|
||||||
|
|
||||||
constructor(synchronizer: DelegateSyncher, storage: P?, gauge: LevelGaugeWidget = LevelGaugeWidget(synchronizer)) : this(synchronizer, gauge = gauge) {
|
constructor(synchronizer: DelegateSyncher, storage: P?, gauge: LevelGaugeWidget = LevelGaugeWidget(synchronizer)) : this(synchronizer, gauge = gauge) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.mc.otm.network
|
package ru.dbotthepony.mc.otm.network
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.bytes.ByteArrayList
|
||||||
import it.unimi.dsi.fastutil.io.FastByteArrayInputStream
|
import it.unimi.dsi.fastutil.io.FastByteArrayInputStream
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectFunction
|
import it.unimi.dsi.fastutil.objects.Object2ObjectFunction
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
|
||||||
@ -20,20 +21,20 @@ import ru.dbotthepony.mc.otm.core.collect.reduce
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class BlockEntitySyncPacket(val position: BlockPos, val buffer: ByteArray, val validBytes: Int) : CustomPacketPayload {
|
class BlockEntitySyncPacket(val position: BlockPos, val buffer: ByteArrayList) : CustomPacketPayload {
|
||||||
fun write(buff: FriendlyByteBuf) {
|
fun write(buff: FriendlyByteBuf) {
|
||||||
buff.writeBlockPos(position)
|
buff.writeBlockPos(position)
|
||||||
buff.writeBytes(buffer, 0, validBytes)
|
buff.writeByteListUnbounded(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun execute() {
|
fun play(context: IPayloadContext) {
|
||||||
val level = minecraft.player?.level()
|
val level = minecraft.player?.level()
|
||||||
|
|
||||||
if (level == null) {
|
if (level == null) {
|
||||||
LOGGER.error("Received BlockEntitySyncPacket before we are in valid level.")
|
LOGGER.error("Received BlockEntitySyncPacket before we are in valid level.")
|
||||||
|
|
||||||
onceClient {
|
onceClient {
|
||||||
execute()
|
play(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -45,7 +46,7 @@ class BlockEntitySyncPacket(val position: BlockPos, val buffer: ByteArray, val v
|
|||||||
val list = backlog.computeIfAbsent(level) { Object2ObjectOpenHashMap() }
|
val list = backlog.computeIfAbsent(level) { Object2ObjectOpenHashMap() }
|
||||||
.computeIfAbsent(position, Object2ObjectFunction { ArrayList() })
|
.computeIfAbsent(position, Object2ObjectFunction { ArrayList() })
|
||||||
|
|
||||||
list.add(buffer.copyOf(validBytes))
|
list.add(buffer)
|
||||||
LOGGER.warn("Putting BlockEntitySyncPacket received for $position into backlog (size: ${list.iterator().map { it.size }.reduce(0, Int::plus)} bytes) because there is literally no block entity there! This might cause memory leak.")
|
LOGGER.warn("Putting BlockEntitySyncPacket received for $position into backlog (size: ${list.iterator().map { it.size }.reduce(0, Int::plus)} bytes) because there is literally no block entity there! This might cause memory leak.")
|
||||||
return
|
return
|
||||||
} else if (blockEntity !is MatteryBlockEntity) {
|
} else if (blockEntity !is MatteryBlockEntity) {
|
||||||
@ -61,36 +62,28 @@ class BlockEntitySyncPacket(val position: BlockPos, val buffer: ByteArray, val v
|
|||||||
LOGGER.info("Unfolding ${packets.size} backlog packets for $position (${level.getBlockState(position)}/$blockEntity)")
|
LOGGER.info("Unfolding ${packets.size} backlog packets for $position (${level.getBlockState(position)}/$blockEntity)")
|
||||||
|
|
||||||
for (packet in packets) {
|
for (packet in packets) {
|
||||||
blockEntity.syncher.read(FastByteArrayInputStream(packet))
|
blockEntity.syncher.read(context.player().registryAccess(), packet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blockEntity.syncher.read(FastByteArrayInputStream(buffer, 0, validBytes))
|
blockEntity.syncher.read(context.player().registryAccess(), buffer)
|
||||||
} catch(err: Throwable) {
|
} catch(err: Throwable) {
|
||||||
LOGGER.error("Exception while reading synchronized BlockEntity data!\nPosition: $position\nBlock: ${level.getBlockState(position)}\nBlock entity: $blockEntity", err)
|
LOGGER.error("Exception while reading synchronized BlockEntity data!\nPosition: $position\nBlock: ${level.getBlockState(position)}\nBlock entity: $blockEntity", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun play(context: IPayloadContext) {
|
|
||||||
execute()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun type(): CustomPacketPayload.Type<out CustomPacketPayload> {
|
override fun type(): CustomPacketPayload.Type<out CustomPacketPayload> {
|
||||||
return TYPE
|
return TYPE
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val backlog = WeakHashMap<Level, Object2ObjectOpenHashMap<BlockPos, ArrayList<ByteArray>>>()
|
private val backlog = WeakHashMap<Level, Object2ObjectOpenHashMap<BlockPos, ArrayList<ByteArrayList>>>()
|
||||||
|
|
||||||
val CODEC: StreamCodec<FriendlyByteBuf, BlockEntitySyncPacket> = StreamCodec.ofMember(BlockEntitySyncPacket::write, ::read)
|
val CODEC: StreamCodec<FriendlyByteBuf, BlockEntitySyncPacket> = StreamCodec.ofMember(BlockEntitySyncPacket::write, ::read)
|
||||||
val TYPE = CustomPacketPayload.Type<BlockEntitySyncPacket>(ResourceLocation(OverdriveThatMatters.MOD_ID, "block_entity_data"))
|
val TYPE = CustomPacketPayload.Type<BlockEntitySyncPacket>(ResourceLocation(OverdriveThatMatters.MOD_ID, "block_entity_data"))
|
||||||
|
|
||||||
fun read(buff: FriendlyByteBuf): BlockEntitySyncPacket {
|
fun read(buff: FriendlyByteBuf): BlockEntitySyncPacket {
|
||||||
val position = buff.readBlockPos()
|
return BlockEntitySyncPacket(buff.readBlockPos(), buff.readByteListUnbounded())
|
||||||
val size = buff.readableBytes()
|
|
||||||
val array = ByteArray(size)
|
|
||||||
buff.readBytes(array)
|
|
||||||
return BlockEntitySyncPacket(position, array, size)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val LOGGER = LogManager.getLogger()
|
private val LOGGER = LogManager.getLogger()
|
||||||
@ -103,7 +96,7 @@ class BlockEntitySyncPacket(val position: BlockPos, val buffer: ByteArray, val v
|
|||||||
LOGGER.info("Unfolding ${packets.size} backlog packets (size: ${packets.iterator().map { it.size }.reduce(0, Int::plus)} bytes) for ${blockEntity.blockPos} (${blockEntity.level!!.getBlockState(blockEntity.blockPos)}/$blockEntity)")
|
LOGGER.info("Unfolding ${packets.size} backlog packets (size: ${packets.iterator().map { it.size }.reduce(0, Int::plus)} bytes) for ${blockEntity.blockPos} (${blockEntity.level!!.getBlockState(blockEntity.blockPos)}/$blockEntity)")
|
||||||
|
|
||||||
for (packet in packets) {
|
for (packet in packets) {
|
||||||
blockEntity.syncher.read(FastByteArrayInputStream(packet))
|
blockEntity.syncher.read(blockEntity.level!!.registryAccess(), packet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(err: Throwable) {
|
} catch(err: Throwable) {
|
||||||
|
Loading…
Reference in New Issue
Block a user