Overflow prevention inside painter block entity

This commit is contained in:
DBotThePony 2024-01-18 19:28:04 +07:00
parent 604029dcd5
commit d540cbef3c
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -66,8 +66,8 @@ class PainterBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryDe
}
override fun fill(resource: FluidStack, action: IFluidHandler.FluidAction): Int {
if (resource.isEmpty || resource.fluid != Fluids.WATER || waterStored() >= MAX_WATER_STORAGE) return 0
val diff = (waterStored() + resource.amount).coerceAtMost(MAX_WATER_STORAGE) - waterStored()
if (resource.amount <= 0 || resource.fluid != Fluids.WATER || waterStored() >= MAX_WATER_STORAGE) return 0
val diff = ((waterStored().toLong() + resource.amount.toLong()).coerceAtMost(MAX_WATER_STORAGE.toLong()) - waterStored().toLong()).toInt()
if (action.simulate() || diff == 0) return diff
dyeStored[null] = waterStored() + diff
return diff