The Binding of Isaac: Rebirth

The Binding of Isaac: Rebirth

Custom Consumable API [OBSOLETE]
 This topic has been pinned, so it's probably important
AgentCucco  [developer] 22 Feb, 2020 @ 11:28pm
Documentation
-= INSTRUCTIONS =-

To clarify, in order to use this api you first need to register your consumables as if you were going to register any cards. By this I mean adding the pocketitems.xml file into your content folder and doing the corresponding setup to give your consumable a proper cardfront. You can find my custom cardfront sprite in the main folder alongside this main.lua, where you can get the custom rune sprites.

Runes / Cards

In order to add a new consumable with this API is fairly simple, all you have to do is follow these rules. I'll use 'Gebo' as an example.
CUSTOMCONSUMABLE_API["Gebo"] = { ID = Isaac.GetCardIdByName("Gebo"), TYPE = "Rune", BACK = 1, SPR = Sprite(), SFX = {SFX = SoundEffect.SOUND_THUMBSUP, Volume = 1, Pitch = 1}, USE = function() Isaac.DebugString("Gebo") end, } CUSTOMCONSUMABLE_API["Gebo"].SPR:Load("gfx/ui/giantbook/giantbook.anm2", false) CUSTOMCONSUMABLE_API["Gebo"].SPR:ReplaceSpritesheet(0,"gfx/ui/giantbook/Gebo.png")

ID: This is the ID of the new consumable, it is automatically generated by Isaac's API.
TYPE: Use this to specify whether the consumable is a rune, a card or a pill.
BACK: This is the type of the consumable.
Runes = [1: Pointy, 2: Chunky, 3: Black Rune, 4: Double Point, 5: Spiky, 6: Shard]
Cards = [1: Tarot, 2: Playing, 3: Emergency Contact, 4: Dice Shard, 5: Magic, 6: Card against humanity, 7: Credit card, 8: Holy Card, 9: Rules card]
SPR: Always leave this as Sprite().
SFX: This is to specify a sound effect when the card is used, this is not mandatory. [OPTIONAL]
USE: Here is where you'll need to define what your consumable does, follows normal Isaac code.
:Load: Leave this unchanged, only switch 'Gebo' for your rune name. [RUNE EXCLUSIVE]
:ReplaceSpritesheet: For this one all you need to change is 'Gebo' for your rune name. But you will need to first have your giantbook sprite on the root stated in it. [RUNE EXCLUSIVE]

To register cards you must follow a really similar process, all you have to skip is the SPR part:
CUSTOMCONSUMABLE_API["Custom Card"] = { ID = Isaac.GetCardIdByName("Custom Card"), TYPE = "Card", BACK = 5, SFX = {SFX = SoundEffect.SOUND_THUMBSUP, Volume = 1, Pitch = 1}, USE = function() Isaac.DebugString("Custom Card") end, }

Worth noting the SFX attribute is completely optional, but given you choose to use it, you must fill all 3 values. You can also modify Valume and Pitch to whatever value you please that doesn't fall into negative numbers.

Bear in mind you MUST have every instance of your consumable name match the one in your xml.
See how every time I used 'Gebo' in the example I used the same caps in every case.

Pills

Registering pills is a simpler process than the one for runes in my opinion, all you have to do is register the pocketitems.xml file and add the proper table to add them into the mod, no sprites needed whatsoever.

Too add a new pill simply follow these steps:
CUSTOMCONSUMABLE_API["Bloody Mary"] = { ID = Isaac.GetPillEffectByName("Bloody Mary"), TYPE = "Pill", BUFF = {"Positive"}, USE = function() Isaac.DebugString("Bloody Mary!") end, }

ID: This is the ID of the new consumable, it is automatically generated by Isaac's API.
TYPE: Use this to specify whether the consumable is a rune, a card or a pill.
BUFF: This is to register what kind of pill it is, there's several types:
[
"Positive": Your average pill, doesn't get affected by PHD.
"PHD": Your average NEGATIVE pill, this one turns into a better pill with PHD.
"Negative": Not your ordinary negative pill, it will turn into a random positive pill with PHD, avoid using this type.
"Transform": This is a unique pill type added by the mod, it is unable to spawn normally, however it can be spawned if the player has PHD, depending on the pill.
]
USE: Here is where you'll need to define what your consumable does, follows normal Isaac code.

