diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/ItemRepairerBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/ItemRepairerBlockEntity.kt index 7efd8d3ad..f80417776 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/ItemRepairerBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/matter/ItemRepairerBlockEntity.kt @@ -19,6 +19,7 @@ import ru.dbotthepony.mc.otm.capability.MatteryCapability import ru.dbotthepony.mc.otm.capability.energy.BlockEnergyStorageImpl import ru.dbotthepony.mc.otm.capability.energy.WorkerEnergyStorage import ru.dbotthepony.mc.otm.capability.matter.IMatterStorage +import ru.dbotthepony.mc.otm.capability.matter.IPatternState import ru.dbotthepony.mc.otm.capability.matter.MatterStorageImpl import ru.dbotthepony.mc.otm.config.ConciseBalanceValues import ru.dbotthepony.mc.otm.container.HandlerFilter @@ -43,14 +44,32 @@ class ItemRepairerBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matt private var matterPerTick = Decimal.ZERO private var progressPerTick = 0.0 private var repairProgress = 0.0 + private var failureChance = 0.0 private var lastItem: Item? = null var canNotWork = false val matter = MatterStorageImpl(::setChangedLight, FlowDirection.INPUT, ::CAPACITY) - val matterNode = SimpleMatterNode(matter = matter) val energy = WorkerEnergyStorage(::setChangedLight, ENERGY_VALUES) + val matterNode = object : MatterNode() { + override fun getMatterHandler(): IMatterStorage { + return matter + } + + override fun onPatternAdded(state: IPatternState) { + containerChanged() + } + + override fun onPatternRemoved(state: IPatternState) { + containerChanged() + } + + override fun onPatternUpdated(newState: IPatternState, oldState: IPatternState) { + containerChanged() + } + } + init { exposeGlobally(MatteryCapability.MATTER, matter) exposeGlobally(MatteryCapability.MATTER_NODE, matterNode) @@ -148,6 +167,7 @@ class ItemRepairerBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matt progressPerTick = (item.maxDamage / matter.complexity) / DIVISOR matterPerTick = (matter.matter / matter.complexity) / DIVISOR + failureChance = (1.0 - found.researchPercent) + FAILURE_CHANCE } else { matterPerTick = Decimal.ZERO progressPerTick = 0.0 @@ -201,7 +221,7 @@ class ItemRepairerBlockEntity(blockPos: BlockPos, blockState: BlockState) : Matt return } - if (FAILURE_CHANCE <= 0.0 || level!!.random.nextDouble() >= FAILURE_CHANCE) + if (failureChance <= 0.0 || level!!.random.nextDouble() >= failureChance) repairProgress += progressPerTick energy.extractEnergy(ENERGY_CONSUMPTION * (progressPerTick / this.progressPerTick), false)