Move Painter to SlottedContainer
This commit is contained in:
parent
4292713874
commit
3ed935001b
@ -20,6 +20,8 @@ import net.neoforged.neoforge.fluids.capability.IFluidHandler
|
||||
import ru.dbotthepony.mc.otm.block.entity.MatteryDeviceBlockEntity
|
||||
import ru.dbotthepony.mc.otm.container.HandlerFilter
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.slotted.ContainerSlot
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.immutableList
|
||||
import ru.dbotthepony.mc.otm.core.immutableMap
|
||||
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
||||
@ -34,7 +36,39 @@ class PainterBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryDe
|
||||
return PainterMenu(containerID, inventory, this)
|
||||
}
|
||||
|
||||
val dyeInput = MatteryContainer(this::markDirtyFast, 1)
|
||||
private inner class InputSlot(container: SlottedContainer, slot: Int) : ContainerSlot(container, slot) {
|
||||
override fun canAutomationPlaceItem(itemStack: ItemStack): Boolean {
|
||||
if (!super.canAutomationPlaceItem(itemStack))
|
||||
return false
|
||||
|
||||
if (waterStored() < MAX_WATER_STORAGE) {
|
||||
itemStack.getCapability(Capabilities.FluidHandler.ITEM)?.let {
|
||||
val drain = it.drain(FluidStack(Fluids.WATER, MAX_WATER_STORAGE - waterStored()), IFluidHandler.FluidAction.SIMULATE)
|
||||
|
||||
if (drain.isNotEmpty) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val dye = DyeColor.getColor(itemStack) ?: return false
|
||||
return dyeStored(dye) + HUE_PER_ITEM <= MAX_STORAGE
|
||||
}
|
||||
|
||||
override fun canAutomationTakeItem(desired: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun modifyAutomationPlaceCount(itemStack: ItemStack): Int {
|
||||
if (itemStack.getCapability(Capabilities.FluidHandler.ITEM) != null)
|
||||
return 1
|
||||
|
||||
val dye = DyeColor.getColor(itemStack) ?: return 0
|
||||
return itemStack.count.coerceAtMost((MAX_STORAGE - dyeStored(dye)) / HUE_PER_ITEM - item.count)
|
||||
}
|
||||
}
|
||||
|
||||
val dyeInput = SlottedContainer.simple(1, ::InputSlot, ::markDirtyFast)
|
||||
// null - water
|
||||
val dyeStored = Object2IntArrayMap<DyeColor?>()
|
||||
|
||||
@ -108,34 +142,7 @@ class PainterBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryDe
|
||||
markDirtyFast()
|
||||
}
|
||||
|
||||
val config = ConfigurableItemHandler(input = dyeInput.handler(object : HandlerFilter {
|
||||
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
|
||||
if (waterStored() < MAX_WATER_STORAGE) {
|
||||
stack.getCapability(Capabilities.FluidHandler.ITEM)?.let {
|
||||
val drain = it.drain(FluidStack(Fluids.WATER, MAX_WATER_STORAGE - waterStored()), IFluidHandler.FluidAction.SIMULATE)
|
||||
|
||||
if (drain.isNotEmpty) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val dye = DyeColor.entries.firstOrNull { stack.`is`(it.tag) } ?: return false
|
||||
return dyeStored(dye) + HUE_PER_ITEM <= MAX_STORAGE
|
||||
}
|
||||
|
||||
override fun modifyInsertCount(slot: Int, stack: ItemStack, existing: ItemStack, simulate: Boolean): Int {
|
||||
if (!ItemStack.isSameItemSameComponents(stack, existing))
|
||||
return super.modifyInsertCount(slot, stack, existing, simulate)
|
||||
|
||||
val dye = DyeColor.entries.firstOrNull { stack.`is`(it.tag) } ?: return 0
|
||||
return stack.count.coerceAtMost((MAX_STORAGE - dyeStored(dye)) / HUE_PER_ITEM - existing.count)
|
||||
}
|
||||
|
||||
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
|
||||
return false
|
||||
}
|
||||
}))
|
||||
val config = ConfigurableItemHandler(input = dyeInput)
|
||||
|
||||
fun waterStored(): Int {
|
||||
return dyeStored.getInt(null)
|
||||
|
@ -17,6 +17,8 @@ import ru.dbotthepony.kommons.util.setValue
|
||||
import ru.dbotthepony.mc.otm.block.entity.decorative.PainterBlockEntity
|
||||
import ru.dbotthepony.mc.otm.capability.matteryPlayer
|
||||
import ru.dbotthepony.mc.otm.container.MatteryContainer
|
||||
import ru.dbotthepony.mc.otm.container.set
|
||||
import ru.dbotthepony.mc.otm.container.slotted.SlottedContainer
|
||||
import ru.dbotthepony.mc.otm.core.addAll
|
||||
import ru.dbotthepony.mc.otm.core.collect.SupplierMap
|
||||
import ru.dbotthepony.mc.otm.core.collect.filter
|
||||
@ -45,8 +47,8 @@ class PainterMenu(
|
||||
val dyeStoredDirect = SupplierMap(dyeStored)
|
||||
val itemConfig = ItemConfigPlayerInput(this, tile?.config)
|
||||
|
||||
val inputContainer = MatteryContainer(::rescan, 1)
|
||||
val outputContainer = MatteryContainer(1)
|
||||
val inputContainer = SlottedContainer.simple(1, ::rescan)
|
||||
val outputContainer = SlottedContainer.simple(1)
|
||||
private var lastRecipe: RecipeHolder<out AbstractPainterRecipe>? = null
|
||||
var selectedRecipe by mSynchronizer.add(ListenableDelegate.Box(null), StreamCodecs.RESOURCE_LOCATION.nullable()).also { it.addListener(Runnable { rescan() }) }
|
||||
|
||||
@ -102,13 +104,13 @@ class PainterMenu(
|
||||
}
|
||||
}
|
||||
|
||||
val dyeSlot = object : MatteryMenuSlot(tile?.dyeInput ?: SimpleContainer(1), 0) {
|
||||
val dyeSlot = object : MatteryMenuSlot(tile?.dyeInput ?: SlottedContainer.simple(1), 0) {
|
||||
override fun mayPlace(itemStack: ItemStack): Boolean {
|
||||
return super.mayPlace(itemStack) && ((
|
||||
itemStack.getCapability(Capabilities.FluidHandler.ITEM)?.let {
|
||||
dyeStoredDirect[null]!! < PainterBlockEntity.MAX_WATER_STORAGE && it.drain(FluidStack(Fluids.WATER, PainterBlockEntity.MAX_WATER_STORAGE - dyeStoredDirect[null]!!), IFluidHandler.FluidAction.SIMULATE).isNotEmpty
|
||||
} ?: false
|
||||
) || (DyeColor.getColor(itemStack)?.let { dyeStoredDirect[it]!! + PainterBlockEntity.HUE_PER_ITEM <= PainterBlockEntity.MAX_STORAGE } ?: false))
|
||||
return super.mayPlace(itemStack) && (
|
||||
itemStack.getCapability(Capabilities.FluidHandler.ITEM)
|
||||
?.drain(FluidStack(Fluids.WATER, PainterBlockEntity.MAX_WATER_STORAGE - dyeStoredDirect[null]!!), IFluidHandler.FluidAction.SIMULATE)?.isNotEmpty
|
||||
?: false
|
||||
|| DyeColor.getColor(itemStack) != null)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user