Modding tutorial/Advanced reactions
Reaction requirements
Reactions can be controlled and may be written to occur only when specific requirements are met:
Property name | Description | Reaction example |
---|---|---|
chance |
Chance per tick of reaction occurring | Borax + Glue |
tempMin |
Minimum temperature a reaction can occur | Rock + Bone |
tempMax |
Maximum temperature a reaction can occur | Tuff + Charcoal |
oneway |
Reaction only occurs if elem1 moves into elem2 | Water + Carbon Dioxide |
charged |
Reaction only occurs if elements are charged | Water + Zinc |
burning1 |
Reaction only occurs if elem1 is burning | Not used |
burning2 |
Reaction only occurs if elem2 is burning | Chlorine + Oil |
"y" |
Reaction only occurs at y-values within range | Steam + Snow Cloud |
"setting" |
Reaction only occurs if specified setting is enabled | Oxygen + Ozone |
Examples of implementation include:
reactions: {
"chance_ex": { elem1:null, elem2:null, chance:0.5 }, // 50% chance per tick
"temprange_ex": { elem1:null, elem2:null, tempMin:50, tempMax:100 }, // Temp must be between 50 and 100
"oneway_ex": { elem1:null, elem2:null, oneway:true }, // Only if elem1 moves into elem2 - essentially, primary reactant must move and/or elements must be mixed
"charged_ex": { elem1:null, elem2:null, charged:true }, // Elements must be charged
"burning_ex": { elem1:null, elem2:null, burning1:true, burning2:true }, // elem1 and elem2 must be burning
"height_ex": { elem1:null, elem2:null, "y":[81,71] } // Only at y-values between 81 and 71
"setting_ex": { elem1:null, elem2:null, "setting":"clouds" } // Clouds setting must be toggled on
},
Product properties
The properties of a reaction's product(s) can be overridden. These properties include:
Property name | Description | Reaction example |
---|---|---|
elem1 |
What primary reactant becomes | Almost all reactions |
elem2 |
What secondary reactant becomes | Almost all reactions |
color1 |
Color(s) of primary reactant | Brass + Ammonia |
color2 |
Color(s) of secondary reactant | Dough + Milk |
temp1 |
Temperature of primary reactant | Cloud + Electric |
temp2 |
Temperature of secondary reactant | Neutron + Uranium |
attr1 |
Additional attribute of primary reactant, must be applicable | Vinegar + Limestone |
attr2 |
Additional attribute of secondary reactant, must be applicable | Yeast + Bleach |
Examples of implementation include:
reactions: {
"elem_ex": { elem1:"water", elem2:"dirt" } // Primary reactant becomes Water, elem_ex becomes Dirt
"color_ex": { color1:"#FFFFFF", color2:"#000000" }, // Primary reactant turns white, color_ex turns black
"temp_ex": { temp1:500, color2:-800 }, // Primary reactant becomes 500°C, temp_ex becomes -80°C
"attr_ex": { attr1:{"foam":20}, elem2:"sodium_acetate", attr2:{"foam":50} }, // If the primary reactant does not foam attr1 does nothing, elem2 becomes Sodium Acetate and foams
},
The base game utilizes the "foam"
attribute, which only takes effect if the reactant has a function utilizing it. For example, Sodium Acetate contains:
tick: function(pixel) {
if ((pixel.foam || Math.random() < 0.25) && isEmpty(pixel.x,pixel.y-1)) {
createPixel("foam",pixel.x,pixel.y-1);
if (pixel.foam) {
pixelMap[pixel.x][pixel.y-1].foam = pixel.foam;
pixel.foam--;
}
}
},
Where foam
contributes to the amount of Foam being generated. A function similar to this can be added to any element to further customize reactions.
Functions for properties
A function can be used in a reaction statement to set any of an element's properties following the reaction. For example:
reactions: {
"water": {func: (pixel1) => {pixel1.burning=true;pixel1.burnStart=pixelTicks}, // Primary reactant is burning starting at current tick
elem2: ["caustic_potash", "fire"], temp2: 400}
}
A similar function can be written to set values for any of an element's properties, including modded ones.