Now I'll go over how to register every type of pill and explain in further detail.

------== Detailed pills:

The "Positive" pill will act as a normal/neutral pill, it will be able to spawn normally and with
PHD.
CUSTOMCONSUMABLE_API["Positive Pill"] = { ID = Isaac.GetPillEffectByName("Positive Pill"), TYPE = "Pill", BUFF = {"Positive"}, USE = function() Isaac.DebugString("Positive Pill") end, }

The "PHD" pill is the usual negative kind of pill that the game uses, it will provide a negative effect to the player, and when in possesion of PHD or Virgo, this pill will turn into a Positive pill. You can specify which pill will it turn into. It can turn into whatever pill you specify, even negative ones.
CUSTOMCONSUMABLE_API["PHD Pill"] = { ID = Isaac.GetPillEffectByName("PHD Pill"), TYPE = "Pill", BUFF = {"PHD", "Positive Pill"}, USE = function() Isaac.DebugString("PHD Pill") end, }
The "Negative" pill is a special case that's only to be used when your negative pill does not count with a counterpart. Normally soft negative pills should be treated as Positive (like explosive diarrhea or puberty), but if you really don't want it to remain neutral and can't come up with a positive effect for it, you can use this one.
This type of pill will turn into a random seeded positive pool from either the modded or vanilla pool, favouring the vanilla one.
CUSTOMCONSUMABLE_API["Negative Pill"] = { ID = Isaac.GetPillEffectByName("Negative Pill"), TYPE = "Pill", BUFF = {"Negative"}, USE = function() Isaac.DebugString("Negative Pill") end, }

The "Neutral" pill is what you would expect from a pill type called Neutral. This pill will be able to spawn normally during the run, however it will not be turned into another pill when getting PHD or Virgo. This pill is also not ellegible for a Negative pill replacement.
Only use this type of pill for soft effects that are neither super beneficial nor super detrimental to the player.
CUSTOMCONSUMABLE_API["Neutral Pill"] = { ID = Isaac.GetPillEffectByName("Neutral Pill"), TYPE = "Pill", BUFF = {"Neutral"}, USE = function() Isaac.DebugString("Neutral Pill") end, }

The "Transform" pill is a unique kind of pill, this pill will not be able to be spawned normally, as it is not ellegible for the pill pool. However you can still access this pill if you are to make it a positive counterpart of a PHD pill. This is used to make the positive effects of custom bad pills a bit more secret since the only way of getting them is by having PHD or Virgo.
CUSTOMCONSUMABLE_API["Transformed Pill"] = { ID = Isaac.GetPillEffectByName("Transformed Pill"), TYPE = "Pill", BUFF = {"Transform"}, USE = function() Isaac.DebugString("Transformed Pill") end, }

That's all there is to pills.
As you might've noticed, there's no SFX attribute for the pills, and that's intended, avoid adding it in if possible.

Notes

Bear in mind that my code DOES NOT count with support for automated stat modifiers, if you want to add them in, you'll have to add the corresponding code into your lua file, same goes for anything else, really.
This API will just run the function you specify on USE, nothing else.

Make sure to first check if the runes table exists:
local mod = RegisterMod("Mod", 1) if not CUSTOMCONSUMABLE_API then CUSTOMCONSUMABLE_API = {} end -- This line

This is to prevent the game from erroring given the case the player doesn't have this API enabled by the time your code is ran.

It is also recommended to add a check at the end of your code to know if the API is installed, if not output an error to the console.
if not ConsumableAPI then mod:AddCallback(ModCallbacks.MC_POST_UPDATE, function() if Game():GetFrameCount() % 15 -- 0 then print("Error: [mod] Custom Consumable API is not enabled.") end end) end

-- Or:
if not ConsumableAPI then function mod:OnAPICheckUpdate() if Game():GetFrameCount() % 15 then print("Error: [mod] Custom Consumable API is not enabled.") end end mod:AddCallback(ModCallbacks.MC_POST_UPDATE, mod.OnAPICheckUpdate) end

They both do the same, use the one that suits you the best.
Last edited by AgentCucco; 22 Feb, 2020 @ 11:44pm