Fix plate press being broken

This commit is contained in:
DBotThePony 2023-02-23 01:58:42 +07:00
parent 259d944d0d
commit 2db9e45291
Signed by: DBot
GPG Key ID: DCC23B5715498507
6 changed files with 29 additions and 24 deletions

View File

@ -23,8 +23,9 @@ class PlatePressBlockEntity(
p_155229_: BlockPos,
p_155230_: BlockState
) : MatteryWorkerBlockEntity<MatteryWorkerBlockEntity.ItemJob>(MBlockEntities.PLATE_PRESS, p_155229_, p_155230_, ::ItemJob) {
val container = MatteryContainer(this::setChangedLight, 2).also(::addDroppableContainer)
val energy = WorkerEnergyStorage(this::setChangedLight, MachinesConfig.PLATE_PRESS)
val inputContainer = MatteryContainer(this::itemContainerUpdated, 1).also(::addDroppableContainer)
val outputContainer = MatteryContainer(this::itemContainerUpdated, 1).also(::addDroppableContainer)
var experience = 0.0
@ -37,19 +38,16 @@ class PlatePressBlockEntity(
}
}
val itemHandler = container.handler(object : HandlerFilter {
override fun canInsert(slot: Int, stack: ItemStack): Boolean {
return slot != SLOT_OUTPUT
}
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
return slot != SLOT_INPUT
}
})
val energyConfig = ConfigurableEnergy(energy)
val itemConfig = ConfigurableItemHandler(
input = inputContainer.handler(HandlerFilter.OnlyIn),
output = outputContainer.handler(HandlerFilter.OnlyOut),
)
init {
savetable(::energy, ENERGY_KEY)
savetable(::container, INVENTORY_KEY)
savetable(::inputContainer)
savetable(::outputContainer)
savetables.double(::experience)
}
@ -61,7 +59,7 @@ class PlatePressBlockEntity(
if (job.itemStack.isEmpty)
return Status.SUCCESS
if (!container.fullyAddItem(job.itemStack, start = SLOT_OUTPUT, end = SLOT_OUTPUT))
if (!outputContainer.fullyAddItem(job.itemStack))
return Status.FAILURE_ITEM
experience = (experience + job.experience).coerceAtMost(100.0)
@ -73,14 +71,13 @@ class PlatePressBlockEntity(
return null to IdleReason.POWER
}
val recipe = level?.recipeManager?.getRecipeFor(MRecipes.PLATE_PRESS, container, level!!)?.orElse(null) ?: return null to IdleReason.ITEM
container[SLOT_INPUT].shrink(1)
val recipe = level?.recipeManager?.getRecipeFor(MRecipes.PLATE_PRESS, inputContainer, level!!)?.orElse(null) ?: return null to IdleReason.ITEM
inputContainer[0].shrink(1)
inputContainer.setChanged(0)
return ItemJob(recipe.resultItem, recipe.workTime.toDouble(), BASELINE_CONSUMPTION, experience = recipe.experience.sample(level!!.random)) to null
}
companion object {
private val BASELINE_CONSUMPTION = Decimal(15)
const val SLOT_INPUT = 0
const val SLOT_OUTPUT = 1
}
}

View File

@ -23,7 +23,7 @@ class PlatePressScreen(menu: PlatePressMenu, inventory: Inventory, title: Compon
ProgressGaugePanel(this, frame, menu.progressGauge, 78f, PROGRESS_ARROW_TOP)
SlotPanel(this, frame, menu.outputSlot, 104f, PROGRESS_SLOT_TOP)
makeDeviceControls(this, frame, redstone = menu.redstone)
makeDeviceControls(this, frame, redstone = menu.redstone, energyConfig = menu.energyConfig, itemConfig = menu.itemConfig)
return frame
}

View File

@ -9,7 +9,7 @@ import ru.dbotthepony.mc.otm.menu.MatteryMenu
/**
* [allowPull] and [allowPush] controls whenever player is allowed to change these options
*/
class EnergyPlayerInput(val menu: MatteryMenu, val allowPull: Boolean = true, val allowPush: Boolean = true) {
class EnergyPlayerInput(val menu: MatteryMenu, val allowPull: Boolean = false, val allowPush: Boolean = false) {
var possibleModes by menu.mSynchronizer.enum(FlowDirection::class.java)
private set

View File

@ -8,7 +8,7 @@ import ru.dbotthepony.mc.otm.menu.MatteryMenu
/**
* [allowPull] and [allowPush] controls whenever player is allowed to change these options
*/
class ItemHandlerPlayerInput(val menu: MatteryMenu, val allowPull: Boolean = true, val allowPush: Boolean = true) {
class ItemHandlerPlayerInput(val menu: MatteryMenu, val allowPull: Boolean = false, val allowPush: Boolean = false) {
inner class Piece(val side: RelativeSide) {
private val allowedFlags = MatteryDeviceBlockEntity.ItemHandlerMode.values().map { menu.mSynchronizer.bool() to it }

View File

@ -8,6 +8,8 @@ import ru.dbotthepony.mc.otm.block.entity.tech.PlatePressBlockEntity
import ru.dbotthepony.mc.otm.menu.MachineOutputSlot
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
import ru.dbotthepony.mc.otm.menu.MatterySlot
import ru.dbotthepony.mc.otm.menu.input.EnergyPlayerInput
import ru.dbotthepony.mc.otm.menu.input.ItemHandlerPlayerInput
import ru.dbotthepony.mc.otm.menu.widget.ProgressGaugeWidget
import ru.dbotthepony.mc.otm.registry.MMenus
@ -16,18 +18,24 @@ class PlatePressMenu @JvmOverloads constructor(
inventory: Inventory,
tile: PlatePressBlockEntity? = null
) : MatteryPoweredMenu(MMenus.PLATE_PRESS, containerID, inventory, tile) {
val container = tile?.container ?: SimpleContainer(2)
val inputSlot = MatterySlot(container, PlatePressBlockEntity.SLOT_INPUT)
val outputSlot = MachineOutputSlot(container, PlatePressBlockEntity.SLOT_OUTPUT) { tile?.popExperience(ply as ServerPlayer) }
val inputSlot = MatterySlot(tile?.inputContainer ?: SimpleContainer(1), 0)
val outputSlot = MachineOutputSlot(tile?.outputContainer ?: SimpleContainer(1), 0) { tile?.popExperience(ply as ServerPlayer) }
override val storageSlots: List<MatterySlot> = ImmutableList.of(inputSlot, outputSlot)
val progressGauge = if (tile != null) ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess) else ProgressGaugeWidget(this)
val itemConfig = ItemHandlerPlayerInput(this, allowPush = true)
val energyConfig = EnergyPlayerInput(this, allowPull = true)
init {
addSlot(inputSlot)
addSlot(outputSlot)
addInventorySlots()
if (tile != null) {
itemConfig.configure(tile.itemConfig)
energyConfig.configure(tile.energyConfig)
}
}
}

View File

@ -38,7 +38,7 @@ class PlatePressRecipe(
if (output.isActuallyEmpty || input.isActuallyEmpty)
return false
return input.test(container[PlatePressBlockEntity.SLOT_INPUT])
return input.test(container[0])
}
private val outputStack: ItemStack by lazy {