Files
Bubberstation/code/datums/components/crafting/containers.dm
Bloop 1e443894b5 [MANUAL MIRROR] Fixes toilet bongs, and fixes a serious bug in the crafting system (#18921)
* Fixes toilet bongs, and fixes a serious bug in the crafting system (#72893)

The PR everyone has been waiting for...fixed toilet bong crafting. Now
you can craft them just as before using the new crafting system.

![image](https://user-images.githubusercontent.com/13398309/213944308-74b3e50e-965d-4e69-9025-d011764b3247.png)

In attempting to fix this I encountered one of the gnarliest, nastiest,
meanest and most infuriatingly difficult to debug bugs I have come
across so far. And it's existed for as long as the crafting system has,
but due to unique circumstances it has been allowed to go unnoticed this
whole time.

Technical details below. Full list of changes here:

- crafting recipes can now contain structures as part of their
requirements
- removed deprecated var 'additional_req_tex' and changed text to use
the 'steps' list instead so they actually show in the gui
- toilet bongs are now passable terrain like normal toilets are
- fixed an atrocious bug with crafting that was by pure coincidence not
causing any problems
- this bug would prevent any recipes that did not contain a material
from deleting properly
- this bug would also cause any recipes that are supposed to use but not
consume machinery to consume them regardless

---

Basically, the bug that took me hours upon hours of debugging and
head-scratching to find is this:

from crafting.dm:
```
	main_loop:
		for(var/path_key in requirements)
			amt = R.reqs[path_key] || R.machinery[path_key]
			if(!amt)//since machinery can have 0 aka CRAFTING_MACHINERY_USE - i.e. use it, don't consume it!
				continue main_loop
```
specifically this line:

`amt = R.reqs[path_key] || R.machinery[path_key] `

The culprit ended up being that if you do machinery[path_key] on an
empty list, it can lead to very unexpected behavior (see: EXITING THE
FUNCTION without actually doing anything).

I spent so much time thinking that item deletion wasn't working because
amt was being set to 0, false, or null perhaps when no, it wasn't that.
The function was just exiting out even before the (!amt) check due to
the atrocities committed by someone before me.

Setting amt = `R.reqs[path_key] || R.machinery[path_key]` on the other
hand always evaluates to a positive integer (either the successfully
retrieved reqs amt, or a 1 from the OR expression). It was only by
coincidence that the code did what it was supposed to, because:

1) Every single recipe has R_reqs, so the first part will never cause
the function-exiting failure because the list is never empty.
2) As for the second part of the expression, there are no recipes that
make use of CRAFTING_MACHINERY_USE, so the fact that machinery[path_key]
was never actually being accessed and thus set to a var (which is what
causes the function to exit) didn't matter.

So these two things together have basically allowed a really bad bug to
go unnoticed this whole time. I only noticed it because when trying to
add a third part to the expression it just did not work at all how you
would expect.

The solution is rather simply to add a check like so:
```

	main_loop:
		for(var/path_key in requirements)
			amt = R.reqs?[path_key] || R.machinery?[path_key]
			if(!amt)//since machinery can have 0 aka CRAFTING_MACHINERY_USE - i.e. use it, don't consume it!
				continue main_loop
```

Fixes https://github.com/Skyrat-SS13/Skyrat-tg/issues/18732 .

Fixes a bug with crafting that would inevitably torment someone else as
soon as they tried to add the right kind of recipe, if that hasn't
already happened by now.

<details>
<summary>Toilet bongs are back baby!!</summary>

![image](https://user-images.githubusercontent.com/13398309/213941079-ae7d007a-ca92-4de3-9de6-7a156b4a0618.png)

</details>

🆑
fix: toilet bongs crafting recipes
fix: fixed crafting itself
refactor: cleaned up some old code in the recipes file, added support
for structures in recipes
/🆑

* Update tgui/packages/tgui/interfaces/PersonalCrafting.tsx

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>

* Update tgui/packages/tgui/interfaces/PersonalCrafting.tsx

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>
2023-01-26 16:45:53 -05:00

51 lines
1.3 KiB
Plaintext

/datum/crafting_recipe/papersack
name = "Paper Sack"
result = /obj/item/storage/box/papersack
time = 1 SECONDS
reqs = list(/obj/item/paper = 5)
category = CAT_CONTAINERS
/datum/crafting_recipe/sillycup
name = "Paper Cup"
result = /obj/item/reagent_containers/cup/glass/sillycup
time = 1 SECONDS
reqs = list(/obj/item/paper = 2)
category = CAT_CONTAINERS
/datum/crafting_recipe/boh
name = "Bag of Holding"
reqs = list(
/obj/item/bag_of_holding_inert = 1,
/obj/item/assembly/signaler/anomaly/bluespace = 1,
)
result = /obj/item/storage/backpack/holding
category = CAT_CONTAINERS
/datum/crafting_recipe/underwater_basket
name = "Underwater Basket (Bamboo)"
reqs = list(
/obj/item/stack/sheet/mineral/bamboo = 20
)
result = /obj/item/storage/basket
category = CAT_CONTAINERS
steps = list(
"master the art of underwater basketweaving",
"be underwater"
)
/datum/crafting_recipe/underwater_basket/check_requirements(mob/user, list/collected_requirements)
. = ..()
if(!HAS_TRAIT(user,TRAIT_UNDERWATER_BASKETWEAVING_KNOWLEDGE))
return FALSE
var/turf/T = get_turf(user)
if(istype(T, /turf/open/water))
return TRUE
var/obj/machinery/shower/S = locate() in T
if(S?.actually_on)
return TRUE
//Same but with wheat
/datum/crafting_recipe/underwater_basket/wheat
name = "Underwater Basket (Wheat)"
reqs = list(/obj/item/food/grown/wheat = 50)