Update Pattern storage to use SlottedContainer
This commit is contained in:
parent
caa8d1bb90
commit
d1a9825ea8
@ -1,8 +1,8 @@
|
||||
package ru.dbotthepony.mc.otm.block.entity.matter
|
||||
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||
import ru.dbotthepony.mc.otm.block.matter.PatternStorageBlock
|
||||
@ -14,7 +14,8 @@ import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.level.block.Block
|
||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||
import ru.dbotthepony.mc.otm.capability.matter.*
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.slotted.ContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.collect.filterNotNull
|
||||
import ru.dbotthepony.mc.otm.core.collect.map
|
||||
import ru.dbotthepony.mc.otm.core.filterNotNull
|
||||
@ -23,53 +24,48 @@ import ru.dbotthepony.mc.otm.graph.matter.SimpleMatterNode
|
||||
import ru.dbotthepony.mc.otm.registry.game.MBlockEntities
|
||||
import java.util.stream.Stream
|
||||
|
||||
class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
||||
MatteryDeviceBlockEntity(MBlockEntities.PATTERN_STORAGE, p_155229_, p_155230_), IPatternStorage {
|
||||
|
||||
class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.PATTERN_STORAGE, p_155229_, p_155230_), IPatternStorage {
|
||||
val matterNode = SimpleMatterNode(patterns = this)
|
||||
|
||||
val container: MatteryContainer = object : MatteryContainer(::markDirtyFast, 8) {
|
||||
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
||||
if (!ItemStack.isSameItemSameComponents(new, old)) {
|
||||
private inner class Slot(container: SlottedContainer, slot: Int) : ContainerSlot(container, slot) {
|
||||
override val maxStackSize: Int
|
||||
get() = 1
|
||||
|
||||
override fun canAutomationPlaceItem(itemStack: ItemStack): Boolean {
|
||||
return super.canAutomationPlaceItem(itemStack) && itemStack.getCapability(MatteryCapability.PATTERN_ITEM) != null
|
||||
}
|
||||
|
||||
override fun canAutomationTakeItem(desired: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun notifyChanged(old: ItemStack) {
|
||||
if (!ItemStack.isSameItemSameComponents(item, old)) {
|
||||
if (!old.isEmpty) {
|
||||
old.getCapability(MatteryCapability.PATTERN_ITEM)?.let { cap: IPatternStorage ->
|
||||
cap.patterns.forEach { matterNode.graph.onPatternRemoved(it) }
|
||||
}
|
||||
}
|
||||
|
||||
if (!new.isEmpty) {
|
||||
new.getCapability(MatteryCapability.PATTERN_ITEM)?.let { cap: IPatternStorage ->
|
||||
if (!item.isEmpty) {
|
||||
item.getCapability(MatteryCapability.PATTERN_ITEM)?.let { cap: IPatternStorage ->
|
||||
cap.patterns.forEach { matterNode.graph.onPatternAdded(it) }
|
||||
}
|
||||
}
|
||||
|
||||
updateBlockstate()
|
||||
val level = level
|
||||
|
||||
if (level is ServerLevel) {
|
||||
level.setBlock(blockPos, blockState.setValue(PatternStorageBlock.PATTERN_STORAGE_DISKS_PROPS[slot], item.getCapability(MatteryCapability.PATTERN_ITEM) != null), Block.UPDATE_CLIENTS)
|
||||
}
|
||||
}
|
||||
|
||||
super.setChanged(slot, new, old)
|
||||
}
|
||||
|
||||
override fun getMaxStackSize(): Int = 1
|
||||
}.also(::addDroppableContainer)
|
||||
|
||||
private fun updateBlockstate() {
|
||||
val level = level ?: return
|
||||
|
||||
var state = blockState
|
||||
|
||||
for (i in 0..7) {
|
||||
state = state.setValue(
|
||||
PatternStorageBlock.PATTERN_STORAGE_DISKS_PROPS[i],
|
||||
this.container.getItem(i).getCapability(MatteryCapability.PATTERN_ITEM) != null
|
||||
)
|
||||
}
|
||||
|
||||
if (state !== blockState) {
|
||||
level.setBlock(blockPos, state, Block.UPDATE_CLIENTS)
|
||||
super.notifyChanged(old)
|
||||
}
|
||||
}
|
||||
|
||||
val itemConfig = ConfigurableItemHandler(inputOutput = container.handler(HandlerFilter.IsPattern.and(HandlerFilter.OnlyIn)))
|
||||
val container = SlottedContainer.simple(2 * 4, ::Slot, ::markDirtyFast).also(::addDroppableContainer)
|
||||
val itemConfig = ConfigurableItemHandler(inputOutput = container)
|
||||
|
||||
override fun setLevel(level: Level) {
|
||||
super.setLevel(level)
|
||||
|
@ -4,6 +4,7 @@ import net.minecraft.world.SimpleContainer
|
||||
import net.minecraft.world.entity.player.Inventory
|
||||
import ru.dbotthepony.mc.otm.core.immutableList
|
||||
import ru.dbotthepony.mc.otm.block.entity.matter.PatternStorageBlockEntity
|
||||
import ru.dbotthepony.mc.otm.container.EnhancedContainer
|
||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||
import ru.dbotthepony.mc.otm.menu.PatternMenuSlot
|
||||
@ -31,9 +32,9 @@ class PatternStorageMenu @JvmOverloads constructor(
|
||||
})
|
||||
}
|
||||
|
||||
val patterns = tile?.container ?: SimpleContainer(2 * 4)
|
||||
val patterns = tile?.container ?: EnhancedContainer(2 * 4)
|
||||
|
||||
storageSlots = immutableList(2 * 4) {
|
||||
storageSlots = immutableList(patterns.containerSize) {
|
||||
addStorageSlot(PatternMenuSlot(patterns, it))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user