[MIRROR] Refactors & patches for grinding & juicing [MDB IGNORE] (#23760)

* Refactors & patches for grinding & juicing (#78268)

## About The Pull Request

This deals with grinding & juicing in 4 stages

**1. General grinding & juicing**
Nothing player facing, just added some extra null checks to ensure we
use `reagents` and `target_holder` only when they are not null. The
current way it was setup did not check for this

**2. Grinding Stacks**
- Fixes #48387
- Fixes #78180
- Fixes #77878

This changes the way stacks are grinded. Rather than grinding the whole
stack and have reagents wasted from grinding because there isn't enough
space in the beaker we do the reverse.
We calculate how many pieces of cable(or sheets of material) can be
grinded "based" on the available volume inside the `target_holder`(i.e.
beaker for all in 1 grinder, or internal buffer for chemical plumbing
grinder, mortar & pedestal)

**For example**
Say you have a beaker of 100 ml capacity and you have a stack of 50 iron
sheets where each sheet of iron when grinded yields 20 units of iron
reagent. Doing some simple math we should only be able to grind 5 sheets
of iron(20 units of iron per sheet x 5 = 100 ml capacity). This means
the remaining 45 sheets of iron should be left untouched and we should
be able to eject and regrind them in a different beaker if we don't have
the space for it.

This PR does exactly that. It computes how many pieces/sheets can be
grinded based on the available volume for grinding (e.g. based on the
available volume in your beaker for the all in 1 grinder) and grinds
exactly that many pieces, leaving the rest of stack untouched so you can
reuse them

This way you avoid wasting stacks when your beaker doesn't have the
required space to hold its reagents

**3. Plumbing Chemical Grinder**
- Not sure how nobody noticed but the plumbing chemical grinder
completely stopped working because wrong arguments were passed to the
items grind & juice procs

https://github.com/tgstation/tgstation/blob/2ddbdca1b7fb5cb85cbdcd566a489cbc4794edcf/code/modules/plumbing/plumbers/grinder_chemical.dm#L47
When it fact it should have been
`I.grind(reagents, usr)`
So yeah the plumbing chemical grinder works again

- Fixes #75429
The plumbing chemical grinder now blocks anything that isn't an
`obj/item` from entering inside it. The `grind` proc is set up to accept
only items anyway so allowing mobs to enter is just a waste of
processing power. That way nobody gets stuck inside,

- Fixes #62822
The chemical grinder now accepts items coming at it from any direction.
if you don't want to throw stuff at it you can manually put stuff in it
with hand. If you try to use a storage item like a bag(plant bag or any
bag) it dumps all its contents in the grinder.

**4. All in 1 Grinder**
- Fixes #76983
You can now remove the beaker when the blender is unpowered with right
click. The left click does not work when power is off because
`ui_interact()` proc is disabled which was responsible for ejecting the
beaker & its contents. The right click was meant to compensate for this
but it also checked if power was available and it also failed. Now that
check has been removed meaning you can eject the beaker & its contents
via right click

- Fixes #54813
The delay and shake animation is already handled by the `operate()` proc
but the mix settings would add an additional timer on top of that with a
fixed delay of 50 deciseconds. That timer is adjusted so its reduced
from upgraded parts

## Changelog
🆑
code: added some null checks for general juicing & grinding items
fix: grinding stacks now grinds as many pieces/sheets from the stack as
possible that can fit in a beaker/container without wasting the whole
stack
fix: plumbing chemical grinder now actually works again
fix: the plumbing chemical grinder allows stuff to enter from any
direction but not mobs and also accepts items put inside it via hand
including bags
fix: You can remove the beaker from the all in 1 grinder when power is
off via right click
fix: All in 1 grinder now mixes faster with upgraded parts
refactor: you can no longer walk into a plumbing chemical grinder
/🆑

---------

Co-authored-by: Jeremiah <42397676+jlsnow301@ users.noreply.github.com>

* Refactors & patches for grinding & juicing

---------

Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
Co-authored-by: Jeremiah <42397676+jlsnow301@ users.noreply.github.com>
This commit is contained in:
SkyratBot
2023-09-17 21:38:53 +02:00
committed by GitHub
parent dc4e1f184c
commit f9fabdf1b6
6 changed files with 117 additions and 67 deletions
+37 -6
View File
@@ -145,18 +145,49 @@
/obj/item/stack/set_custom_materials(list/materials, multiplier=1, is_update=FALSE)
return is_update ? ..() : set_mats_per_unit(materials, multiplier/(amount || 1))
/obj/item/stack/on_grind()
. = ..()
for(var/i in 1 to length(grind_results)) //This should only call if it's ground, so no need to check if grind_results exists
grind_results[grind_results[i]] *= get_amount() //Gets the key at position i, then the reagent amount of that key, then multiplies it by stack size
/obj/item/stack/grind_requirements()
if(is_cyborg)
to_chat(usr, span_warning("[src] is too integrated into your chassis and can't be ground up!"))
return
return TRUE
/obj/item/stack/grind(datum/reagents/target_holder, mob/user)
var/current_amount = get_amount()
if(current_amount <= 0 || QDELETED(src)) //just to get rid of this 0 amount/deleted stack we return success
return TRUE
if(on_grind() == -1)
return FALSE
if(isnull(target_holder))
return TRUE
if(reagents)
reagents.trans_to(target_holder, reagents.total_volume, transferred_by = user)
var/available_volume = target_holder.maximum_volume - target_holder.total_volume
//compute total volume of reagents that will be occupied by grind_results
var/total_volume = 0
for(var/reagent in grind_results)
total_volume += grind_results[reagent]
//compute number of pieces(or sheets) from available_volume
var/available_amount = min(current_amount, round(available_volume / total_volume))
if(available_amount <= 0)
return FALSE
//Now transfer the grind results scaled by available_amount
var/list/grind_reagents = grind_results.Copy()
for(var/reagent in grind_reagents)
grind_reagents[reagent] *= available_amount
target_holder.add_reagent_list(grind_reagents)
/**
* use available_amount of sheets/pieces, return TRUE only if all sheets/pieces of this stack were used
* we don't delete this stack when it reaches 0 because we expect the all in one grinder, etc to delete
* this stack if grinding was successfull
*/
use(available_amount, check = FALSE)
return available_amount == current_amount
/obj/item/stack/proc/get_main_recipes()
RETURN_TYPE(/list)
SHOULD_CALL_PARENT(TRUE)