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_155229_: BlockPos,
p_155230_: BlockState p_155230_: BlockState
) : MatteryWorkerBlockEntity<MatteryWorkerBlockEntity.ItemJob>(MBlockEntities.PLATE_PRESS, p_155229_, p_155230_, ::ItemJob) { ) : 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 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 var experience = 0.0
@ -37,19 +38,16 @@ class PlatePressBlockEntity(
} }
} }
val itemHandler = container.handler(object : HandlerFilter { val energyConfig = ConfigurableEnergy(energy)
override fun canInsert(slot: Int, stack: ItemStack): Boolean { val itemConfig = ConfigurableItemHandler(
return slot != SLOT_OUTPUT input = inputContainer.handler(HandlerFilter.OnlyIn),
} output = outputContainer.handler(HandlerFilter.OnlyOut),
)
override fun canExtract(slot: Int, amount: Int, stack: ItemStack): Boolean {
return slot != SLOT_INPUT
}
})
init { init {
savetable(::energy, ENERGY_KEY) savetable(::energy, ENERGY_KEY)
savetable(::container, INVENTORY_KEY) savetable(::inputContainer)
savetable(::outputContainer)
savetables.double(::experience) savetables.double(::experience)
} }
@ -61,7 +59,7 @@ class PlatePressBlockEntity(
if (job.itemStack.isEmpty) if (job.itemStack.isEmpty)
return Status.SUCCESS return Status.SUCCESS
if (!container.fullyAddItem(job.itemStack, start = SLOT_OUTPUT, end = SLOT_OUTPUT)) if (!outputContainer.fullyAddItem(job.itemStack))
return Status.FAILURE_ITEM return Status.FAILURE_ITEM
experience = (experience + job.experience).coerceAtMost(100.0) experience = (experience + job.experience).coerceAtMost(100.0)
@ -73,14 +71,13 @@ class PlatePressBlockEntity(
return null to IdleReason.POWER return null to IdleReason.POWER
} }
val recipe = level?.recipeManager?.getRecipeFor(MRecipes.PLATE_PRESS, container, level!!)?.orElse(null) ?: return null to IdleReason.ITEM val recipe = level?.recipeManager?.getRecipeFor(MRecipes.PLATE_PRESS, inputContainer, level!!)?.orElse(null) ?: return null to IdleReason.ITEM
container[SLOT_INPUT].shrink(1) inputContainer[0].shrink(1)
inputContainer.setChanged(0)
return ItemJob(recipe.resultItem, recipe.workTime.toDouble(), BASELINE_CONSUMPTION, experience = recipe.experience.sample(level!!.random)) to null return ItemJob(recipe.resultItem, recipe.workTime.toDouble(), BASELINE_CONSUMPTION, experience = recipe.experience.sample(level!!.random)) to null
} }
companion object { companion object {
private val BASELINE_CONSUMPTION = Decimal(15) 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) ProgressGaugePanel(this, frame, menu.progressGauge, 78f, PROGRESS_ARROW_TOP)
SlotPanel(this, frame, menu.outputSlot, 104f, PROGRESS_SLOT_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 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 * [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) var possibleModes by menu.mSynchronizer.enum(FlowDirection::class.java)
private set 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 * [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) { inner class Piece(val side: RelativeSide) {
private val allowedFlags = MatteryDeviceBlockEntity.ItemHandlerMode.values().map { menu.mSynchronizer.bool() to it } 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.MachineOutputSlot
import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu import ru.dbotthepony.mc.otm.menu.MatteryPoweredMenu
import ru.dbotthepony.mc.otm.menu.MatterySlot 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.menu.widget.ProgressGaugeWidget
import ru.dbotthepony.mc.otm.registry.MMenus import ru.dbotthepony.mc.otm.registry.MMenus
@ -16,18 +18,24 @@ class PlatePressMenu @JvmOverloads constructor(
inventory: Inventory, inventory: Inventory,
tile: PlatePressBlockEntity? = null tile: PlatePressBlockEntity? = null
) : MatteryPoweredMenu(MMenus.PLATE_PRESS, containerID, inventory, tile) { ) : MatteryPoweredMenu(MMenus.PLATE_PRESS, containerID, inventory, tile) {
val container = tile?.container ?: SimpleContainer(2) val inputSlot = MatterySlot(tile?.inputContainer ?: SimpleContainer(1), 0)
val outputSlot = MachineOutputSlot(tile?.outputContainer ?: SimpleContainer(1), 0) { tile?.popExperience(ply as ServerPlayer) }
val inputSlot = MatterySlot(container, PlatePressBlockEntity.SLOT_INPUT)
val outputSlot = MachineOutputSlot(container, PlatePressBlockEntity.SLOT_OUTPUT) { tile?.popExperience(ply as ServerPlayer) }
override val storageSlots: List<MatterySlot> = ImmutableList.of(inputSlot, outputSlot) override val storageSlots: List<MatterySlot> = ImmutableList.of(inputSlot, outputSlot)
val progressGauge = if (tile != null) ProgressGaugeWidget(this, tile::workProgress, tile::isUnableToProcess) else ProgressGaugeWidget(this) 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 { init {
addSlot(inputSlot) addSlot(inputSlot)
addSlot(outputSlot) addSlot(outputSlot)
addInventorySlots() 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) if (output.isActuallyEmpty || input.isActuallyEmpty)
return false return false
return input.test(container[PlatePressBlockEntity.SLOT_INPUT]) return input.test(container[0])
} }
private val outputStack: ItemStack by lazy { private val outputStack: ItemStack by lazy {