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
|
package ru.dbotthepony.mc.otm.block.entity.matter
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos
|
import net.minecraft.core.BlockPos
|
||||||
|
import net.minecraft.server.level.ServerLevel
|
||||||
import net.minecraft.world.level.block.state.BlockState
|
import net.minecraft.world.level.block.state.BlockState
|
||||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
import ru.dbotthepony.mc.otm.block.matter.PatternStorageBlock
|
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 net.minecraft.world.level.block.Block
|
||||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||||
import ru.dbotthepony.mc.otm.capability.matter.*
|
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.filterNotNull
|
||||||
import ru.dbotthepony.mc.otm.core.collect.map
|
import ru.dbotthepony.mc.otm.core.collect.map
|
||||||
import ru.dbotthepony.mc.otm.core.filterNotNull
|
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 ru.dbotthepony.mc.otm.registry.game.MBlockEntities
|
||||||
import java.util.stream.Stream
|
import java.util.stream.Stream
|
||||||
|
|
||||||
class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) :
|
class PatternStorageBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.PATTERN_STORAGE, p_155229_, p_155230_), IPatternStorage {
|
||||||
MatteryDeviceBlockEntity(MBlockEntities.PATTERN_STORAGE, p_155229_, p_155230_), IPatternStorage {
|
|
||||||
|
|
||||||
val matterNode = SimpleMatterNode(patterns = this)
|
val matterNode = SimpleMatterNode(patterns = this)
|
||||||
|
|
||||||
val container: MatteryContainer = object : MatteryContainer(::markDirtyFast, 8) {
|
private inner class Slot(container: SlottedContainer, slot: Int) : ContainerSlot(container, slot) {
|
||||||
override fun setChanged(slot: Int, new: ItemStack, old: ItemStack) {
|
override val maxStackSize: Int
|
||||||
if (!ItemStack.isSameItemSameComponents(new, old)) {
|
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) {
|
if (!old.isEmpty) {
|
||||||
old.getCapability(MatteryCapability.PATTERN_ITEM)?.let { cap: IPatternStorage ->
|
old.getCapability(MatteryCapability.PATTERN_ITEM)?.let { cap: IPatternStorage ->
|
||||||
cap.patterns.forEach { matterNode.graph.onPatternRemoved(it) }
|
cap.patterns.forEach { matterNode.graph.onPatternRemoved(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!new.isEmpty) {
|
if (!item.isEmpty) {
|
||||||
new.getCapability(MatteryCapability.PATTERN_ITEM)?.let { cap: IPatternStorage ->
|
item.getCapability(MatteryCapability.PATTERN_ITEM)?.let { cap: IPatternStorage ->
|
||||||
cap.patterns.forEach { matterNode.graph.onPatternAdded(it) }
|
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)
|
super.notifyChanged(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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
override fun setLevel(level: Level) {
|
||||||
super.setLevel(level)
|
super.setLevel(level)
|
||||||
|
@ -4,6 +4,7 @@ import net.minecraft.world.SimpleContainer
|
|||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import ru.dbotthepony.mc.otm.core.immutableList
|
import ru.dbotthepony.mc.otm.core.immutableList
|
||||||
import ru.dbotthepony.mc.otm.block.entity.matter.PatternStorageBlockEntity
|
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.core.math.Decimal
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import ru.dbotthepony.mc.otm.menu.PatternMenuSlot
|
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))
|
addStorageSlot(PatternMenuSlot(patterns, it))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user