Merge pull request #1353 from lllllllllwith10ls/main

Fix some bugs with chem.js and alchem.js
This commit is contained in:
slweeb 2026-02-03 12:58:18 -05:00 committed by GitHub
commit 1845849d5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 174 additions and 175 deletions

View File

@ -14,6 +14,17 @@ function findReachable(elems) {
}
if(e1 === "oil") {
redo = redo || addElement_(elems, "lamp_oil");
redo = redo || addElement_(elems, "propane");
redo = redo || addElement_(elems, "molten_plastic");
}
if (eLists.SEEDS.includes(e1)) {
redo = redo || addElement_(elems, "fiber");
}
if(e1 === "thorium" && elems.includes("neutron")) {
redo = redo || addElement_(elems, "radium");
}
@ -80,6 +91,8 @@ function findReachable(elems) {
return elems;
}
worldgentypes = {}
function addElement_(list, elem) {
if(elem instanceof Array)
{
@ -106,7 +119,7 @@ function loadAlchem() {
elements.hematite = {
color: ["#e0472f", "#bf2a2a", "#913920"],
behavior: behaviors.POWDER,
category: "alchemy mod",
category: "land",
density: 5250,
state: "solid",
tempHigh: 1539,
@ -132,7 +145,7 @@ function loadAlchem() {
elements.chalcopyrite = {
color: ["#e8d7cb", "#cdc0af", "#726153", "#8f775e", "#bfaea0",],
behavior: behaviors.WALL,
category: "alchemy mod",
category: "land",
density: 4200,
state: "solid",
tempHigh: 950,
@ -150,7 +163,7 @@ function loadAlchem() {
elements.sphalerite = {
color: ["#7a7a7a", "#5c5c5c", "#3d3d3d", "#363636", "#e0e0e0",],
behavior: behaviors.WALL,
category: "alchemy mod",
category: "land",
density: 4090,
state: "solid",
tempHigh: 1850,
@ -169,7 +182,7 @@ function loadAlchem() {
elements.cassiterite = {
color: ["#5e5b5b", "#705a4d", "#826f6f", "#333030", "#e3d8d1"],
behavior: behaviors.WALL,
category: "alchemy mod",
category: "land",
density: 6950,
state: "solid",
tempHigh: 1630,
@ -187,7 +200,7 @@ function loadAlchem() {
elements.galena = {
color: ["#e6e6e6", "#bdbdbd", "#7a7a7a", "#737373"],
behavior: behaviors.WALL,
category: "alchemy mod",
category: "land",
density: 7600,
state: "solid",
tempHigh: 1113,
@ -212,7 +225,7 @@ function loadAlchem() {
.concat(Array(2).fill("molten_silver"))
.concat(Array(1).fill("molten_gold"))
.concat(Array(3).fill("molten_fluorite"))
.concat(Array(3).fill("molten_uraninite"))
.concat(Array(3).fill("molten_uraninite"));
elements.molten_slag.ignore.push("rutile");
elements.molten_slag.ignore.push("bauxite");
@ -237,7 +250,7 @@ if (!settings.alchemyUnlocked) {
if (settings.unlocked.alchemymod) {
for (var element in settings.unlocked) {
if (settings.unlocked[element]) {
settings.alchemyUnlocked[element] = true
settings.alchemyUnlocked[element] = true;
}
}
}
@ -255,21 +268,6 @@ if (elements.cook) {
if (elements.incinerate) {
elements.incinerate.category = "tools";
}
for (var element in elements) {
if (elements[element].category === "tools") {
settings.alchemyUnlocked[element] = true;
}
if (settings.alchemyUnlocked[element]) {
elements[element].hidden = false;
if (elements[element].category !== "tools") { elements[element].category = "alchemy mod"; }
}
else if (elements[element].category !== "tools") {
// give the element the hidden attribute true
elements[element].hidden = true;
// set its category to "alchemy mod"
elements[element].category = "alchemy mod";
}
}
// set the unhide setting to Unlock as Discovered (2)
settings.unhide = 2;
@ -279,7 +277,7 @@ runAfterLoad(function(){
if (elements[element] && elements[element].hidden && !settings.alchemyUnlocked[element]) {
settings.alchemyUnlocked[element] = true;
if (settings.unhide === 2) {
createElementButton(element)
createElementButton(element);
var categoryButton = document.querySelector(".categoryButton[current='true']");
var currentCategory = categoryButton.getAttribute("category");
if (currentCategory !== elements[element].category) {
@ -290,83 +288,81 @@ runAfterLoad(function(){
}
saveSettings();
}
}
})
runAfterAutogen(function(){
for (var element in elements) {
if (elements[element].category === "states") {
elements[element].category = "alchemy mod"
}
}
})
};
});
window.addEventListener("load", function () {
for (var element in elements) {
if (elements[element].hidden && document.getElementById("elementButton-" + element)) {
document.getElementById("elementButton-"+element).remove()
document.getElementById("elementButton-" + element).remove();
}
}
})
});
/*runAfterAutogen(function(){
function lockAll() {
for (var element in elements) {
if (elements[element].category === "tools") {
settings.alchemyUnlocked[element] = true;
}
if (settings.alchemyUnlocked[element]) {
elements[element].hidden = false;
}
else if (elements[element].category !== "tools") {
// give the element the hidden attribute true
elements[element].hidden = true;
}
if (elements[element].category !== "tools") {
if (!settings.alchemyUnlocked || Object.keys(settings.alchemyUnlocked).length < 25) {
elements[element].category = "alchemy mod";
}
}
}
}
runAfterAutogen(() => runAfterAutogen(lockAll));
function printReachable() {
let reachable = findReachable(initialElements);
console.log(reachable.join(","));
let string = "";
for(let i in elements)
{
if(!reachable.includes(i))
{
if(string === "")
{
for (let i in elements) {
if (!reachable.includes(i)) {
if (string === "") {
string = i;
}
else
{
else {
string += "," + i;
}
}
}
console.log(string);
string = "";
for(let i = 0; i < reachable.length; i++)
{
if(!settings.alchemyUnlocked[reachable[i]])
{
if(string === "")
{
for (let i = 0; i < reachable.length; i++) {
if (!settings.alchemyUnlocked[reachable[i]]) {
if (string === "") {
string = reachable[i];
}
else
{
else {
string += "," + reachable[i];
}
}
}
console.log(string);
string = "";
for(let i in settings.alchemyUnlocked)
{
if(!reachable.includes(i) && settings.alchemyUnlocked[i] && elements[i].category !== "tools")
{
if(string === "")
{
for (let i in settings.alchemyUnlocked) {
if (!reachable.includes(i) && settings.alchemyUnlocked[i] && elements[i].category !== "tools") {
if (string === "") {
string = i;
}
else
{
else {
string += "," + i;
}
}
}
console.log(string);
});*/
}
// runAfterAutogen(() => runAfterAutogen(printReachable));
}
if (chemMod) {
if (chemMod.readyState === 'complete') {
dependOn("chem.js", () => { return; }, true);
loadAlchem();
} else {
chemMod.addEventListener("load", loadAlchem);
}
} else {
loadAlchem();
}

View File

@ -2542,7 +2542,7 @@ chemjsChemicals.sodium_hydroxide_solution = {
},
elemName: "sodium_hydroxide",
tempHigh: [100, 150],
stateHigh: [null, ["caustic_soda"]],
stateHigh: [null, ["lye"]],
densityHigh: [1],
tempLow: [0],
reactionProduct: { anionBase: "hydroxide", cationBase: "sodium_ion" },
@ -2554,24 +2554,13 @@ elements.sodium_hydroxide_gas = {
};
chemjsChemicals.sodium_hydroxide = {
elem: {
color: "#ffe8ff",
behavior: behaviors.CAUSTIC,
category: "powders",
tempHigh: 323,
state: "solid",
density: 2130,
hidden: true,
alias: "sodium hydroxide powder",
},
elemName: "caustic_soda",
elementNames: ["lye", "molten_lye", "chemical!sodium_hydroxide_solution"],
tempHigh: [323],
reactionProduct: { anionBase: "hydroxide", cationBase: "sodium_ion" },
categories: ["bases", "sodium_ion", "hydroxide", "caustic"],
};
elements.molten_caustic_soda = {
behavior: behaviors.MOLTEN_CAUSTIC,
};
elements.lye.behavior = behaviors.CAUSTIC;
elements.molten_lye.behavior = behaviors.MOLTEN_CAUSTIC;
chemjsChemicals.potassium_hydroxide_solution = {
elem: {
@ -2955,7 +2944,7 @@ chemjsChemicals.sodium_bromoheptahydrotriborate = {
hidden: true,
},
tempHigh: [150], //wild guess
stateHigh: [["pentaborane", "sodium_bromide", "hydrogen"]],
stateHigh: [["pentaborane_9", "sodium_bromide", "hydrogen"]],
categories: ["insoluble", "sodium_ion", "bromoheptahydrotriborate"],
};
@ -3456,6 +3445,7 @@ elements.aluminum_fluoride_gas = {
state: "gas",
category: "gases",
density: 3.491,
hidden: true,
};
chemjsChemicals.potassium_carbonate = {
@ -4371,7 +4361,7 @@ chemjsChemicals.uraninite = {
chemjsChemicals.yellowcake = {
elem: {
color: ["#545323", "#50573b", "#656660", "#4d4933", "#615e4a", "#525043"],
color: ["#dbd827", "#bce346", "#a8c418", "#d9bb1a", "#dec418", "#cfb615"],
behavior: ["XX|CR:radiation%0.05|XX", "CR:radiation%0.05|XX|CR:radiation%0.05", "M2|M1|M2"],
category: "powders",
hidden: true,
@ -5727,7 +5717,7 @@ chemjsChemicals.diborane = {
},
tempLow: [-92.5, -164],
tempHigh: [200],
stateHigh: [["pentaborane", "pentaborane", "decaborane"]],
stateHigh: [["pentaborane_9", "pentaborane_9", "decaborane"]],
toxic: [1],
densityLow: [477],
};
@ -6390,7 +6380,7 @@ elements.soy_sauce = {
stateHigh: ["steam", "steam", "steam", "steam", "salt"],
};
elements.supernova.behavior = ["XX|XX|XX", "XX|EX:80>plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,molten_iron,molten_uranium,molten_lead,oxygen,molten_sodium,sulfur_gas,fluorine,neon,molten_potassium,chlorine,molten_calcium,molten_titanium,molten_nickel,molten_copper,molten_zinc,gallium_gas,bromine_gas,iodine_gas AND CH:neutronium,neutronium,quark_matter,void|XX", "XX|XX|XX"];
elements.supernova.behavior = ["XX|XX|XX", "XX|EX:80>plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,plasma,molten_iron,molten_uranium,molten_lead,oxygen,molten_sodium,sulfur_gas,fluorine,neon,molten_potassium,molten_magnesium,molten_aluminum,chlorine,molten_calcium,molten_titanium,molten_nickel,molten_copper,molten_zinc,gallium_gas,bromine_gas,iodine_gas AND CH:neutronium,neutronium,quark_matter,void|XX", "XX|XX|XX"];
elements.gamma_ray_burst = {
color: ["#fbf8ff", "#fbf3ff", "#f8f7ff"],
@ -6455,7 +6445,7 @@ chemjsChemicals.quark_matter = {
};
elements.liquid_helium.behavior2 = ["XX|XX|XX".split("|"), "M1|XX|M1".split("|"), "M1|M1|M1".split("|")];
elements.liquid_helium.behavior = null;
delete elements.liquid_helium.behavior;
elements.liquid_helium.tick = function (pixel) {
if (Math.random() < 0.9) {
@ -6730,6 +6720,19 @@ elements.living_spark = {
ignoreAir: true,
};
runEveryTick(function () {
for (let i = currentPixels.length - 1; i >= 0; i--) {
if (currentPixels[i].element === "living_spark") {
if (currentPixels[i].lifeState === 2) {
deletePixel(currentPixels[i].x, currentPixels[i].y);
} else {
currentPixels[i].lifeState = 0;
}
}
}
});
function elementCircle(x, y, radius, pixelType = "fire", chance = 0.1, replace = [null]) {
if (!Array.isArray(replace)) {
replace = [replace];
@ -6939,7 +6942,7 @@ chemjsReactions = [
{ react1: "chemical!acid_liquids", react2: "sodium", elem1: "explosion", elem2: "no_change", priority: 50 },
{ react1: "chemical!acid_liquids", react2: "potassium", elem1: "explosion", elem2: "no_change", priority: 50 },
{ react1: "chemical!acid_liquids", react2: "meat", elem1: "no_change", elem2: "rotten_meat", elem1: null, chance: 0.5, priority: 50 },
{ react1: "chemical!acids", react2: "chemical!liquid_water,ignore!dirty_water,ignore!neutral_acid", elem1: null, elem2: "dirty_water", priority: 10 },
{ react1: "chemical!acids,restrictchemical!caustic", react2: "chemical!liquid_water,ignore!dirty_water,ignore!neutral_acid", elem1: null, elem2: "dirty_water", priority: 10 },
{ react1: "chemical!nitric_acid,chemical!sulfuric_acid,chemical!hydroiodic_acid,chemical!hydroastatic_acid,chemical!fluoroboric_acid", react2: "chemical!liquid_water,ignore!dirty_water,ignore!neutral_acid", elem1: "no_change", elem2: "dirty_water", priority: 11 },
{ react1: "chemical!acid_gases", react2: "chemical!acid_gases", elem1: null, elem2: "acid_cloud", props: { chance: 0.3, y: [0, 12], setting: "clouds" }, priority: 50 },
@ -7181,7 +7184,7 @@ chemjsReactions = [
{ react1: "chemical!ammonia", react2: "oxygen", elem1: "nitric_oxide", elem2: "steam", props: { chance: 0.01 }, priority: 100 },
{ react1: "chemical!nitric_acid", react2: "chemical!ammonia", elem1: "ammonium_nitrate", elem2: null, priority: 100 },
{ react1: "chemical!ammonia", react2: "hydrochloric_acid", elem1: "ammonium_chloride", elem2: null, priority: 100 },
{ react1: "chemical!ammonia", react2: "acid", elem1: "ammonium_chloride", elem2: null, priority: 100 },
{ react1: "chemical!nitrogen_dioxide", react2: "rain_cloud", elem1: null, elem2: "acid_cloud", props: { chance: 0.4, y: [0, 12], setting: "clouds" }, priority: 100 },
{ react1: "chemical!nitrogen_dioxide", react2: "cloud", elem1: null, elem2: "acid_cloud", props: { chance: 0.4, y: [0, 12], setting: "clouds" }, priority: 100 },
@ -7204,7 +7207,7 @@ chemjsReactions = [
{ react1: "fluorine", react2: "liquid_oxygen", elem1: "foof", elem2: null, priority: 100 },
{ react1: "chemical!chloroform", react2: "chemical!hydrogen_fluoride", elem1: "tetrafluoroethylene", elem2: "hydrochloric_acid", props: { temp2: 50 }, priority: 100 },
{ react1: "chemical!chloroform", react2: "chemical!hydrogen_fluoride", elem1: "tetrafluoroethylene", elem2: "acid", props: { temp2: 50 }, priority: 100 },
{ react1: "chemical!tetrafluoroethylene", react2: "chemical!oxygen", elem1: "fire", elem2: "fire", priority: 100 },
{ react1: "chemical!tetrafluoroethylene", react2: "chemical!sulfuric_acid", elem1: "polytetrafluoroethylene", elem2: "no_change", priority: 100 },
@ -7333,7 +7336,7 @@ chemjsReactions = [
{ react1: "chemical!sulfur", react2: "chemical!fluorine", elem1: "sulfur_hexafluoride", elem2: "fire", priority: 100 },
//Cl
{ react1: "chemical!chlorine", react2: "chemical!methane", elem1: "chloroform", elem2: ["hydrochloric_acid", null, null], priority: 100 },
{ react1: "chemical!chlorine", react2: "chemical!methane", elem1: "chloroform", elem2: ["acid", null, null], priority: 100 },
{ react1: "chemical!sulfuric_acid", react2: "chemical!sodium_chloride", elem1: "sodium_sulfate", elem2: "acid", props: { temp1: 50, temp2: 50 }, priority: 100 },
{ react1: "chemical!sulfuric_acid", react2: "chemical!potassium_chloride", elem1: "potassium_sulfate", elem2: "acid", props: { temp1: 50, temp2: 50 }, priority: 100 },
@ -7719,9 +7722,9 @@ chemjsReactions = [
{ react1: "chemical!ununennium", react2: "steam", elem1: "n_explosion", elem2: null, priority: 100 },
{ react1: "chemical!ununennium", react2: "chemical!liquid_water", elem1: "n_explosion", elem2: null, priority: 10 },
{ react1: "chemical!stable_ununennium", react2: "rad_steam", elem1: "ununennium_hydroxide", elem2: [null, null, "big_pop"], props: { func: ununenniumHydroxide }, priority: 100 },
{ react1: "chemical!stable_ununennium", react2: "steam", elem1: "ununennium_hydroxide", elem2: [null, null, "big_pop"], props: { func: ununenniumHydroxide }, priority: 100 },
{ react1: "chemical!stable_ununennium", react2: "chemical!liquid_water", elem1: "ununennium_hydroxide", elem2: [null, null, "big_pop"], props: { func: ununenniumHydroxide }, priority: 10 },
{ react1: "chemical!stable_ununennium", react2: "rad_steam", elem1: "ununennium_hydroxide", elem2: [null, null, "explosion"], props: { func: ununenniumHydroxide }, priority: 100 },
{ react1: "chemical!stable_ununennium", react2: "steam", elem1: "ununennium_hydroxide", elem2: [null, null, "explosion"], props: { func: ununenniumHydroxide }, priority: 100 },
{ react1: "chemical!stable_ununennium", react2: "chemical!liquid_water", elem1: "ununennium_hydroxide", elem2: [null, null, "explosion"], props: { func: ununenniumHydroxide }, priority: 10 },
{ react1: "chemical!ununennium_hydroxide,ignorechemical!ununennium_hydroxide_solution", react2: "chemical!liquid_water", elem1: "ununennium_hydroxide", elem2: null, priority: 10 },
{ react1: "chemical!ununennium_fluoride", react2: "chemical!fluorine", elem1: "ununennium_trifluoride", elem2: "fire", priority: 100 },