Repository navigation
Custom Transitions [Hard Dependency]
TheInsanityGod edited this page Sep 17, 2026
·
5 revisions
Note: under the hood this uses the Enum Extension Util
Custom transition types are defined through json in the assets/domain/transitiontypes folder.

Properties:
-
Code: The identifier of the transition. -
Handler('insanitylib:TransitionHandler'by default): The transition handler to use. -
Attributes: Like with Items and Blocks, these can be used to provide extra information.
You can define the following language keys:
"MODID:transition-CODE""MODID:transition-CODE-progression""MODID:transition-CODE-duration-hours""MODID:transition-CODE-duration-days""MODID:transition-CODE-duration-years""MODID:transition-CODE-handbook"
See the examples for clearer insight to what these should contain.
{
"Code": "melt",
"Handler": "TemperatureTransitionHandler", //Remember to add the modID (aka domain) prefix if using it from a different mod
"Attributes": {
"invert": true
}
}{
"transition-melt": "<font color=\"burlywood\">Meltable.</font>",
"transition-melt-progression": "<font color=\"burlywood\">Meltable.</font> {0}% melted",
"transition-melt-duration-hours": "Will <font color=\"burlywood\">melt</font> in {p0:less than an hour|# hour|# hours}",
"transition-melt-duration-days": "Will <font color=\"burlywood\">melt</font> in {p0:less than a day|# day|# days}",
"transition-melt-duration-years": "Will <font color=\"burlywood\">melt</font> in {p0:less than a year|# year|# years}",
"handbook-processesinto-transition-melt-hours": "After {p0:less than an hour|a hour|# hours} on average, melts into",
"handbook-processesinto-transition-melt-days": "After {p0:|a day|# days} on average, melts into",
"handbook-processesinto-transition-melt-years": "After {p0:|a year|#.# years} on average, melts into",
"handbook-createdby-transition-melt": "Melting",
}public class TemperatureTransitionHandler : TransitionHandler
{
public bool Invert { get; private set; }
public override void LoadAttributes(JsonObject attributes)
{
if(attributes == null) return;
Invert = attributes["Invert"].AsBool(Invert);
}
public const float DefaultFreezePoint = 0;
public static float GetFreezingPoint(ItemSlot slot)
{
var attr = slot.Itemstack?.Collectible.Attributes;
return attr != null ? attr["freezePoint"].AsFloat() : DefaultFreezePoint;
}
public override float GetTransitionRateMul(IWorldAccessor world, ItemSlot inSlot, float currentResult)
{
float multiplier = 0;
var pos = inSlot.Inventory?.Pos ?? (inSlot.Inventory as InventoryBasePlayer)?.Player.Entity.Pos.AsBlockPos;
if(pos == null) return multiplier;
if (!world.BlockAccessor.IsValidPos(pos)) return multiplier;
var freezingPoint = GetFreezingPoint(inSlot);
var temperature = GetTemperatureAtPos(world, inSlot, pos); //This method is not relevant for the example
var diffMult = Math.Abs(temperature - freezingPoint) / 5;
if (Invert) return temperature >= freezingPoint ? diffMult : -diffMult;
return temperature <= freezingPoint ? diffMult : -diffMult;
}
}Note: This code comes from the BrainFreeze Repository (full code can be seen there).