From 5b76f727773f5ce2bac4704a3054179df8f238d5 Mon Sep 17 00:00:00 2001 From: lllllllllwith10ls <38187754+lllllllllwith10ls@users.noreply.github.com> Date: Thu, 20 Jul 2023 18:34:08 -0500 Subject: [PATCH 1/3] For some reason yumcherries.js moved --- yumcherries.js => mods/yumcherries.js | 1084 ++++++++++++------------- 1 file changed, 542 insertions(+), 542 deletions(-) rename yumcherries.js => mods/yumcherries.js (97%) diff --git a/yumcherries.js b/mods/yumcherries.js similarity index 97% rename from yumcherries.js rename to mods/yumcherries.js index 90b335ae..29b7495d 100644 --- a/yumcherries.js +++ b/mods/yumcherries.js @@ -1,543 +1,543 @@ -var modName = "mods/cherries.js"; -var onTryMoveIntoMod = "mods/onTryMoveInto.js"; -var libraryMod = "mods/code_library.js"; - -if(enabledMods.includes(onTryMoveIntoMod) && enabledMods.includes(libraryMod)) { - randomNumberFromOneToThree = function() { - return 1 + Math.floor(Math.random() * 3) - }; - - debugSpeedGrowth = false; - logLeaves = false; - cherryAttachWhitelist = ["cherry_log","cherry_branch_1","cherry_branch_2","blossom","cherry_leaf","cherry_plant_top","cherry"]; - - cherryDirtElements = ["dirt","mud","sand","wet_sand","clay_soil","mycelium","grass"]; - - function logPixelCoords(pixel) { - return `(${pixel.x}, ${pixel.y})` - }; - - function hasPixel(x,y,elementInput) { - if(isEmpty(x,y,true)) { //if empty, it can't have a pixel - return false; - } else { - if(elementInput.includes(",")) { //CSTA - elementInput = elementInput.split(","); - }; - if(Array.isArray(elementInput)) { //if element list - return elementInput.includes(pixelMap[x][y].element); - } else { //if single element - return pixelMap[x][y].element === elementInput; - }; - }; - }; - - elements.cherry_seed = { - color: "#8b4513", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if (isEmpty(pixel.x,pixel.y+1)) { - movePixel(pixel,pixel.x,pixel.y+1); - } else { - if (Math.random() < (debugSpeedGrowth ? 0.09 : 0.03) && pixel.age > (debugSpeedGrowth ? 20 : 50) && pixel.temp < 100) { - if (!outOfBounds(pixel.x,pixel.y+1)) { - var dirtPixel = pixelMap[pixel.x][pixel.y+1]; - if (cherryDirtElements.includes(dirtPixel.element)) { - changePixel(dirtPixel,"root"); - }; - }; - if (isEmpty(pixel.x,pixel.y-1)) { - movePixel(pixel,pixel.x,pixel.y-1); - createPixel("cherry_log",pixel.x,pixel.y+1); - pixelMap[pixel.x][pixel.y+1].cherryRange = pixel.cherryRange; //pass cherry range down to log - }; - } else if (pixel.age > (debugSpeedGrowth ? 500 : 1000)) { - changePixel(pixel,"cherry_plant_top"); - }; - pixel.age++; - }; - if(Math.random() < 0.01 && pixel.age > 200) { - changePixel(pixel,"cherry_plant_top"); - }; - doDefaults(pixel); - }, - properties: { - "age": 0, - //"cherryRange": null, //apparently this is suddenly, in an illogical, never-before-seen, completely new, unprecedented incident of bad behavior, evaluated before being put into the property database, so RNG has to be done in tick - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - cooldown: defaultCooldown, - }; - - elements.cherry_log = { - hidden: true, - color: "#310a0b", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if (pixel.age > 60 && pixel.temp < 100 && !pixel.grewPeduncle) { - var peduncleOffsets = [-1, 1]; //placed to the left, placed to the right - for(i = 0; i < peduncleOffsets.length; i++) { - if (isEmpty(pixel.x+peduncleOffsets[i],pixel.y,false)) { - if (Math.random() < 0.005) { - createPixel("cherry_branch_1",pixel.x+peduncleOffsets[i],pixel.y); - pixelMap[pixel.x+peduncleOffsets[i]][pixel.y].dir = Math.sign(peduncleOffsets[i]); - pixelMap[pixel.x+peduncleOffsets[i]][pixel.y].cherryRange = pixel.cherryRange; //pass cherry range down to branch - if(Math.random() < 0.8) { pixel.grewPeduncle = true; } //20% chance to not mark as true, allowing for a chance to try another branch - }; - }; - }; - }; - pixel.age++; - doDefaults(pixel); - }, - properties: { - "age": 0, - "grewPeduncle": false, - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - }; - - elements.cherry = { - color: "#f7022a", - tick: function(pixel) { - if(pixel.attached) { - var attachCoords = [pixel.x+Math.sign(pixel.attachDirection), pixel.y]; - if(isEmpty(attachCoords[0],attachCoords[1],false)) { - pixel.attached = false; - }; - } else { //Move if not attached - if (!tryMove(pixel, pixel.x, pixel.y+1)) { - if(Math.random() < 0.9) { - if (Math.random() < 0.5) { - if (!tryMove(pixel, pixel.x+1, pixel.y+1)) { - tryMove(pixel, pixel.x-1, pixel.y+1); - }; - } else { - if (!tryMove(pixel, pixel.x-1, pixel.y+1)) { - tryMove(pixel, pixel.x+1, pixel.y+1); - }; - }; - }; - }; - }; - doDefaults(pixel); - var shouldSpoil = true; //spoil by default - if(pixel.attached) { //if it's attached - if(!isEmpty(attachCoords[0],attachCoords[1],true)) { //if the attachment coords are a pixel and not OOB - var attachPixel = pixelMap[attachCoords[0]][attachCoords[1]]; - var attachElement = attachPixel.element; - if(cherryAttachWhitelist.includes(attachElement)) {//if the element is a whitelisted "don't spoil" element - shouldSpoil = false; //then don't spoil - }; - }; - }; - if(shouldSpoil) { //spoil if not attached - if(pixel.temp > -14 && pixel.temp <= 4) { //(no spoiling below 14C) - pixel.spoilage += Math.max(Math.min(scale(pixel.temp,-14,4,0,9),9),0) - } else if(pixel.temp > 4) { - pixel.spoilage += Math.max(Math.min(scale(pixel.temp,4,20,9,30),40),0) - }; - }; - if(pixel.spoilage > 14400) { //3600 = 120 ticks at 20C - if(Math.random() < 0.05) { - changePixel(pixel,"spoiled_cherry"); - }; - }; - }, - properties: { - "spoilage":0, - "attached": false, - "attachDirection": (!Math.floor(Math.random() * 2)) ? 1 : -1, - }, - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - tempHigh: 200, - stateHigh: ["steam", "ash"], - onTryMoveInto: function(pixel,otherPixel) { - var otherInfo = elements[otherPixel.element] - if(typeof(otherInfo.state) === "string" && otherInfo.state !== "gas") { - pixel.attached = false; - }; - }, - }; - - elements.cherry_branch_1 = { - hidden: true, - name: "cherry branch (offshoot)", - color: "#310a0b", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if (pixel.age > 20 && pixel.temp < 100) { - var peduncleCoords1 = [pixel.x + pixel.dir, pixel.y]; - var peduncleCoords2 = [pixel.x + pixel.dir, pixel.y + 1]; - if(isEmpty(peduncleCoords1[0],peduncleCoords1[1],false) && isEmpty(peduncleCoords2[0],peduncleCoords2[1],false)) { - if(Math.random() < 0.5) { - createPixel(pixel.element,peduncleCoords1[0],peduncleCoords1[1]); - pixelMap[peduncleCoords1[0]][peduncleCoords1[1]].dir = pixel.dir; - pixelMap[peduncleCoords1[0]][peduncleCoords1[1]].cherryRange = pixel.cherryRange; //pass cherry range down to next pixel of branch horizontal - } else { - createPixel("cherry_branch_2",peduncleCoords2[0],peduncleCoords2[1]); - pixelMap[peduncleCoords2[0]][peduncleCoords2[1]].cherryRange = pixel.cherryRange; //pass cherry range down to diagonal offshoot - }; - }; - }; - pixel.age++; - doDefaults(pixel); - }, - properties: { - "dir": (!Math.floor(Math.random() * 2)) ? 1 : -1, - "age": 0, - //"cherryRange": (1 + (Math.floor(Math.random() * 3))), //1-3 - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - }; - - elements.cherry_branch_2 = { - hidden: true, - name: "cherry branch (hanging)", - color: "#310a0b", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - // Grow/Flower - if (pixel.age > 20 && pixel.temp < 100) { - var growthCoords = [pixel.x, pixel.y + 1]; - if(isEmpty(...growthCoords)) { - if(Math.random() < 0.9) { - createPixel(pixel.element,...growthCoords); - pixelMap[growthCoords[0]][growthCoords[1]].cherryRange = pixel.cherryRange; //pass cherry range down to next pixel of branch vertical - } else { - createPixel("blossom",...growthCoords); // cherry flower - }; - }; - }; - - //Make cherries - if (pixel.age > 40 && pixel.temp < 100) { - var cherryOffsets = [-1, 1]; //placed to the left, placed to the right - for(i = 0; i < cherryOffsets.length; i++) { - //console.log(`Looping through left and right positions: ${cherryOffsets}`); - for(j = 1; j < pixel.cherryRange + 1; j++) { //for max cherry distance, using the cherry range - //console.log(`Looping through cherry offset multipliers: ${j}`); - if (isEmpty(pixel.x+(j * cherryOffsets[i]),pixel.y,false)) { //if there's an empty space - //console.log(`Cherry position is empty: [${j * cherryOffsets[i]}, 0]\nTrying cherry at (${pixel.x+(j * cherryOffsets[i])},${pixel.y})`); - if (Math.random() < (debugSpeedGrowth ? 0.05 : 0.005)) { //try to place the cherry - //console.log(`Placing cherry`); - createPixel("cherry",pixel.x+(j * cherryOffsets[i]),pixel.y); - pixelMap[pixel.x+(j * cherryOffsets[i])][pixel.y].attached = true; - pixelMap[pixel.x+(j * cherryOffsets[i])][pixel.y].attachDirection = -1 * Math.sign(cherryOffsets[i]); //attach dir is the opposite of placement dir so it attaches towards the stem - } else { - //console.log(`NOT placing cherry`); - }; - //console.log(`Cherry tried, stopping iteration`); - break; //and then stop iteration - } else { - //console.log(`Cherry position is NOT empty: [${j * cherryOffsets[i]}, 0]\nSkipping this offset`); - continue; //if not empty, skip that pixel and move on the next distance - }; - //console.log(`====End of side try====`); - }; - //console.log(`####End of side iterator####`); - }; - //console.log(`>>>>End of cherry iterator<<<<`); - }; - pixel.age++; - doDefaults(pixel); - //console.log(`\nEnd of branch tick\n`); - }, - properties: { - "age": 0, - //"cherryRange": (1 + (Math.floor(Math.random() * 3))), //1-3 - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - }; - - elements.spoiled_cherry = { - hidden: true, - color: "#594b29", - behavior: [ - "XX|CR:stench,fly%0.1|XX", - "M2%0.5|CH:dirty_water,fly,fly%0.007|M2%0.5", - "M2|M1|M2" - ], - stain: 0.01, - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - tempHigh: 200, - stateHigh: ["steam", "ash"], - }; - - elements.fly.reactions.spoiled_cherry = { "elem2":null, chance:0.15, func:behaviors.FEEDPIXEL }; - - elements.cherry_leaf = { - hidden: true, - color: "#9df24e", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if(pixel.attached) { - var attachCoords = [pixel.x + pixel.attachOffsets[0], pixel.y + pixel.attachOffsets[1]]; - if(isEmpty(attachCoords[0],attachCoords[1],false)) { //consider OOB full - pixel.attached = false; - }; - } else { //Move if not attached - if(Math.random() < 0.2) { - if (!tryMove(pixel, pixel.x, pixel.y+1)) { - if(Math.random() < 0.4) { - if (Math.random() < 0.5) { - if (!tryMove(pixel, pixel.x+1, pixel.y+1)) { - tryMove(pixel, pixel.x-1, pixel.y+1); - }; - } else { - if (!tryMove(pixel, pixel.x-1, pixel.y+1)) { - tryMove(pixel, pixel.x+1, pixel.y+1); - }; - }; - }; - }; - }; - }; - doDefaults(pixel); - }, - properties: { - "attached": false, - "attachOffsets": [(!Math.floor(Math.random() * 2)) ? 1 : -1, 0], - "cherryRange": null, - }, - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - tempHigh: 200, - stateHigh: ["steam", "ash"], - onTryMoveInto: function(pixel,otherPixel) { //Move through - var otherElement = otherPixel.element; //var element for readability - - var otherInfo = elements[otherElement]; //var info - - var otherState = "solid"; //consider things solid by default - if(typeof(otherInfo.state) === "string") { - otherState = otherInfo.state; //get actual state if it exists - }; - - var otherDensity = 1000; //consider density 1000 by default - if(typeof(otherInfo.density) === "number") { - otherDensity = otherInfo.density; //get actual density if it exists - }; - - var react = false; //default to no reaction - if(typeof(otherInfo.reactions) === "object") { //look for reactions - if(typeof(otherInfo.reactions[pixel.element]) === "object") { //look for reactions involving this element - react = true; //if there are any, set reaction flag to true - }; - }; - - if(otherElement.endsWith("head") || otherElement.endsWith("body")) { - //i don't want to make general MPL handling so I'll just try to exclude them; - if(otherElement !== "antibody") { - //exclude antibody from exclusion - return false; - }; - }; - - if(otherElement !== pixel.element) { //allow this element from piling on itself - if(logLeaves) { console.log("Other element is not cherry leaves") }; //yes, this code is for cherry leaves - if(react) { //if there was a reaction in that previous step - if(logLeaves) { console.log("Reacting pixels") }; - reactPixels(otherPixel,pixel); //react - } else { //if no such reaction existed, move through - if(logLeaves) { console.log("Moving pixels") }; - if((otherState !== "solid") || (otherState === "solid" && otherDensity > 100)) { //admit any non-solid, or any solid with a density over 100 - var pX = pixel.x; //var pixel coords for no particular reason - var pY = pixel.y; - var oX = otherPixel.x; //var other pixel's coords for no particular reason - var oY = otherPixel.y; - if(logLeaves) { console.log(`${otherElement} pixel (${oX},${oY}) trying to move info leaf block (${pX},${pY})`) }; - var dX = oX - pX; //get the difference between this's X and other's X; if the other pixel is moving from the space immediately to the right, this dX value should be 1 - var dY = oY - pY; - var iDX = -1 * dX; //get the additive inverse; if we want to move such a pixel from the right to the left, we would change its +1 X offset to a -1 X offset for the coord sto move it to - var iDY = -1 * dY; - if(logLeaves) { console.log(`Old offset (relative to leaf): [${dX},${dY}], new offset [${iDX},${iDY}]`) }; - var fX = pX + iDX; //combine this pixel's X with the inverted offset we just made; - //assuming this pixel is (23,31) and the other pixel is trying to move in to the left into this from (24,31), - //the dX would be [1, 0], signifying that the other pixel is 1 pixel to the right of this - //the space to the left of this, where it would go, is (22,31), and the offset for that pixel relative to this is [-1, 0] - //to get the [-1, 0], we'd need to flip that [1, 0] offset (lmao flip that the song by loona), hence the inverse - var fY = pY + iDY; - if(logLeaves) { console.log(`Calculated final position: (${fX},${fY}), moving other pixel from (${oX},${oY})`) }; - tryMove(otherPixel,fX,fY); - }; - }; - }; - }, - }; - - /*if(!elements.diamond.reactions) { //test reaction - elements.diamond.reactions = {}; - }; - - elements.diamond.reactions.cherry_leaf = { "elem2": "dead_plant" };*/ - - elements.cherry_plant_top = { - hidden: true, - color: "#310a0b", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if (pixel.age > 30 && pixel.temp < 100) { - if(!pixel.grewLeftLeaves) { - for(i = (0 - pixel.leafRange); i < 0; i++) { //left half - if(i == 0) { - continue; - }; - - var leafOffset = i; //readability - var leafX = pixel.x + leafOffset; //set X to cherry_plant_top pixel's X + offset/index - var leafAttachOffset = [1, 0]; //difference 1: attaches rightwards (+) for leaves left (-) of center - var leafY = pixel.y; //set Y to default cherry_plant_top pixel's Y - if(Math.abs(leafOffset) == pixel.leafRange) { - leafY++; //place edge leaves 1 pixel downwards; - leafAttachOffset[1] = -1; //compensate by subtracting 1 from Y attach offset (less Y = higher position, so they attach diagonally up-right or up-left) - }; - - if(outOfBounds(leafX,leafY)) { - continue; - }; - - if (isEmpty(leafX,leafY,false)) { - createPixel("cherry_leaf",leafX,leafY); - pixelMap[leafX][leafY].attached = true; //set leaf's attached to true - pixelMap[leafX][leafY].attachOffsets = leafAttachOffset; //array of 2 numbers - pixelMap[leafX][leafY].cherryRange = pixel.cherryRange; - pixel.grewLeftLeaves = true; //difference 2: separate flag for left side - } else { - break; - }; - }; - }; - - if(!pixel.grewRightLeaves) { - for(i = 1; i < (pixel.leafRange + 1); i++) { //right half - if(i == 0) { - continue; - }; - - var leafOffset = i; //readability - var leafX = pixel.x + leafOffset; //set X to cherry_plant_top pixel's X + offset/index - var leafAttachOffset = [-1, 0]; //difference 1: attaches leftwards (-) for leaves right (+) of center - var leafY = pixel.y; //set Y to default cherry_plant_top pixel's Y - if(Math.abs(leafOffset) == pixel.leafRange) { - leafY++; //place edge leaves 1 pixel downwards; - leafAttachOffset[1] = -1; //compensate by subtracting 1 from Y attach offset (less Y = higher position, so they attach diagonally up-right or up-left) - }; - - if(outOfBounds(leafX,leafY)) { - continue; - }; - - if (isEmpty(leafX,leafY,false)) { - createPixel("cherry_leaf",leafX,leafY); - pixelMap[leafX][leafY].attached = true; //set leaf's attached to true - pixelMap[leafX][leafY].attachOffsets = leafAttachOffset; //array of 2 numbers - pixelMap[leafX][leafY].cherryRange = pixel.cherryRange; - pixel.grewRightLeaves = true; //difference 2: separate flag for right side - } else { - break; - }; - }; - }; - }; - pixel.age++; - doDefaults(pixel); - }, - properties: { - "age": 0, - "leafRange": 2 + (Math.floor(Math.random() * 3)), //2-4 - "grewLeftLeaves": false, - "grewRightLeaves": false, - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - }; - - - /*elements.cocoa_bean = { - color: ["#f2ede9", "#f0dfce", "#e8cfb5"], - behavior: behaviors.SOLID, - category: "liquids", - viscosity: 100000, - state: "liquid", - density: 593, - tick: functi - };*/ -} else { - enabledMods.splice(enabledMods.indexOf(modName),0,onTryMoveIntoMod); - enabledMods.splice(enabledMods.indexOf(modName),0,libraryMod); - localStorage.setItem("enabledMods", JSON.stringify(enabledMods)); - alert(`The ${onTryMoveIntoMod} mod and ${libraryMod} mods are required and have been automatically inserted (reload for this to take effect).`); +var modName = "mods/cherries.js"; +var onTryMoveIntoMod = "mods/onTryMoveInto.js"; +var libraryMod = "mods/code_library.js"; + +if(enabledMods.includes(onTryMoveIntoMod) && enabledMods.includes(libraryMod)) { + randomNumberFromOneToThree = function() { + return 1 + Math.floor(Math.random() * 3) + }; + + debugSpeedGrowth = false; + logLeaves = false; + cherryAttachWhitelist = ["cherry_log","cherry_branch_1","cherry_branch_2","blossom","cherry_leaf","cherry_plant_top","cherry"]; + + cherryDirtElements = ["dirt","mud","sand","wet_sand","clay_soil","mycelium","grass"]; + + function logPixelCoords(pixel) { + return `(${pixel.x}, ${pixel.y})` + }; + + function hasPixel(x,y,elementInput) { + if(isEmpty(x,y,true)) { //if empty, it can't have a pixel + return false; + } else { + if(elementInput.includes(",")) { //CSTA + elementInput = elementInput.split(","); + }; + if(Array.isArray(elementInput)) { //if element list + return elementInput.includes(pixelMap[x][y].element); + } else { //if single element + return pixelMap[x][y].element === elementInput; + }; + }; + }; + + elements.cherry_seed = { + color: "#8b4513", + tick: function(pixel) { + if(pixel.cherryRange === null) { + pixel.cherryRange = randomNumberFromOneToThree(); + }; + + if (isEmpty(pixel.x,pixel.y+1)) { + movePixel(pixel,pixel.x,pixel.y+1); + } else { + if (Math.random() < (debugSpeedGrowth ? 0.09 : 0.03) && pixel.age > (debugSpeedGrowth ? 20 : 50) && pixel.temp < 100) { + if (!outOfBounds(pixel.x,pixel.y+1)) { + var dirtPixel = pixelMap[pixel.x][pixel.y+1]; + if (cherryDirtElements.includes(dirtPixel.element)) { + changePixel(dirtPixel,"root"); + }; + }; + if (isEmpty(pixel.x,pixel.y-1)) { + movePixel(pixel,pixel.x,pixel.y-1); + createPixel("cherry_log",pixel.x,pixel.y+1); + pixelMap[pixel.x][pixel.y+1].cherryRange = pixel.cherryRange; //pass cherry range down to log + }; + } else if (pixel.age > (debugSpeedGrowth ? 500 : 1000)) { + changePixel(pixel,"cherry_plant_top"); + }; + pixel.age++; + }; + if(Math.random() < 0.01 && pixel.age > 200) { + changePixel(pixel,"cherry_plant_top"); + }; + doDefaults(pixel); + }, + properties: { + "age": 0, + //"cherryRange": null, //apparently this is suddenly, in an illogical, never-before-seen, completely new, unprecedented incident of bad behavior, evaluated before being put into the property database, so RNG has to be done in tick + "cherryRange": null, + }, + tempHigh: 100, + stateHigh: "dead_plant", + tempLow: -2, + stateLow: "frozen_plant", + burn: 5, + burnInto: ["steam", "ash"], + burnTime: 600, + category: "life", + state: "solid", + density: 1500, + cooldown: defaultCooldown, + }; + + elements.cherry_log = { + hidden: true, + color: "#310a0b", + tick: function(pixel) { + if(pixel.cherryRange === null) { + pixel.cherryRange = randomNumberFromOneToThree(); + }; + + if (pixel.age > 60 && pixel.temp < 100 && !pixel.grewPeduncle) { + var peduncleOffsets = [-1, 1]; //placed to the left, placed to the right + for(i = 0; i < peduncleOffsets.length; i++) { + if (isEmpty(pixel.x+peduncleOffsets[i],pixel.y,false)) { + if (Math.random() < 0.005) { + createPixel("cherry_branch_1",pixel.x+peduncleOffsets[i],pixel.y); + pixelMap[pixel.x+peduncleOffsets[i]][pixel.y].dir = Math.sign(peduncleOffsets[i]); + pixelMap[pixel.x+peduncleOffsets[i]][pixel.y].cherryRange = pixel.cherryRange; //pass cherry range down to branch + if(Math.random() < 0.8) { pixel.grewPeduncle = true; } //20% chance to not mark as true, allowing for a chance to try another branch + }; + }; + }; + }; + pixel.age++; + doDefaults(pixel); + }, + properties: { + "age": 0, + "grewPeduncle": false, + "cherryRange": null, + }, + tempHigh: 100, + stateHigh: "dead_plant", + tempLow: -2, + stateLow: "frozen_plant", + burn: 5, + burnInto: ["steam", "ash"], + burnTime: 600, + category: "life", + state: "solid", + density: 1500, + }; + + elements.cherry = { + color: "#f7022a", + tick: function(pixel) { + if(pixel.attached) { + var attachCoords = [pixel.x+Math.sign(pixel.attachDirection), pixel.y]; + if(isEmpty(attachCoords[0],attachCoords[1],false)) { + pixel.attached = false; + }; + } else { //Move if not attached + if (!tryMove(pixel, pixel.x, pixel.y+1)) { + if(Math.random() < 0.9) { + if (Math.random() < 0.5) { + if (!tryMove(pixel, pixel.x+1, pixel.y+1)) { + tryMove(pixel, pixel.x-1, pixel.y+1); + }; + } else { + if (!tryMove(pixel, pixel.x-1, pixel.y+1)) { + tryMove(pixel, pixel.x+1, pixel.y+1); + }; + }; + }; + }; + }; + doDefaults(pixel); + var shouldSpoil = true; //spoil by default + if(pixel.attached) { //if it's attached + if(!isEmpty(attachCoords[0],attachCoords[1],true)) { //if the attachment coords are a pixel and not OOB + var attachPixel = pixelMap[attachCoords[0]][attachCoords[1]]; + var attachElement = attachPixel.element; + if(cherryAttachWhitelist.includes(attachElement)) {//if the element is a whitelisted "don't spoil" element + shouldSpoil = false; //then don't spoil + }; + }; + }; + if(shouldSpoil) { //spoil if not attached + if(pixel.temp > -14 && pixel.temp <= 4) { //(no spoiling below 14C) + pixel.spoilage += Math.max(Math.min(scale(pixel.temp,-14,4,0,9),9),0) + } else if(pixel.temp > 4) { + pixel.spoilage += Math.max(Math.min(scale(pixel.temp,4,20,9,30),40),0) + }; + }; + if(pixel.spoilage > 14400) { //3600 = 120 ticks at 20C + if(Math.random() < 0.05) { + changePixel(pixel,"spoiled_cherry"); + }; + }; + }, + properties: { + "spoilage":0, + "attached": false, + "attachDirection": (!Math.floor(Math.random() * 2)) ? 1 : -1, + }, + burn: 5, + burnInto: ["steam", "ash"], + burnTime: 600, + tempHigh: 200, + stateHigh: ["steam", "ash"], + onTryMoveInto: function(pixel,otherPixel) { + var otherInfo = elements[otherPixel.element] + if(typeof(otherInfo.state) === "string" && otherInfo.state !== "gas") { + pixel.attached = false; + }; + }, + }; + + elements.cherry_branch_1 = { + hidden: true, + name: "cherry branch (offshoot)", + color: "#310a0b", + tick: function(pixel) { + if(pixel.cherryRange === null) { + pixel.cherryRange = randomNumberFromOneToThree(); + }; + + if (pixel.age > 20 && pixel.temp < 100) { + var peduncleCoords1 = [pixel.x + pixel.dir, pixel.y]; + var peduncleCoords2 = [pixel.x + pixel.dir, pixel.y + 1]; + if(isEmpty(peduncleCoords1[0],peduncleCoords1[1],false) && isEmpty(peduncleCoords2[0],peduncleCoords2[1],false)) { + if(Math.random() < 0.5) { + createPixel(pixel.element,peduncleCoords1[0],peduncleCoords1[1]); + pixelMap[peduncleCoords1[0]][peduncleCoords1[1]].dir = pixel.dir; + pixelMap[peduncleCoords1[0]][peduncleCoords1[1]].cherryRange = pixel.cherryRange; //pass cherry range down to next pixel of branch horizontal + } else { + createPixel("cherry_branch_2",peduncleCoords2[0],peduncleCoords2[1]); + pixelMap[peduncleCoords2[0]][peduncleCoords2[1]].cherryRange = pixel.cherryRange; //pass cherry range down to diagonal offshoot + }; + }; + }; + pixel.age++; + doDefaults(pixel); + }, + properties: { + "dir": (!Math.floor(Math.random() * 2)) ? 1 : -1, + "age": 0, + //"cherryRange": (1 + (Math.floor(Math.random() * 3))), //1-3 + "cherryRange": null, + }, + tempHigh: 100, + stateHigh: "dead_plant", + tempLow: -2, + stateLow: "frozen_plant", + burn: 5, + burnInto: ["steam", "ash"], + burnTime: 600, + category: "life", + state: "solid", + density: 1500, + }; + + elements.cherry_branch_2 = { + hidden: true, + name: "cherry branch (hanging)", + color: "#310a0b", + tick: function(pixel) { + if(pixel.cherryRange === null) { + pixel.cherryRange = randomNumberFromOneToThree(); + }; + + // Grow/Flower + if (pixel.age > 20 && pixel.temp < 100) { + var growthCoords = [pixel.x, pixel.y + 1]; + if(isEmpty(...growthCoords)) { + if(Math.random() < 0.9) { + createPixel(pixel.element,...growthCoords); + pixelMap[growthCoords[0]][growthCoords[1]].cherryRange = pixel.cherryRange; //pass cherry range down to next pixel of branch vertical + } else { + createPixel("blossom",...growthCoords); // cherry flower + }; + }; + }; + + //Make cherries + if (pixel.age > 40 && pixel.temp < 100) { + var cherryOffsets = [-1, 1]; //placed to the left, placed to the right + for(i = 0; i < cherryOffsets.length; i++) { + //console.log(`Looping through left and right positions: ${cherryOffsets}`); + for(j = 1; j < pixel.cherryRange + 1; j++) { //for max cherry distance, using the cherry range + //console.log(`Looping through cherry offset multipliers: ${j}`); + if (isEmpty(pixel.x+(j * cherryOffsets[i]),pixel.y,false)) { //if there's an empty space + //console.log(`Cherry position is empty: [${j * cherryOffsets[i]}, 0]\nTrying cherry at (${pixel.x+(j * cherryOffsets[i])},${pixel.y})`); + if (Math.random() < (debugSpeedGrowth ? 0.05 : 0.005)) { //try to place the cherry + //console.log(`Placing cherry`); + createPixel("cherry",pixel.x+(j * cherryOffsets[i]),pixel.y); + pixelMap[pixel.x+(j * cherryOffsets[i])][pixel.y].attached = true; + pixelMap[pixel.x+(j * cherryOffsets[i])][pixel.y].attachDirection = -1 * Math.sign(cherryOffsets[i]); //attach dir is the opposite of placement dir so it attaches towards the stem + } else { + //console.log(`NOT placing cherry`); + }; + //console.log(`Cherry tried, stopping iteration`); + break; //and then stop iteration + } else { + //console.log(`Cherry position is NOT empty: [${j * cherryOffsets[i]}, 0]\nSkipping this offset`); + continue; //if not empty, skip that pixel and move on the next distance + }; + //console.log(`====End of side try====`); + }; + //console.log(`####End of side iterator####`); + }; + //console.log(`>>>>End of cherry iterator<<<<`); + }; + pixel.age++; + doDefaults(pixel); + //console.log(`\nEnd of branch tick\n`); + }, + properties: { + "age": 0, + //"cherryRange": (1 + (Math.floor(Math.random() * 3))), //1-3 + "cherryRange": null, + }, + tempHigh: 100, + stateHigh: "dead_plant", + tempLow: -2, + stateLow: "frozen_plant", + burn: 5, + burnInto: ["steam", "ash"], + burnTime: 600, + category: "life", + state: "solid", + density: 1500, + }; + + elements.spoiled_cherry = { + hidden: true, + color: "#594b29", + behavior: [ + "XX|CR:stench,fly%0.1|XX", + "M2%0.5|CH:dirty_water,fly,fly%0.007|M2%0.5", + "M2|M1|M2" + ], + stain: 0.01, + burn: 5, + burnInto: ["steam", "ash"], + burnTime: 600, + tempHigh: 200, + stateHigh: ["steam", "ash"], + }; + + elements.fly.reactions.spoiled_cherry = { "elem2":null, chance:0.15, func:behaviors.FEEDPIXEL }; + + elements.cherry_leaf = { + hidden: true, + color: "#9df24e", + tick: function(pixel) { + if(pixel.cherryRange === null) { + pixel.cherryRange = randomNumberFromOneToThree(); + }; + + if(pixel.attached) { + var attachCoords = [pixel.x + pixel.attachOffsets[0], pixel.y + pixel.attachOffsets[1]]; + if(isEmpty(attachCoords[0],attachCoords[1],false)) { //consider OOB full + pixel.attached = false; + }; + } else { //Move if not attached + if(Math.random() < 0.2) { + if (!tryMove(pixel, pixel.x, pixel.y+1)) { + if(Math.random() < 0.4) { + if (Math.random() < 0.5) { + if (!tryMove(pixel, pixel.x+1, pixel.y+1)) { + tryMove(pixel, pixel.x-1, pixel.y+1); + }; + } else { + if (!tryMove(pixel, pixel.x-1, pixel.y+1)) { + tryMove(pixel, pixel.x+1, pixel.y+1); + }; + }; + }; + }; + }; + }; + doDefaults(pixel); + }, + properties: { + "attached": false, + "attachOffsets": [(!Math.floor(Math.random() * 2)) ? 1 : -1, 0], + "cherryRange": null, + }, + burn: 5, + burnInto: ["steam", "ash"], + burnTime: 600, + tempHigh: 200, + stateHigh: ["steam", "ash"], + onTryMoveInto: function(pixel,otherPixel) { //Move through + var otherElement = otherPixel.element; //var element for readability + + var otherInfo = elements[otherElement]; //var info + + var otherState = "solid"; //consider things solid by default + if(typeof(otherInfo.state) === "string") { + otherState = otherInfo.state; //get actual state if it exists + }; + + var otherDensity = 1000; //consider density 1000 by default + if(typeof(otherInfo.density) === "number") { + otherDensity = otherInfo.density; //get actual density if it exists + }; + + var react = false; //default to no reaction + if(typeof(otherInfo.reactions) === "object") { //look for reactions + if(typeof(otherInfo.reactions[pixel.element]) === "object") { //look for reactions involving this element + react = true; //if there are any, set reaction flag to true + }; + }; + + if(otherElement.endsWith("head") || otherElement.endsWith("body")) { + //i don't want to make general MPL handling so I'll just try to exclude them; + if(otherElement !== "antibody") { + //exclude antibody from exclusion + return false; + }; + }; + + if(otherElement !== pixel.element) { //allow this element from piling on itself + if(logLeaves) { console.log("Other element is not cherry leaves") }; //yes, this code is for cherry leaves + if(react) { //if there was a reaction in that previous step + if(logLeaves) { console.log("Reacting pixels") }; + reactPixels(otherPixel,pixel); //react + } else { //if no such reaction existed, move through + if(logLeaves) { console.log("Moving pixels") }; + if((otherState !== "solid") || (otherState === "solid" && otherDensity > 100)) { //admit any non-solid, or any solid with a density over 100 + var pX = pixel.x; //var pixel coords for no particular reason + var pY = pixel.y; + var oX = otherPixel.x; //var other pixel's coords for no particular reason + var oY = otherPixel.y; + if(logLeaves) { console.log(`${otherElement} pixel (${oX},${oY}) trying to move info leaf block (${pX},${pY})`) }; + var dX = oX - pX; //get the difference between this's X and other's X; if the other pixel is moving from the space immediately to the right, this dX value should be 1 + var dY = oY - pY; + var iDX = -1 * dX; //get the additive inverse; if we want to move such a pixel from the right to the left, we would change its +1 X offset to a -1 X offset for the coord sto move it to + var iDY = -1 * dY; + if(logLeaves) { console.log(`Old offset (relative to leaf): [${dX},${dY}], new offset [${iDX},${iDY}]`) }; + var fX = pX + iDX; //combine this pixel's X with the inverted offset we just made; + //assuming this pixel is (23,31) and the other pixel is trying to move in to the left into this from (24,31), + //the dX would be [1, 0], signifying that the other pixel is 1 pixel to the right of this + //the space to the left of this, where it would go, is (22,31), and the offset for that pixel relative to this is [-1, 0] + //to get the [-1, 0], we'd need to flip that [1, 0] offset (lmao flip that the song by loona), hence the inverse + var fY = pY + iDY; + if(logLeaves) { console.log(`Calculated final position: (${fX},${fY}), moving other pixel from (${oX},${oY})`) }; + tryMove(otherPixel,fX,fY); + }; + }; + }; + }, + }; + + /*if(!elements.diamond.reactions) { //test reaction + elements.diamond.reactions = {}; + }; + + elements.diamond.reactions.cherry_leaf = { "elem2": "dead_plant" };*/ + + elements.cherry_plant_top = { + hidden: true, + color: "#310a0b", + tick: function(pixel) { + if(pixel.cherryRange === null) { + pixel.cherryRange = randomNumberFromOneToThree(); + }; + + if (pixel.age > 30 && pixel.temp < 100) { + if(!pixel.grewLeftLeaves) { + for(i = (0 - pixel.leafRange); i < 0; i++) { //left half + if(i == 0) { + continue; + }; + + var leafOffset = i; //readability + var leafX = pixel.x + leafOffset; //set X to cherry_plant_top pixel's X + offset/index + var leafAttachOffset = [1, 0]; //difference 1: attaches rightwards (+) for leaves left (-) of center + var leafY = pixel.y; //set Y to default cherry_plant_top pixel's Y + if(Math.abs(leafOffset) == pixel.leafRange) { + leafY++; //place edge leaves 1 pixel downwards; + leafAttachOffset[1] = -1; //compensate by subtracting 1 from Y attach offset (less Y = higher position, so they attach diagonally up-right or up-left) + }; + + if(outOfBounds(leafX,leafY)) { + continue; + }; + + if (isEmpty(leafX,leafY,false)) { + createPixel("cherry_leaf",leafX,leafY); + pixelMap[leafX][leafY].attached = true; //set leaf's attached to true + pixelMap[leafX][leafY].attachOffsets = leafAttachOffset; //array of 2 numbers + pixelMap[leafX][leafY].cherryRange = pixel.cherryRange; + pixel.grewLeftLeaves = true; //difference 2: separate flag for left side + } else { + break; + }; + }; + }; + + if(!pixel.grewRightLeaves) { + for(i = 1; i < (pixel.leafRange + 1); i++) { //right half + if(i == 0) { + continue; + }; + + var leafOffset = i; //readability + var leafX = pixel.x + leafOffset; //set X to cherry_plant_top pixel's X + offset/index + var leafAttachOffset = [-1, 0]; //difference 1: attaches leftwards (-) for leaves right (+) of center + var leafY = pixel.y; //set Y to default cherry_plant_top pixel's Y + if(Math.abs(leafOffset) == pixel.leafRange) { + leafY++; //place edge leaves 1 pixel downwards; + leafAttachOffset[1] = -1; //compensate by subtracting 1 from Y attach offset (less Y = higher position, so they attach diagonally up-right or up-left) + }; + + if(outOfBounds(leafX,leafY)) { + continue; + }; + + if (isEmpty(leafX,leafY,false)) { + createPixel("cherry_leaf",leafX,leafY); + pixelMap[leafX][leafY].attached = true; //set leaf's attached to true + pixelMap[leafX][leafY].attachOffsets = leafAttachOffset; //array of 2 numbers + pixelMap[leafX][leafY].cherryRange = pixel.cherryRange; + pixel.grewRightLeaves = true; //difference 2: separate flag for right side + } else { + break; + }; + }; + }; + }; + pixel.age++; + doDefaults(pixel); + }, + properties: { + "age": 0, + "leafRange": 2 + (Math.floor(Math.random() * 3)), //2-4 + "grewLeftLeaves": false, + "grewRightLeaves": false, + "cherryRange": null, + }, + tempHigh: 100, + stateHigh: "dead_plant", + tempLow: -2, + stateLow: "frozen_plant", + burn: 5, + burnInto: ["steam", "ash"], + burnTime: 600, + category: "life", + state: "solid", + density: 1500, + }; + + + /*elements.cocoa_bean = { + color: ["#f2ede9", "#f0dfce", "#e8cfb5"], + behavior: behaviors.SOLID, + category: "liquids", + viscosity: 100000, + state: "liquid", + density: 593, + tick: functi + };*/ +} else { + enabledMods.splice(enabledMods.indexOf(modName),0,onTryMoveIntoMod); + enabledMods.splice(enabledMods.indexOf(modName),0,libraryMod); + localStorage.setItem("enabledMods", JSON.stringify(enabledMods)); + alert(`The ${onTryMoveIntoMod} mod and ${libraryMod} mods are required and have been automatically inserted (reload for this to take effect).`); }; \ No newline at end of file From 66d2fbd317d0892be5f524eb0a9b32931d977c41 Mon Sep 17 00:00:00 2001 From: lllllllllwith10ls <38187754+lllllllllwith10ls@users.noreply.github.com> Date: Thu, 20 Jul 2023 19:09:56 -0500 Subject: [PATCH 2/3] Delete yumcherries.js --- mods/yumcherries.js | 543 -------------------------------------------- 1 file changed, 543 deletions(-) delete mode 100644 mods/yumcherries.js diff --git a/mods/yumcherries.js b/mods/yumcherries.js deleted file mode 100644 index 29b7495d..00000000 --- a/mods/yumcherries.js +++ /dev/null @@ -1,543 +0,0 @@ -var modName = "mods/cherries.js"; -var onTryMoveIntoMod = "mods/onTryMoveInto.js"; -var libraryMod = "mods/code_library.js"; - -if(enabledMods.includes(onTryMoveIntoMod) && enabledMods.includes(libraryMod)) { - randomNumberFromOneToThree = function() { - return 1 + Math.floor(Math.random() * 3) - }; - - debugSpeedGrowth = false; - logLeaves = false; - cherryAttachWhitelist = ["cherry_log","cherry_branch_1","cherry_branch_2","blossom","cherry_leaf","cherry_plant_top","cherry"]; - - cherryDirtElements = ["dirt","mud","sand","wet_sand","clay_soil","mycelium","grass"]; - - function logPixelCoords(pixel) { - return `(${pixel.x}, ${pixel.y})` - }; - - function hasPixel(x,y,elementInput) { - if(isEmpty(x,y,true)) { //if empty, it can't have a pixel - return false; - } else { - if(elementInput.includes(",")) { //CSTA - elementInput = elementInput.split(","); - }; - if(Array.isArray(elementInput)) { //if element list - return elementInput.includes(pixelMap[x][y].element); - } else { //if single element - return pixelMap[x][y].element === elementInput; - }; - }; - }; - - elements.cherry_seed = { - color: "#8b4513", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if (isEmpty(pixel.x,pixel.y+1)) { - movePixel(pixel,pixel.x,pixel.y+1); - } else { - if (Math.random() < (debugSpeedGrowth ? 0.09 : 0.03) && pixel.age > (debugSpeedGrowth ? 20 : 50) && pixel.temp < 100) { - if (!outOfBounds(pixel.x,pixel.y+1)) { - var dirtPixel = pixelMap[pixel.x][pixel.y+1]; - if (cherryDirtElements.includes(dirtPixel.element)) { - changePixel(dirtPixel,"root"); - }; - }; - if (isEmpty(pixel.x,pixel.y-1)) { - movePixel(pixel,pixel.x,pixel.y-1); - createPixel("cherry_log",pixel.x,pixel.y+1); - pixelMap[pixel.x][pixel.y+1].cherryRange = pixel.cherryRange; //pass cherry range down to log - }; - } else if (pixel.age > (debugSpeedGrowth ? 500 : 1000)) { - changePixel(pixel,"cherry_plant_top"); - }; - pixel.age++; - }; - if(Math.random() < 0.01 && pixel.age > 200) { - changePixel(pixel,"cherry_plant_top"); - }; - doDefaults(pixel); - }, - properties: { - "age": 0, - //"cherryRange": null, //apparently this is suddenly, in an illogical, never-before-seen, completely new, unprecedented incident of bad behavior, evaluated before being put into the property database, so RNG has to be done in tick - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - cooldown: defaultCooldown, - }; - - elements.cherry_log = { - hidden: true, - color: "#310a0b", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if (pixel.age > 60 && pixel.temp < 100 && !pixel.grewPeduncle) { - var peduncleOffsets = [-1, 1]; //placed to the left, placed to the right - for(i = 0; i < peduncleOffsets.length; i++) { - if (isEmpty(pixel.x+peduncleOffsets[i],pixel.y,false)) { - if (Math.random() < 0.005) { - createPixel("cherry_branch_1",pixel.x+peduncleOffsets[i],pixel.y); - pixelMap[pixel.x+peduncleOffsets[i]][pixel.y].dir = Math.sign(peduncleOffsets[i]); - pixelMap[pixel.x+peduncleOffsets[i]][pixel.y].cherryRange = pixel.cherryRange; //pass cherry range down to branch - if(Math.random() < 0.8) { pixel.grewPeduncle = true; } //20% chance to not mark as true, allowing for a chance to try another branch - }; - }; - }; - }; - pixel.age++; - doDefaults(pixel); - }, - properties: { - "age": 0, - "grewPeduncle": false, - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - }; - - elements.cherry = { - color: "#f7022a", - tick: function(pixel) { - if(pixel.attached) { - var attachCoords = [pixel.x+Math.sign(pixel.attachDirection), pixel.y]; - if(isEmpty(attachCoords[0],attachCoords[1],false)) { - pixel.attached = false; - }; - } else { //Move if not attached - if (!tryMove(pixel, pixel.x, pixel.y+1)) { - if(Math.random() < 0.9) { - if (Math.random() < 0.5) { - if (!tryMove(pixel, pixel.x+1, pixel.y+1)) { - tryMove(pixel, pixel.x-1, pixel.y+1); - }; - } else { - if (!tryMove(pixel, pixel.x-1, pixel.y+1)) { - tryMove(pixel, pixel.x+1, pixel.y+1); - }; - }; - }; - }; - }; - doDefaults(pixel); - var shouldSpoil = true; //spoil by default - if(pixel.attached) { //if it's attached - if(!isEmpty(attachCoords[0],attachCoords[1],true)) { //if the attachment coords are a pixel and not OOB - var attachPixel = pixelMap[attachCoords[0]][attachCoords[1]]; - var attachElement = attachPixel.element; - if(cherryAttachWhitelist.includes(attachElement)) {//if the element is a whitelisted "don't spoil" element - shouldSpoil = false; //then don't spoil - }; - }; - }; - if(shouldSpoil) { //spoil if not attached - if(pixel.temp > -14 && pixel.temp <= 4) { //(no spoiling below 14C) - pixel.spoilage += Math.max(Math.min(scale(pixel.temp,-14,4,0,9),9),0) - } else if(pixel.temp > 4) { - pixel.spoilage += Math.max(Math.min(scale(pixel.temp,4,20,9,30),40),0) - }; - }; - if(pixel.spoilage > 14400) { //3600 = 120 ticks at 20C - if(Math.random() < 0.05) { - changePixel(pixel,"spoiled_cherry"); - }; - }; - }, - properties: { - "spoilage":0, - "attached": false, - "attachDirection": (!Math.floor(Math.random() * 2)) ? 1 : -1, - }, - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - tempHigh: 200, - stateHigh: ["steam", "ash"], - onTryMoveInto: function(pixel,otherPixel) { - var otherInfo = elements[otherPixel.element] - if(typeof(otherInfo.state) === "string" && otherInfo.state !== "gas") { - pixel.attached = false; - }; - }, - }; - - elements.cherry_branch_1 = { - hidden: true, - name: "cherry branch (offshoot)", - color: "#310a0b", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if (pixel.age > 20 && pixel.temp < 100) { - var peduncleCoords1 = [pixel.x + pixel.dir, pixel.y]; - var peduncleCoords2 = [pixel.x + pixel.dir, pixel.y + 1]; - if(isEmpty(peduncleCoords1[0],peduncleCoords1[1],false) && isEmpty(peduncleCoords2[0],peduncleCoords2[1],false)) { - if(Math.random() < 0.5) { - createPixel(pixel.element,peduncleCoords1[0],peduncleCoords1[1]); - pixelMap[peduncleCoords1[0]][peduncleCoords1[1]].dir = pixel.dir; - pixelMap[peduncleCoords1[0]][peduncleCoords1[1]].cherryRange = pixel.cherryRange; //pass cherry range down to next pixel of branch horizontal - } else { - createPixel("cherry_branch_2",peduncleCoords2[0],peduncleCoords2[1]); - pixelMap[peduncleCoords2[0]][peduncleCoords2[1]].cherryRange = pixel.cherryRange; //pass cherry range down to diagonal offshoot - }; - }; - }; - pixel.age++; - doDefaults(pixel); - }, - properties: { - "dir": (!Math.floor(Math.random() * 2)) ? 1 : -1, - "age": 0, - //"cherryRange": (1 + (Math.floor(Math.random() * 3))), //1-3 - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - }; - - elements.cherry_branch_2 = { - hidden: true, - name: "cherry branch (hanging)", - color: "#310a0b", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - // Grow/Flower - if (pixel.age > 20 && pixel.temp < 100) { - var growthCoords = [pixel.x, pixel.y + 1]; - if(isEmpty(...growthCoords)) { - if(Math.random() < 0.9) { - createPixel(pixel.element,...growthCoords); - pixelMap[growthCoords[0]][growthCoords[1]].cherryRange = pixel.cherryRange; //pass cherry range down to next pixel of branch vertical - } else { - createPixel("blossom",...growthCoords); // cherry flower - }; - }; - }; - - //Make cherries - if (pixel.age > 40 && pixel.temp < 100) { - var cherryOffsets = [-1, 1]; //placed to the left, placed to the right - for(i = 0; i < cherryOffsets.length; i++) { - //console.log(`Looping through left and right positions: ${cherryOffsets}`); - for(j = 1; j < pixel.cherryRange + 1; j++) { //for max cherry distance, using the cherry range - //console.log(`Looping through cherry offset multipliers: ${j}`); - if (isEmpty(pixel.x+(j * cherryOffsets[i]),pixel.y,false)) { //if there's an empty space - //console.log(`Cherry position is empty: [${j * cherryOffsets[i]}, 0]\nTrying cherry at (${pixel.x+(j * cherryOffsets[i])},${pixel.y})`); - if (Math.random() < (debugSpeedGrowth ? 0.05 : 0.005)) { //try to place the cherry - //console.log(`Placing cherry`); - createPixel("cherry",pixel.x+(j * cherryOffsets[i]),pixel.y); - pixelMap[pixel.x+(j * cherryOffsets[i])][pixel.y].attached = true; - pixelMap[pixel.x+(j * cherryOffsets[i])][pixel.y].attachDirection = -1 * Math.sign(cherryOffsets[i]); //attach dir is the opposite of placement dir so it attaches towards the stem - } else { - //console.log(`NOT placing cherry`); - }; - //console.log(`Cherry tried, stopping iteration`); - break; //and then stop iteration - } else { - //console.log(`Cherry position is NOT empty: [${j * cherryOffsets[i]}, 0]\nSkipping this offset`); - continue; //if not empty, skip that pixel and move on the next distance - }; - //console.log(`====End of side try====`); - }; - //console.log(`####End of side iterator####`); - }; - //console.log(`>>>>End of cherry iterator<<<<`); - }; - pixel.age++; - doDefaults(pixel); - //console.log(`\nEnd of branch tick\n`); - }, - properties: { - "age": 0, - //"cherryRange": (1 + (Math.floor(Math.random() * 3))), //1-3 - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - }; - - elements.spoiled_cherry = { - hidden: true, - color: "#594b29", - behavior: [ - "XX|CR:stench,fly%0.1|XX", - "M2%0.5|CH:dirty_water,fly,fly%0.007|M2%0.5", - "M2|M1|M2" - ], - stain: 0.01, - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - tempHigh: 200, - stateHigh: ["steam", "ash"], - }; - - elements.fly.reactions.spoiled_cherry = { "elem2":null, chance:0.15, func:behaviors.FEEDPIXEL }; - - elements.cherry_leaf = { - hidden: true, - color: "#9df24e", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if(pixel.attached) { - var attachCoords = [pixel.x + pixel.attachOffsets[0], pixel.y + pixel.attachOffsets[1]]; - if(isEmpty(attachCoords[0],attachCoords[1],false)) { //consider OOB full - pixel.attached = false; - }; - } else { //Move if not attached - if(Math.random() < 0.2) { - if (!tryMove(pixel, pixel.x, pixel.y+1)) { - if(Math.random() < 0.4) { - if (Math.random() < 0.5) { - if (!tryMove(pixel, pixel.x+1, pixel.y+1)) { - tryMove(pixel, pixel.x-1, pixel.y+1); - }; - } else { - if (!tryMove(pixel, pixel.x-1, pixel.y+1)) { - tryMove(pixel, pixel.x+1, pixel.y+1); - }; - }; - }; - }; - }; - }; - doDefaults(pixel); - }, - properties: { - "attached": false, - "attachOffsets": [(!Math.floor(Math.random() * 2)) ? 1 : -1, 0], - "cherryRange": null, - }, - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - tempHigh: 200, - stateHigh: ["steam", "ash"], - onTryMoveInto: function(pixel,otherPixel) { //Move through - var otherElement = otherPixel.element; //var element for readability - - var otherInfo = elements[otherElement]; //var info - - var otherState = "solid"; //consider things solid by default - if(typeof(otherInfo.state) === "string") { - otherState = otherInfo.state; //get actual state if it exists - }; - - var otherDensity = 1000; //consider density 1000 by default - if(typeof(otherInfo.density) === "number") { - otherDensity = otherInfo.density; //get actual density if it exists - }; - - var react = false; //default to no reaction - if(typeof(otherInfo.reactions) === "object") { //look for reactions - if(typeof(otherInfo.reactions[pixel.element]) === "object") { //look for reactions involving this element - react = true; //if there are any, set reaction flag to true - }; - }; - - if(otherElement.endsWith("head") || otherElement.endsWith("body")) { - //i don't want to make general MPL handling so I'll just try to exclude them; - if(otherElement !== "antibody") { - //exclude antibody from exclusion - return false; - }; - }; - - if(otherElement !== pixel.element) { //allow this element from piling on itself - if(logLeaves) { console.log("Other element is not cherry leaves") }; //yes, this code is for cherry leaves - if(react) { //if there was a reaction in that previous step - if(logLeaves) { console.log("Reacting pixels") }; - reactPixels(otherPixel,pixel); //react - } else { //if no such reaction existed, move through - if(logLeaves) { console.log("Moving pixels") }; - if((otherState !== "solid") || (otherState === "solid" && otherDensity > 100)) { //admit any non-solid, or any solid with a density over 100 - var pX = pixel.x; //var pixel coords for no particular reason - var pY = pixel.y; - var oX = otherPixel.x; //var other pixel's coords for no particular reason - var oY = otherPixel.y; - if(logLeaves) { console.log(`${otherElement} pixel (${oX},${oY}) trying to move info leaf block (${pX},${pY})`) }; - var dX = oX - pX; //get the difference between this's X and other's X; if the other pixel is moving from the space immediately to the right, this dX value should be 1 - var dY = oY - pY; - var iDX = -1 * dX; //get the additive inverse; if we want to move such a pixel from the right to the left, we would change its +1 X offset to a -1 X offset for the coord sto move it to - var iDY = -1 * dY; - if(logLeaves) { console.log(`Old offset (relative to leaf): [${dX},${dY}], new offset [${iDX},${iDY}]`) }; - var fX = pX + iDX; //combine this pixel's X with the inverted offset we just made; - //assuming this pixel is (23,31) and the other pixel is trying to move in to the left into this from (24,31), - //the dX would be [1, 0], signifying that the other pixel is 1 pixel to the right of this - //the space to the left of this, where it would go, is (22,31), and the offset for that pixel relative to this is [-1, 0] - //to get the [-1, 0], we'd need to flip that [1, 0] offset (lmao flip that the song by loona), hence the inverse - var fY = pY + iDY; - if(logLeaves) { console.log(`Calculated final position: (${fX},${fY}), moving other pixel from (${oX},${oY})`) }; - tryMove(otherPixel,fX,fY); - }; - }; - }; - }, - }; - - /*if(!elements.diamond.reactions) { //test reaction - elements.diamond.reactions = {}; - }; - - elements.diamond.reactions.cherry_leaf = { "elem2": "dead_plant" };*/ - - elements.cherry_plant_top = { - hidden: true, - color: "#310a0b", - tick: function(pixel) { - if(pixel.cherryRange === null) { - pixel.cherryRange = randomNumberFromOneToThree(); - }; - - if (pixel.age > 30 && pixel.temp < 100) { - if(!pixel.grewLeftLeaves) { - for(i = (0 - pixel.leafRange); i < 0; i++) { //left half - if(i == 0) { - continue; - }; - - var leafOffset = i; //readability - var leafX = pixel.x + leafOffset; //set X to cherry_plant_top pixel's X + offset/index - var leafAttachOffset = [1, 0]; //difference 1: attaches rightwards (+) for leaves left (-) of center - var leafY = pixel.y; //set Y to default cherry_plant_top pixel's Y - if(Math.abs(leafOffset) == pixel.leafRange) { - leafY++; //place edge leaves 1 pixel downwards; - leafAttachOffset[1] = -1; //compensate by subtracting 1 from Y attach offset (less Y = higher position, so they attach diagonally up-right or up-left) - }; - - if(outOfBounds(leafX,leafY)) { - continue; - }; - - if (isEmpty(leafX,leafY,false)) { - createPixel("cherry_leaf",leafX,leafY); - pixelMap[leafX][leafY].attached = true; //set leaf's attached to true - pixelMap[leafX][leafY].attachOffsets = leafAttachOffset; //array of 2 numbers - pixelMap[leafX][leafY].cherryRange = pixel.cherryRange; - pixel.grewLeftLeaves = true; //difference 2: separate flag for left side - } else { - break; - }; - }; - }; - - if(!pixel.grewRightLeaves) { - for(i = 1; i < (pixel.leafRange + 1); i++) { //right half - if(i == 0) { - continue; - }; - - var leafOffset = i; //readability - var leafX = pixel.x + leafOffset; //set X to cherry_plant_top pixel's X + offset/index - var leafAttachOffset = [-1, 0]; //difference 1: attaches leftwards (-) for leaves right (+) of center - var leafY = pixel.y; //set Y to default cherry_plant_top pixel's Y - if(Math.abs(leafOffset) == pixel.leafRange) { - leafY++; //place edge leaves 1 pixel downwards; - leafAttachOffset[1] = -1; //compensate by subtracting 1 from Y attach offset (less Y = higher position, so they attach diagonally up-right or up-left) - }; - - if(outOfBounds(leafX,leafY)) { - continue; - }; - - if (isEmpty(leafX,leafY,false)) { - createPixel("cherry_leaf",leafX,leafY); - pixelMap[leafX][leafY].attached = true; //set leaf's attached to true - pixelMap[leafX][leafY].attachOffsets = leafAttachOffset; //array of 2 numbers - pixelMap[leafX][leafY].cherryRange = pixel.cherryRange; - pixel.grewRightLeaves = true; //difference 2: separate flag for right side - } else { - break; - }; - }; - }; - }; - pixel.age++; - doDefaults(pixel); - }, - properties: { - "age": 0, - "leafRange": 2 + (Math.floor(Math.random() * 3)), //2-4 - "grewLeftLeaves": false, - "grewRightLeaves": false, - "cherryRange": null, - }, - tempHigh: 100, - stateHigh: "dead_plant", - tempLow: -2, - stateLow: "frozen_plant", - burn: 5, - burnInto: ["steam", "ash"], - burnTime: 600, - category: "life", - state: "solid", - density: 1500, - }; - - - /*elements.cocoa_bean = { - color: ["#f2ede9", "#f0dfce", "#e8cfb5"], - behavior: behaviors.SOLID, - category: "liquids", - viscosity: 100000, - state: "liquid", - density: 593, - tick: functi - };*/ -} else { - enabledMods.splice(enabledMods.indexOf(modName),0,onTryMoveIntoMod); - enabledMods.splice(enabledMods.indexOf(modName),0,libraryMod); - localStorage.setItem("enabledMods", JSON.stringify(enabledMods)); - alert(`The ${onTryMoveIntoMod} mod and ${libraryMod} mods are required and have been automatically inserted (reload for this to take effect).`); -}; \ No newline at end of file From 33b9907afd664546903a6831dc841436a10d91fe Mon Sep 17 00:00:00 2001 From: lllllllllwith10ls <38187754+lllllllllwith10ls@users.noreply.github.com> Date: Tue, 15 Aug 2023 21:54:02 -0500 Subject: [PATCH 3/3] Fixed some bugs in chem.js, mobs.js, and onTryMoveInto.js --- mods/chem.js | 7 +++++-- mods/mobs.js | 2 +- mods/onTryMoveInto.js | 8 +++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mods/chem.js b/mods/chem.js index c1e3b9a1..a4fd8fcc 100644 --- a/mods/chem.js +++ b/mods/chem.js @@ -411,8 +411,8 @@ if (enabledMods.includes("mods/generative_mods.js")) { elements["hydrofluoric_acid_gas"].reactions["pyrocumulus"]= { "elem1": null, "elem2": "hydrofluoric_acid_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; elements["hydrofluoric_acid_gas"].reactions["fire_cloud"]= { "elem1": null, "elem2": "hydrofluoric_acid_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; - elements["cloud"].reactions["anesthesia"] = { elem1:"acid_cloud", elem2:null, chance:0.05 }; - elements["rain_cloud"].reactions["anesthesia"] = { elem1:"acid_cloud", elem2:null, chance:0.05 }; + elements["cloud"].reactions["anesthesia"] = { elem1:"nitric_acid_cloud", elem2:null, chance:0.05 }; + elements["rain_cloud"].reactions["anesthesia"] = { elem1:"nitric_acid_cloud", elem2:null, chance:0.05 }; } function createAcid(name,reactions, gasReactions, color, category, categoryGas, tempHigh, tempLowGas, tempLow, tempHighGas, density, densityGas) @@ -462,6 +462,7 @@ function createAcid(name,reactions, gasReactions, color, category, categoryGas, if (enabledMods.includes("mods/generative_mods.js")) { runAfterLoad(function() { generateCloud(name); + console.log(name); }); elements[name+"_gas"].reactions[name+"_gas"]= { "elem1": null, "elem2": name + "_cloud", "chance":0.3, "y":[0,12], "setting":"clouds" }; elements[name+"_gas"].reactions["rain_cloud"]= { "elem1": null, "elem2": name + "_cloud", "chance":0.4, "y":[0,12], "setting":"clouds" }; @@ -2197,9 +2198,11 @@ elements.molten_iodine = { behavior: behaviors.LIQUID, tempHigh: 184, tempLow: 113, + temp: 123, stateHigh: "iodine_gas", stateLow: "iodine", state: "liquid", + hidden: true, }; elements.iodine_gas = { diff --git a/mods/mobs.js b/mods/mobs.js index d1ae8033..7761f24f 100644 --- a/mods/mobs.js +++ b/mods/mobs.js @@ -197,7 +197,7 @@ if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(explodeAtPlu if(Array.isArray(breakIntoElement)) { breakIntoElement = breakIntoElement[Math.floor(Math.random() * breakIntoElement.length)] }; - if(typeof(breakIntoElement) === "undefined") { + if(typeof(breakIntoElement) === "undefined" || breakIntoElement === null) { deletePixel(pixel.x,pixel.y); return true; }; diff --git a/mods/onTryMoveInto.js b/mods/onTryMoveInto.js index 0261f691..a66279a4 100644 --- a/mods/onTryMoveInto.js +++ b/mods/onTryMoveInto.js @@ -9,6 +9,8 @@ elements.on_try_move_into_test = { "dirt": { elem1: "diamond" }, }, state: "solid", + hidden: true, + excludeRandom: true, category: "special", density: 1000, tick: function(pixel) { @@ -42,12 +44,13 @@ function tryMove(pixel,nx,ny,leaveBehind,force) { // Reactions newPixel = pixelMap[nx][ny]; var newInfo = elements[newPixel.element]; + var returnVal = false; if(newInfo.onTryMoveInto !== undefined) { newInfo.onTryMoveInto(newPixel,pixel); if(!pixel || pixel.del) { return "deleted"; }; - return true; + returnVal = true; } var rr1 = false; if (info.reactions !== undefined && info.reactions[newPixel.element] !== undefined) { @@ -74,6 +77,9 @@ function tryMove(pixel,nx,ny,leaveBehind,force) { } } } + if(returnVal) { + return true; + } } return false; }