From 5082c23afd81d2c94b992ce0876e61f37814f18e Mon Sep 17 00:00:00 2001 From: Rain <58303213+rainingBrackets@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:48:47 +0200 Subject: [PATCH 01/10] Add files via upload --- moving_pixels.js | 179 +++++++++++++++++++++++++++++++++++++++++++++++ nitroglycerin.js | 54 ++++++++++++++ plastic.js | 93 ++++++++++++++++++++++++ 3 files changed, 326 insertions(+) create mode 100644 moving_pixels.js create mode 100644 nitroglycerin.js create mode 100644 plastic.js diff --git a/moving_pixels.js b/moving_pixels.js new file mode 100644 index 00000000..3c8d6e65 --- /dev/null +++ b/moving_pixels.js @@ -0,0 +1,179 @@ + +// created by Rain :o 20/8 2024 + +elements.car = { + //color: ["#E37F6F", "#B075DF", "#4F8FEF"], + color: ["#ee70aa", "#ab33ef", "#5e6eee"], + category: "special", + density: 10000, + state: "solid", + tempHigh: 400, + stateHigh: ["steel", "molten_plastic", "glass"], + breakInto: ["steel", "plastic", "glass_shard"], + reactions: { + "water": { elem1: "rust", chance: 0.003 }, + "dirty_water": { elem1: "rust", chance: 0.003 }, + "salt_water": { elem1: "rust", chance: 0.006 }, + "grape": { elem2: "juice", chance: 0.1, color2: "#291824" }, + "tomato": { elem2: "sauce", chance: 0.1 }, + "egg": { elem2: "yolk", chance: 0.1 }, + "malware": {elem1: "explosion"}, + }, + flippableX: true, + tick: function (pixel) { + + if (pixel.carFlip === undefined) { + pixel.carFlip = 1; //it's the "pixel." that gives the variable to each car instance, very important :) + } + tryMove(pixel, pixel.x, pixel.y + 1); //try to move down (fall) + if (!isEmpty(pixel.x, pixel.y + 1)) { //if it didn't work (if the car is on the ground): + + if (isEmpty(pixel.x + pixel.carFlip, pixel.y + 1)) { + tryMove(pixel, pixel.x + pixel.carFlip, pixel.y + 1); // move diagonally down to avoid falling when going downhill + } + else if (isEmpty(pixel.x + pixel.carFlip, pixel.y)) { + tryMove(pixel, pixel.x + pixel.carFlip, pixel.y); //move to the side (which side is derived from current carFlip state) + + } else if (isEmpty(pixel.x + pixel.carFlip, pixel.y - 1)) { + tryMove(pixel, pixel.x + pixel.carFlip, pixel.y - 1); //move diagonally up the hill + + } else { //if no movement possible (like when hitting a wall): + pixel.carFlip = pixel.carFlip * -1; // Update carFlip for this car instance + } + + doDefaults(pixel); + } + }, +}; + +elements.tram = { + color: "#93E493", + conduct: 1, + category: "special", + density: 10000, + state: "solid", + tempHigh: 400, + stateHigh: ["molten_aluminum", "molten_plastic", "glass"], + breakInto: ["aluminum", "plastic", "glass_shard"], + flippableX: true, + desc: "Powered by electricity. Can hang on conductive materials for suspension railway", + reactions: { + "malware": { elem2: "electric" }, + }, + tick: function (pixel) { + + if (pixel.tramFlip === undefined) { + pixel.tramFlip = 1; //tramFlip works like carFlip for the car + } + + if (pixel.charge > 0) { //only if powered by electricity + + if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 2)) { + var diUpPixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y - 2] //establishes the variable. Must be down here because it would crash if there is no diUpPixel + if (elements[diUpPixel.element].conduct && diUpPixel.element !== "tram") { //^ is also the reason this is a seperate if statement + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y - 1); //move diagonally upwards if there is support + } + else { + pixel.tramFlip = pixel.tramFlip * -1; + } + } + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1)) { + var sidePixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y - 1] + if (elements[sidePixel.element].conduct && sidePixel.element !== "tram") { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y); //move to the side if there is support + } + else { + pixel.tramFlip = pixel.tramFlip * -1; + } + } + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y + 1) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y)) { + var diDownPixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y] + if (elements[diDownPixel.element].conduct && diDownPixel.element !== "tram") { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y + 1); //move diagonally downwards if there is support + } + else { + pixel.tramFlip = pixel.tramFlip * -1; + } + } + + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y + 1) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y)) { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y + 1); //move diagonally downwards if there isn't support + } + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1)) { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y); //move to the side if there isn't support + } + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 2)) { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y - 1); //move diagonally upwards if there isn't support (uphill) + } + else { + pixel.tramFlip = pixel.tramFlip * -1; + } + + } + else { //if not powered + if (!isEmpty(pixel.x, pixel.y - 1)) { + var upPixel = pixelMap[pixel.x][pixel.y - 1] //looks at the properties of the pixel above + if (elements[upPixel.element].conduct > 0.1 && upPixel.element !== "tram") { //if the pixel above is conductive but not tram + //nothing happens ie it doesn't fall + } + else { + tryMove(pixel, pixel.x, pixel.y + 1); //it falls down + } + } + else { + tryMove(pixel, pixel.x, pixel.y + 1); //it falls down (same as above) + } + + } + doDefaults(pixel) + }, +}; +elements.bouncy_ball = { + color: "#e35693", + behavior: behaviors.WALL, + tempHigh: 250, + stateHigh: ["borax", "glue"], + category: "special", + conduct: 1, + tick: function (pixel) { + if (pixel.fallDist === undefined) { + pixel.fallDist = 0; + } + if (pixel.isFalling === undefined) { + pixel.isFalling = true; + } + + if (pixel.isFalling) { //main loop of a bouncy ball. Functions are defined below + falling() + } else { + rising() + } + if (pixel.charge > 0) { //will bounce on electricity (doesn't work on real bouncy balls :/) + pixel.fallDist = (pixel.fallDist + 1) + rising() + } + + function falling() { + + if (isEmpty(pixel.x, pixel.y + 1)) { + tryMove(pixel, pixel.x, pixel.y + 1) + pixel.fallDist += 1; //counts how many pixels the ball has fallen so far + } else { //if it touched the ground + pixel.isFalling = false; //will change the outcome of the main if statement and make ball start rising + pixel.fallDist = pixel.fallDist * 3 / 4; //dynamically decreases bounce height based on how high it is, instead of constant 1 per bounce + } + } + function rising() { + if (pixel.fallDist > 0) { + tryMove(pixel, pixel.x, pixel.y - 1) + pixel.fallDist -= 1 + } else { + pixel.isFalling = true; + pixel.fallDist -= 1 //makes the ball lose 1 pixel height each bounce, useful at the end when * 3/4 only results in fractions + } + + } + + } +}; +elements.borax.reactions.slime = { elem1: "bouncy_ball", elem2: null}; \ No newline at end of file diff --git a/nitroglycerin.js b/nitroglycerin.js new file mode 100644 index 00000000..97befd1a --- /dev/null +++ b/nitroglycerin.js @@ -0,0 +1,54 @@ + +// created by Rain :o 20/8 2024 + +elements.glycerol = { + color: "#eeeeee", + behavior: behaviors.LIQUID, + viscosity: 1412, + category: "liquids", + state: "liquid", + density: 1261, + tempLow: 18, + tempHigh: 290, + tick: function (pixel) { + pixel.color = "rgba(250, 250, 250, 0.7)"; + }, + reactions: { + }, + burn: 5, + burnTime: 40, +}; + +elements.nitro.tempHigh = 218; //More accurate detonation temperature +elements.salt_water.tempLow = -20; //melting point depression + +elements.nitro.tick = function (pixel) { // Exothermic decomposition of nitroglycerin when above 60° + if (pixel.temp > 60) { + pixel.temp += 1; + if (Math.random() > 0.999) { + var possibleElements = ["oxygen", "nitrogen", "nitrogen", "steam", "steam", "steam", "carbon_dioxide", "carbon_dioxide", "carbon_dioxide"]; //array of possibilities for changing the nitroglycerin pixel + + var randomElement = possibleElements[Math.floor(Math.random() * possibleElements.length)]; //randomly selecting an element from the array + + changePixel(pixel, randomElement); // Change the pixel to the randomly selected element + } + } +} + +if (enabledMods.includes("mods/chem.js")) { + runAfterLoad(function () { + elements.glycerol.reactions.nitric_acid = { elem1: "nitro", chance: 0.05, temp1: 70 }; //nitric acid nitrates glycerol to make nitroglycerin + elements.nitric_acid.ignore.push("glycerol", "nitro") //added my glycerol and nitro to allow for making nitroglycerin + + elements.copper.reactions.sulfuric_acid = { elem1: "copper_sulfate", elem2: null, chance: 0.1 }; //this is how you can actually make CuSO4 + elements.sulfuric_acid.ignore.push("copper_sulfate") + + elements.grease.reactions.sodium_hydroxide = { elem1: "soap", elem2: "null", chance: 0.04, tempMin: 40 }; + elements.sodium_hydroxide.ignore.push("grease", "soap", "fat"); + + + }); +} else { + elements.glycerol.reactions.acid = { elem1: "nitro", chance: 0.05, temp1: 70 }; //if we don't have nitric acid from chem.js, "acid" is a good approximation + elements.acid.ignore.push("glycerol", "nitro") +} \ No newline at end of file diff --git a/plastic.js b/plastic.js new file mode 100644 index 00000000..ed90927b --- /dev/null +++ b/plastic.js @@ -0,0 +1,93 @@ + +// created by Rain :o 20/8 2024 + +elements.water_bottle = { + color: "#a8d2e3", + behavior: behaviors.STURDYPOWDER, + category: "powders", + state: "solid", + density: 800, + breakInto: ["water_everywhere", "water_everywhere", "water_everywhere", "water_everywhere", "microplastic"], + tempHigh: 250, + stateHigh: ["molten_plastic", "water_everywhere", "water_everywhere"], +}; +elements.head.reactions.water_bottle = { elem2: ["plastic", "water", null, null, null], chance: 0.1 }; +elements.body.reactions.water_bottle = { elem2: ["plastic", "water", null, null, null], chance: 0.1 }; + +elements.water_everywhere = { + color: "#8882e3", + behavior: [ + "CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water", + "CR:water_everywhere%20 AND CR:water|XX%20 AND CH:water|CR:water_everywhere%20 AND CR:water", + "CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water", + ], + category: "liquids", + state: "solid", + density: 800, + hidden: true, +}; +elements.microplastic = { + color: ["#adc7c9", "#cadadb", "#6cbda8", "#62d5d4", "#b3b47b"], + behavior: [ + "XX|XX|XX", + "XX|XX|XX", + "M2%25|M1%50|M2%25", + ], + category: "powders", + state: "solid", + density: 700, + tempHigh: 250, + stateHigh: "molten_plastic", + reactions: { + "fish": { elem1: null, elem2: "meat", chance: 0.01 }, + "glue": { elem1: "bead", elem2: null, chance: 0.03 }, + }, +}; +elements.plastic.breakInto = "microplastic"; + +elements.cellulose.reactions.vinegar = { elem1: "bioplastic", elem2: null, tempMin: 40, chance: 0.1}; + +elements.bioplastic = { + color: "#eeeeaa", + behavior: behaviors.WALL, + category: "solids", + tempHigh: 180, + stateHigh: "molten_bioplastic", + breakInto: "bioplastic_crumbs", + alias: "Cellulose acetate", + desc: "It's biodegradable :)", +}; +elements.bioplastic_crumbs = { + color: ["#dfd499", "#c0e8a0", "#dfab87"], + hidden: true, + behavior: behaviors.POWDER, + category: "powders", + tempHigh: 180, + stateHigh: "molten_bioplastic", + desc: "small pieces of cellulose acetate" +}; + +elements.worm.reactions.bioplastic = { elem2: ["carbon_dioxide", null, null], chance: 0.05, func: behaviors.FEEDPIXEL }; +elements.worm.reactions.bioplastic_crumbs = { elem2: ["carbon_dioxide", null, null], chance: 0.05, func: behaviors.FEEDPIXEL }; +elements.worm.behavior = [ + "SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic%3|XX|SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic,bioplastic_crumbs%3", + "M2%10|XX|M2%10", + "SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic%3|M1|SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic,bioplastic_crumbs%3", +]; +elements.cell.reactions.bioplastic = { elem2: ["carbon_dioxide", null, null], chance: 0.02, func: behaviors.FEEDPIXEL }; +elements.cell.reactions.bioplastic_crumbs = { elem2: ["carbon_dioxide", null, null], chance: 0.02, func: behaviors.FEEDPIXEL }; + +elements.molten_bioplastic = { + color: "#ccccac", + behavior: behaviors.LIQUID, + viscosity: 300, + category: "states", + state: "liquid", + tempLow: 150, + stateLow: "bioplastic", + temp: 160, + density: 1300, + hidden: true, +}; + + From 150ff5e1ef5b3d416c130fcbe7fe037dc26e38d0 Mon Sep 17 00:00:00 2001 From: Rain <58303213+rainingBrackets@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:52:39 +0200 Subject: [PATCH 02/10] Add files via upload --- mods/moving_pixels.js | 179 ++++++++++++++++++++++++++++++++++++++++++ mods/nitroglycerin.js | 54 +++++++++++++ mods/plastic.js | 93 ++++++++++++++++++++++ 3 files changed, 326 insertions(+) create mode 100644 mods/moving_pixels.js create mode 100644 mods/nitroglycerin.js create mode 100644 mods/plastic.js diff --git a/mods/moving_pixels.js b/mods/moving_pixels.js new file mode 100644 index 00000000..3c8d6e65 --- /dev/null +++ b/mods/moving_pixels.js @@ -0,0 +1,179 @@ + +// created by Rain :o 20/8 2024 + +elements.car = { + //color: ["#E37F6F", "#B075DF", "#4F8FEF"], + color: ["#ee70aa", "#ab33ef", "#5e6eee"], + category: "special", + density: 10000, + state: "solid", + tempHigh: 400, + stateHigh: ["steel", "molten_plastic", "glass"], + breakInto: ["steel", "plastic", "glass_shard"], + reactions: { + "water": { elem1: "rust", chance: 0.003 }, + "dirty_water": { elem1: "rust", chance: 0.003 }, + "salt_water": { elem1: "rust", chance: 0.006 }, + "grape": { elem2: "juice", chance: 0.1, color2: "#291824" }, + "tomato": { elem2: "sauce", chance: 0.1 }, + "egg": { elem2: "yolk", chance: 0.1 }, + "malware": {elem1: "explosion"}, + }, + flippableX: true, + tick: function (pixel) { + + if (pixel.carFlip === undefined) { + pixel.carFlip = 1; //it's the "pixel." that gives the variable to each car instance, very important :) + } + tryMove(pixel, pixel.x, pixel.y + 1); //try to move down (fall) + if (!isEmpty(pixel.x, pixel.y + 1)) { //if it didn't work (if the car is on the ground): + + if (isEmpty(pixel.x + pixel.carFlip, pixel.y + 1)) { + tryMove(pixel, pixel.x + pixel.carFlip, pixel.y + 1); // move diagonally down to avoid falling when going downhill + } + else if (isEmpty(pixel.x + pixel.carFlip, pixel.y)) { + tryMove(pixel, pixel.x + pixel.carFlip, pixel.y); //move to the side (which side is derived from current carFlip state) + + } else if (isEmpty(pixel.x + pixel.carFlip, pixel.y - 1)) { + tryMove(pixel, pixel.x + pixel.carFlip, pixel.y - 1); //move diagonally up the hill + + } else { //if no movement possible (like when hitting a wall): + pixel.carFlip = pixel.carFlip * -1; // Update carFlip for this car instance + } + + doDefaults(pixel); + } + }, +}; + +elements.tram = { + color: "#93E493", + conduct: 1, + category: "special", + density: 10000, + state: "solid", + tempHigh: 400, + stateHigh: ["molten_aluminum", "molten_plastic", "glass"], + breakInto: ["aluminum", "plastic", "glass_shard"], + flippableX: true, + desc: "Powered by electricity. Can hang on conductive materials for suspension railway", + reactions: { + "malware": { elem2: "electric" }, + }, + tick: function (pixel) { + + if (pixel.tramFlip === undefined) { + pixel.tramFlip = 1; //tramFlip works like carFlip for the car + } + + if (pixel.charge > 0) { //only if powered by electricity + + if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 2)) { + var diUpPixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y - 2] //establishes the variable. Must be down here because it would crash if there is no diUpPixel + if (elements[diUpPixel.element].conduct && diUpPixel.element !== "tram") { //^ is also the reason this is a seperate if statement + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y - 1); //move diagonally upwards if there is support + } + else { + pixel.tramFlip = pixel.tramFlip * -1; + } + } + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1)) { + var sidePixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y - 1] + if (elements[sidePixel.element].conduct && sidePixel.element !== "tram") { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y); //move to the side if there is support + } + else { + pixel.tramFlip = pixel.tramFlip * -1; + } + } + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y + 1) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y)) { + var diDownPixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y] + if (elements[diDownPixel.element].conduct && diDownPixel.element !== "tram") { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y + 1); //move diagonally downwards if there is support + } + else { + pixel.tramFlip = pixel.tramFlip * -1; + } + } + + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y + 1) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y)) { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y + 1); //move diagonally downwards if there isn't support + } + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1)) { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y); //move to the side if there isn't support + } + else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 2)) { + tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y - 1); //move diagonally upwards if there isn't support (uphill) + } + else { + pixel.tramFlip = pixel.tramFlip * -1; + } + + } + else { //if not powered + if (!isEmpty(pixel.x, pixel.y - 1)) { + var upPixel = pixelMap[pixel.x][pixel.y - 1] //looks at the properties of the pixel above + if (elements[upPixel.element].conduct > 0.1 && upPixel.element !== "tram") { //if the pixel above is conductive but not tram + //nothing happens ie it doesn't fall + } + else { + tryMove(pixel, pixel.x, pixel.y + 1); //it falls down + } + } + else { + tryMove(pixel, pixel.x, pixel.y + 1); //it falls down (same as above) + } + + } + doDefaults(pixel) + }, +}; +elements.bouncy_ball = { + color: "#e35693", + behavior: behaviors.WALL, + tempHigh: 250, + stateHigh: ["borax", "glue"], + category: "special", + conduct: 1, + tick: function (pixel) { + if (pixel.fallDist === undefined) { + pixel.fallDist = 0; + } + if (pixel.isFalling === undefined) { + pixel.isFalling = true; + } + + if (pixel.isFalling) { //main loop of a bouncy ball. Functions are defined below + falling() + } else { + rising() + } + if (pixel.charge > 0) { //will bounce on electricity (doesn't work on real bouncy balls :/) + pixel.fallDist = (pixel.fallDist + 1) + rising() + } + + function falling() { + + if (isEmpty(pixel.x, pixel.y + 1)) { + tryMove(pixel, pixel.x, pixel.y + 1) + pixel.fallDist += 1; //counts how many pixels the ball has fallen so far + } else { //if it touched the ground + pixel.isFalling = false; //will change the outcome of the main if statement and make ball start rising + pixel.fallDist = pixel.fallDist * 3 / 4; //dynamically decreases bounce height based on how high it is, instead of constant 1 per bounce + } + } + function rising() { + if (pixel.fallDist > 0) { + tryMove(pixel, pixel.x, pixel.y - 1) + pixel.fallDist -= 1 + } else { + pixel.isFalling = true; + pixel.fallDist -= 1 //makes the ball lose 1 pixel height each bounce, useful at the end when * 3/4 only results in fractions + } + + } + + } +}; +elements.borax.reactions.slime = { elem1: "bouncy_ball", elem2: null}; \ No newline at end of file diff --git a/mods/nitroglycerin.js b/mods/nitroglycerin.js new file mode 100644 index 00000000..97befd1a --- /dev/null +++ b/mods/nitroglycerin.js @@ -0,0 +1,54 @@ + +// created by Rain :o 20/8 2024 + +elements.glycerol = { + color: "#eeeeee", + behavior: behaviors.LIQUID, + viscosity: 1412, + category: "liquids", + state: "liquid", + density: 1261, + tempLow: 18, + tempHigh: 290, + tick: function (pixel) { + pixel.color = "rgba(250, 250, 250, 0.7)"; + }, + reactions: { + }, + burn: 5, + burnTime: 40, +}; + +elements.nitro.tempHigh = 218; //More accurate detonation temperature +elements.salt_water.tempLow = -20; //melting point depression + +elements.nitro.tick = function (pixel) { // Exothermic decomposition of nitroglycerin when above 60° + if (pixel.temp > 60) { + pixel.temp += 1; + if (Math.random() > 0.999) { + var possibleElements = ["oxygen", "nitrogen", "nitrogen", "steam", "steam", "steam", "carbon_dioxide", "carbon_dioxide", "carbon_dioxide"]; //array of possibilities for changing the nitroglycerin pixel + + var randomElement = possibleElements[Math.floor(Math.random() * possibleElements.length)]; //randomly selecting an element from the array + + changePixel(pixel, randomElement); // Change the pixel to the randomly selected element + } + } +} + +if (enabledMods.includes("mods/chem.js")) { + runAfterLoad(function () { + elements.glycerol.reactions.nitric_acid = { elem1: "nitro", chance: 0.05, temp1: 70 }; //nitric acid nitrates glycerol to make nitroglycerin + elements.nitric_acid.ignore.push("glycerol", "nitro") //added my glycerol and nitro to allow for making nitroglycerin + + elements.copper.reactions.sulfuric_acid = { elem1: "copper_sulfate", elem2: null, chance: 0.1 }; //this is how you can actually make CuSO4 + elements.sulfuric_acid.ignore.push("copper_sulfate") + + elements.grease.reactions.sodium_hydroxide = { elem1: "soap", elem2: "null", chance: 0.04, tempMin: 40 }; + elements.sodium_hydroxide.ignore.push("grease", "soap", "fat"); + + + }); +} else { + elements.glycerol.reactions.acid = { elem1: "nitro", chance: 0.05, temp1: 70 }; //if we don't have nitric acid from chem.js, "acid" is a good approximation + elements.acid.ignore.push("glycerol", "nitro") +} \ No newline at end of file diff --git a/mods/plastic.js b/mods/plastic.js new file mode 100644 index 00000000..ed90927b --- /dev/null +++ b/mods/plastic.js @@ -0,0 +1,93 @@ + +// created by Rain :o 20/8 2024 + +elements.water_bottle = { + color: "#a8d2e3", + behavior: behaviors.STURDYPOWDER, + category: "powders", + state: "solid", + density: 800, + breakInto: ["water_everywhere", "water_everywhere", "water_everywhere", "water_everywhere", "microplastic"], + tempHigh: 250, + stateHigh: ["molten_plastic", "water_everywhere", "water_everywhere"], +}; +elements.head.reactions.water_bottle = { elem2: ["plastic", "water", null, null, null], chance: 0.1 }; +elements.body.reactions.water_bottle = { elem2: ["plastic", "water", null, null, null], chance: 0.1 }; + +elements.water_everywhere = { + color: "#8882e3", + behavior: [ + "CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water", + "CR:water_everywhere%20 AND CR:water|XX%20 AND CH:water|CR:water_everywhere%20 AND CR:water", + "CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water", + ], + category: "liquids", + state: "solid", + density: 800, + hidden: true, +}; +elements.microplastic = { + color: ["#adc7c9", "#cadadb", "#6cbda8", "#62d5d4", "#b3b47b"], + behavior: [ + "XX|XX|XX", + "XX|XX|XX", + "M2%25|M1%50|M2%25", + ], + category: "powders", + state: "solid", + density: 700, + tempHigh: 250, + stateHigh: "molten_plastic", + reactions: { + "fish": { elem1: null, elem2: "meat", chance: 0.01 }, + "glue": { elem1: "bead", elem2: null, chance: 0.03 }, + }, +}; +elements.plastic.breakInto = "microplastic"; + +elements.cellulose.reactions.vinegar = { elem1: "bioplastic", elem2: null, tempMin: 40, chance: 0.1}; + +elements.bioplastic = { + color: "#eeeeaa", + behavior: behaviors.WALL, + category: "solids", + tempHigh: 180, + stateHigh: "molten_bioplastic", + breakInto: "bioplastic_crumbs", + alias: "Cellulose acetate", + desc: "It's biodegradable :)", +}; +elements.bioplastic_crumbs = { + color: ["#dfd499", "#c0e8a0", "#dfab87"], + hidden: true, + behavior: behaviors.POWDER, + category: "powders", + tempHigh: 180, + stateHigh: "molten_bioplastic", + desc: "small pieces of cellulose acetate" +}; + +elements.worm.reactions.bioplastic = { elem2: ["carbon_dioxide", null, null], chance: 0.05, func: behaviors.FEEDPIXEL }; +elements.worm.reactions.bioplastic_crumbs = { elem2: ["carbon_dioxide", null, null], chance: 0.05, func: behaviors.FEEDPIXEL }; +elements.worm.behavior = [ + "SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic%3|XX|SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic,bioplastic_crumbs%3", + "M2%10|XX|M2%10", + "SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic%3|M1|SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic,bioplastic_crumbs%3", +]; +elements.cell.reactions.bioplastic = { elem2: ["carbon_dioxide", null, null], chance: 0.02, func: behaviors.FEEDPIXEL }; +elements.cell.reactions.bioplastic_crumbs = { elem2: ["carbon_dioxide", null, null], chance: 0.02, func: behaviors.FEEDPIXEL }; + +elements.molten_bioplastic = { + color: "#ccccac", + behavior: behaviors.LIQUID, + viscosity: 300, + category: "states", + state: "liquid", + tempLow: 150, + stateLow: "bioplastic", + temp: 160, + density: 1300, + hidden: true, +}; + + From 7df6ea9f1857ee1f335771b4a08ed05c5dbfa27e Mon Sep 17 00:00:00 2001 From: Rain <58303213+rainingBrackets@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:53:56 +0200 Subject: [PATCH 03/10] Delete nitroglycerin.js --- nitroglycerin.js | 54 ------------------------------------------------ 1 file changed, 54 deletions(-) delete mode 100644 nitroglycerin.js diff --git a/nitroglycerin.js b/nitroglycerin.js deleted file mode 100644 index 97befd1a..00000000 --- a/nitroglycerin.js +++ /dev/null @@ -1,54 +0,0 @@ - -// created by Rain :o 20/8 2024 - -elements.glycerol = { - color: "#eeeeee", - behavior: behaviors.LIQUID, - viscosity: 1412, - category: "liquids", - state: "liquid", - density: 1261, - tempLow: 18, - tempHigh: 290, - tick: function (pixel) { - pixel.color = "rgba(250, 250, 250, 0.7)"; - }, - reactions: { - }, - burn: 5, - burnTime: 40, -}; - -elements.nitro.tempHigh = 218; //More accurate detonation temperature -elements.salt_water.tempLow = -20; //melting point depression - -elements.nitro.tick = function (pixel) { // Exothermic decomposition of nitroglycerin when above 60° - if (pixel.temp > 60) { - pixel.temp += 1; - if (Math.random() > 0.999) { - var possibleElements = ["oxygen", "nitrogen", "nitrogen", "steam", "steam", "steam", "carbon_dioxide", "carbon_dioxide", "carbon_dioxide"]; //array of possibilities for changing the nitroglycerin pixel - - var randomElement = possibleElements[Math.floor(Math.random() * possibleElements.length)]; //randomly selecting an element from the array - - changePixel(pixel, randomElement); // Change the pixel to the randomly selected element - } - } -} - -if (enabledMods.includes("mods/chem.js")) { - runAfterLoad(function () { - elements.glycerol.reactions.nitric_acid = { elem1: "nitro", chance: 0.05, temp1: 70 }; //nitric acid nitrates glycerol to make nitroglycerin - elements.nitric_acid.ignore.push("glycerol", "nitro") //added my glycerol and nitro to allow for making nitroglycerin - - elements.copper.reactions.sulfuric_acid = { elem1: "copper_sulfate", elem2: null, chance: 0.1 }; //this is how you can actually make CuSO4 - elements.sulfuric_acid.ignore.push("copper_sulfate") - - elements.grease.reactions.sodium_hydroxide = { elem1: "soap", elem2: "null", chance: 0.04, tempMin: 40 }; - elements.sodium_hydroxide.ignore.push("grease", "soap", "fat"); - - - }); -} else { - elements.glycerol.reactions.acid = { elem1: "nitro", chance: 0.05, temp1: 70 }; //if we don't have nitric acid from chem.js, "acid" is a good approximation - elements.acid.ignore.push("glycerol", "nitro") -} \ No newline at end of file From cf5bee5b403ffa79c2577709a0fa193bc0c157fa Mon Sep 17 00:00:00 2001 From: Rain <58303213+rainingBrackets@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:54:56 +0200 Subject: [PATCH 04/10] Delete moving_pixels.js --- moving_pixels.js | 179 ----------------------------------------------- 1 file changed, 179 deletions(-) delete mode 100644 moving_pixels.js diff --git a/moving_pixels.js b/moving_pixels.js deleted file mode 100644 index 3c8d6e65..00000000 --- a/moving_pixels.js +++ /dev/null @@ -1,179 +0,0 @@ - -// created by Rain :o 20/8 2024 - -elements.car = { - //color: ["#E37F6F", "#B075DF", "#4F8FEF"], - color: ["#ee70aa", "#ab33ef", "#5e6eee"], - category: "special", - density: 10000, - state: "solid", - tempHigh: 400, - stateHigh: ["steel", "molten_plastic", "glass"], - breakInto: ["steel", "plastic", "glass_shard"], - reactions: { - "water": { elem1: "rust", chance: 0.003 }, - "dirty_water": { elem1: "rust", chance: 0.003 }, - "salt_water": { elem1: "rust", chance: 0.006 }, - "grape": { elem2: "juice", chance: 0.1, color2: "#291824" }, - "tomato": { elem2: "sauce", chance: 0.1 }, - "egg": { elem2: "yolk", chance: 0.1 }, - "malware": {elem1: "explosion"}, - }, - flippableX: true, - tick: function (pixel) { - - if (pixel.carFlip === undefined) { - pixel.carFlip = 1; //it's the "pixel." that gives the variable to each car instance, very important :) - } - tryMove(pixel, pixel.x, pixel.y + 1); //try to move down (fall) - if (!isEmpty(pixel.x, pixel.y + 1)) { //if it didn't work (if the car is on the ground): - - if (isEmpty(pixel.x + pixel.carFlip, pixel.y + 1)) { - tryMove(pixel, pixel.x + pixel.carFlip, pixel.y + 1); // move diagonally down to avoid falling when going downhill - } - else if (isEmpty(pixel.x + pixel.carFlip, pixel.y)) { - tryMove(pixel, pixel.x + pixel.carFlip, pixel.y); //move to the side (which side is derived from current carFlip state) - - } else if (isEmpty(pixel.x + pixel.carFlip, pixel.y - 1)) { - tryMove(pixel, pixel.x + pixel.carFlip, pixel.y - 1); //move diagonally up the hill - - } else { //if no movement possible (like when hitting a wall): - pixel.carFlip = pixel.carFlip * -1; // Update carFlip for this car instance - } - - doDefaults(pixel); - } - }, -}; - -elements.tram = { - color: "#93E493", - conduct: 1, - category: "special", - density: 10000, - state: "solid", - tempHigh: 400, - stateHigh: ["molten_aluminum", "molten_plastic", "glass"], - breakInto: ["aluminum", "plastic", "glass_shard"], - flippableX: true, - desc: "Powered by electricity. Can hang on conductive materials for suspension railway", - reactions: { - "malware": { elem2: "electric" }, - }, - tick: function (pixel) { - - if (pixel.tramFlip === undefined) { - pixel.tramFlip = 1; //tramFlip works like carFlip for the car - } - - if (pixel.charge > 0) { //only if powered by electricity - - if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 2)) { - var diUpPixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y - 2] //establishes the variable. Must be down here because it would crash if there is no diUpPixel - if (elements[diUpPixel.element].conduct && diUpPixel.element !== "tram") { //^ is also the reason this is a seperate if statement - tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y - 1); //move diagonally upwards if there is support - } - else { - pixel.tramFlip = pixel.tramFlip * -1; - } - } - else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1)) { - var sidePixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y - 1] - if (elements[sidePixel.element].conduct && sidePixel.element !== "tram") { - tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y); //move to the side if there is support - } - else { - pixel.tramFlip = pixel.tramFlip * -1; - } - } - else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y + 1) && !isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y)) { - var diDownPixel = pixelMap[pixel.x + 1 * pixel.tramFlip][pixel.y] - if (elements[diDownPixel.element].conduct && diDownPixel.element !== "tram") { - tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y + 1); //move diagonally downwards if there is support - } - else { - pixel.tramFlip = pixel.tramFlip * -1; - } - } - - else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y + 1) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y)) { - tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y + 1); //move diagonally downwards if there isn't support - } - else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1)) { - tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y); //move to the side if there isn't support - } - else if (isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 1) && isEmpty(pixel.x + 1 * pixel.tramFlip, pixel.y - 2)) { - tryMove(pixel, pixel.x + 1 * pixel.tramFlip, pixel.y - 1); //move diagonally upwards if there isn't support (uphill) - } - else { - pixel.tramFlip = pixel.tramFlip * -1; - } - - } - else { //if not powered - if (!isEmpty(pixel.x, pixel.y - 1)) { - var upPixel = pixelMap[pixel.x][pixel.y - 1] //looks at the properties of the pixel above - if (elements[upPixel.element].conduct > 0.1 && upPixel.element !== "tram") { //if the pixel above is conductive but not tram - //nothing happens ie it doesn't fall - } - else { - tryMove(pixel, pixel.x, pixel.y + 1); //it falls down - } - } - else { - tryMove(pixel, pixel.x, pixel.y + 1); //it falls down (same as above) - } - - } - doDefaults(pixel) - }, -}; -elements.bouncy_ball = { - color: "#e35693", - behavior: behaviors.WALL, - tempHigh: 250, - stateHigh: ["borax", "glue"], - category: "special", - conduct: 1, - tick: function (pixel) { - if (pixel.fallDist === undefined) { - pixel.fallDist = 0; - } - if (pixel.isFalling === undefined) { - pixel.isFalling = true; - } - - if (pixel.isFalling) { //main loop of a bouncy ball. Functions are defined below - falling() - } else { - rising() - } - if (pixel.charge > 0) { //will bounce on electricity (doesn't work on real bouncy balls :/) - pixel.fallDist = (pixel.fallDist + 1) - rising() - } - - function falling() { - - if (isEmpty(pixel.x, pixel.y + 1)) { - tryMove(pixel, pixel.x, pixel.y + 1) - pixel.fallDist += 1; //counts how many pixels the ball has fallen so far - } else { //if it touched the ground - pixel.isFalling = false; //will change the outcome of the main if statement and make ball start rising - pixel.fallDist = pixel.fallDist * 3 / 4; //dynamically decreases bounce height based on how high it is, instead of constant 1 per bounce - } - } - function rising() { - if (pixel.fallDist > 0) { - tryMove(pixel, pixel.x, pixel.y - 1) - pixel.fallDist -= 1 - } else { - pixel.isFalling = true; - pixel.fallDist -= 1 //makes the ball lose 1 pixel height each bounce, useful at the end when * 3/4 only results in fractions - } - - } - - } -}; -elements.borax.reactions.slime = { elem1: "bouncy_ball", elem2: null}; \ No newline at end of file From 1ecf777b11e364b35d8e54013fe62fa62ae2753a Mon Sep 17 00:00:00 2001 From: Rain <58303213+rainingBrackets@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:55:23 +0200 Subject: [PATCH 05/10] Delete plastic.js --- plastic.js | 93 ------------------------------------------------------ 1 file changed, 93 deletions(-) delete mode 100644 plastic.js diff --git a/plastic.js b/plastic.js deleted file mode 100644 index ed90927b..00000000 --- a/plastic.js +++ /dev/null @@ -1,93 +0,0 @@ - -// created by Rain :o 20/8 2024 - -elements.water_bottle = { - color: "#a8d2e3", - behavior: behaviors.STURDYPOWDER, - category: "powders", - state: "solid", - density: 800, - breakInto: ["water_everywhere", "water_everywhere", "water_everywhere", "water_everywhere", "microplastic"], - tempHigh: 250, - stateHigh: ["molten_plastic", "water_everywhere", "water_everywhere"], -}; -elements.head.reactions.water_bottle = { elem2: ["plastic", "water", null, null, null], chance: 0.1 }; -elements.body.reactions.water_bottle = { elem2: ["plastic", "water", null, null, null], chance: 0.1 }; - -elements.water_everywhere = { - color: "#8882e3", - behavior: [ - "CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water", - "CR:water_everywhere%20 AND CR:water|XX%20 AND CH:water|CR:water_everywhere%20 AND CR:water", - "CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water|CR:water_everywhere%20 AND CR:water", - ], - category: "liquids", - state: "solid", - density: 800, - hidden: true, -}; -elements.microplastic = { - color: ["#adc7c9", "#cadadb", "#6cbda8", "#62d5d4", "#b3b47b"], - behavior: [ - "XX|XX|XX", - "XX|XX|XX", - "M2%25|M1%50|M2%25", - ], - category: "powders", - state: "solid", - density: 700, - tempHigh: 250, - stateHigh: "molten_plastic", - reactions: { - "fish": { elem1: null, elem2: "meat", chance: 0.01 }, - "glue": { elem1: "bead", elem2: null, chance: 0.03 }, - }, -}; -elements.plastic.breakInto = "microplastic"; - -elements.cellulose.reactions.vinegar = { elem1: "bioplastic", elem2: null, tempMin: 40, chance: 0.1}; - -elements.bioplastic = { - color: "#eeeeaa", - behavior: behaviors.WALL, - category: "solids", - tempHigh: 180, - stateHigh: "molten_bioplastic", - breakInto: "bioplastic_crumbs", - alias: "Cellulose acetate", - desc: "It's biodegradable :)", -}; -elements.bioplastic_crumbs = { - color: ["#dfd499", "#c0e8a0", "#dfab87"], - hidden: true, - behavior: behaviors.POWDER, - category: "powders", - tempHigh: 180, - stateHigh: "molten_bioplastic", - desc: "small pieces of cellulose acetate" -}; - -elements.worm.reactions.bioplastic = { elem2: ["carbon_dioxide", null, null], chance: 0.05, func: behaviors.FEEDPIXEL }; -elements.worm.reactions.bioplastic_crumbs = { elem2: ["carbon_dioxide", null, null], chance: 0.05, func: behaviors.FEEDPIXEL }; -elements.worm.behavior = [ - "SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic%3|XX|SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic,bioplastic_crumbs%3", - "M2%10|XX|M2%10", - "SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic%3|M1|SW:dirt,sand,gravel,ash,mycelium,mud,wet_sand,clay_soil,water,salt_water,dirty_water,primordial_soup,blood,infection,color_sand,bioplastic,bioplastic_crumbs%3", -]; -elements.cell.reactions.bioplastic = { elem2: ["carbon_dioxide", null, null], chance: 0.02, func: behaviors.FEEDPIXEL }; -elements.cell.reactions.bioplastic_crumbs = { elem2: ["carbon_dioxide", null, null], chance: 0.02, func: behaviors.FEEDPIXEL }; - -elements.molten_bioplastic = { - color: "#ccccac", - behavior: behaviors.LIQUID, - viscosity: 300, - category: "states", - state: "liquid", - tempLow: 150, - stateLow: "bioplastic", - temp: 160, - density: 1300, - hidden: true, -}; - - From a558c844229dbfebb8da1f119c0cb2c54fd78dc3 Mon Sep 17 00:00:00 2001 From: redbirdly <155550833+redbirdly@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:15:07 +0800 Subject: [PATCH 06/10] Add files via upload --- mods/circuitcore_displays.js | 146 +++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 mods/circuitcore_displays.js diff --git a/mods/circuitcore_displays.js b/mods/circuitcore_displays.js new file mode 100644 index 00000000..252ba699 --- /dev/null +++ b/mods/circuitcore_displays.js @@ -0,0 +1,146 @@ +if (!enabledMods.includes("mods/circuitcore.js")) { enabledMods.unshift("mods/circuitcore.js"); localStorage.setItem("enabledMods", JSON.stringify(enabledMods)); window.location.reload() }; +var lightmapEnabled = enabledMods.includes("mods/lightmap.js") || enabledMods.includes("mods/fast_lightmap.js"); + +function general_display(w, h, colorMode) { // colorMode: 0 for monochrome, 1 for 3-bit, 2 for 4-bit + return function(pixel) { + var pins = []; + + // X input (expands right) + for (var i = 0; i < Math.ceil(Math.log2(w)); i++) { + pins.push([-1, (i * 2) + 1, true]); + } + + // Y input (expands downward) + for (var i = 0; i < Math.ceil(Math.log2(h)); i++) { + pins.push([(i * 2) + 1, -1, true]); + } + + if (colorMode === 1) { // 3-bit color + pins.push([-1, 11, true]); // Red + pins.push([-1, 13, true]); // Green + pins.push([-1, 15, true]); // Blue + } else if (colorMode === 2) { // 4-bit color + for (var i = 0; i < 4; i++) { + pins.push([-1, 11 + (i * 2), true]); // 4-bit color input + } + } else { // Monochrome + pins.push([w - 4, -1, true]); + } + + // Reset pin + pins.push([w - 2, -1, true]); + + // Clock input + pins.push([w, -1, true]); + + initializeCircuit(pixel, pins, w + 2, h + 2, false, pixel.circuitRotation, addDisplayCallback); + + var X = []; + for (var i = 0; i < Math.ceil(Math.log2(w)); i++) { + X.push(checkPin(pixel, pins, i)); + } + + var Y = []; + for (var i = 0; i < Math.ceil(Math.log2(h)); i++) { + Y.push(checkPin(pixel, pins, Math.ceil(Math.log2(w)) + i)); + } + + var color; + if (colorMode === 1) { + var red = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h))); + var green = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + 1); + var blue = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + 2); + color = `rgb(${red ? 255 : 0}, ${green ? 255 : 0}, ${blue ? 255 : 0})`; + } else if (colorMode === 2) { + var colorIndex = 0; + for (var i = 0; i < 4; i++) { + colorIndex += checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + i) ? Math.pow(2, i) : 0; + } + color = colorPalette_4bit[colorIndex]; + } else { + color = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h))) ? "rgb(16, 230, 120)" : "rgb(16, 24, 32)"; + } + + var reset = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + (colorMode === 1 ? 3 : (colorMode === 2 ? 4 : 1))); + var clock = checkPin(pixel, pins, Math.ceil(Math.log2(w)) + Math.ceil(Math.log2(h)) + (colorMode === 1 ? 4 : (colorMode === 2 ? 5 : 2))); + + var x_pos = 0; + for (var i = 0; i < X.length; i++) { + x_pos += X[i] ? Math.pow(2, (X.length - 1) - i) : 0; + } + + var y_pos = 0; + for (var i = 0; i < Y.length; i++) { + y_pos += Y[i] ? Math.pow(2, (Y.length - 1) - i) : 0; + } + + if (x_pos >= w || y_pos >= h) return; + + var px = pixel.x + 1 + x_pos; + var py = pixel.y + 1 + y_pos; + + if (reset) { + for (var y = 1; y <= h; y++) { + for (var x = 1; x <= w; x++) { + var reset_px = pixel.x + x; + var reset_py = pixel.y + y; + if (pixelMap[reset_px] && pixelMap[reset_px][reset_py] && pixelMap[reset_px][reset_py].element == "displayPixel") { + pixelMap[reset_px][reset_py].color = "rgb(16, 24, 32)"; + } + } + } + return; + } + + if (clock) { + if (pixelMap[px] && pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") { + pixelMap[px][py].color = color; + } + } + }; +} + +elements.gridDisplay = { + color: "#33FF66", + category: "logic", + maxSize: 1, + onSelect: function() { + // Prompt the user for display width, height, and color depth + var width = parseInt(prompt("Enter the display width (e.g., 16, 32, 64):", "16")); + var height = parseInt(prompt("Enter the display height (e.g., 16, 32, 64):", "16")); + var colorDepth = parseInt(prompt("Enter the color depth (1 for monochrome, 3 for 3-bit, 4 for 4-bit):", "4")); + + // Set these values for the pixel + elements.gridDisplay.displayWidth = width; + elements.gridDisplay.displayHeight = height; + elements.gridDisplay.displayColorDepth = colorDepth; + }, + cc_stableTick: function(pixel) { + // Get the display properties + var width = elements.gridDisplay.displayWidth || 16; + var height = elements.gridDisplay.displayHeight || 16; + var colorDepth = elements.gridDisplay.displayColorDepth || 4; + + // Call general_display with the appropriate parameters + var displayFunction = general_display(width, height, colorDepth === 1 ? 0 : (colorDepth === 3 ? 1 : 2)); + displayFunction(pixel); + } +}; + +elements.displayPixel = { + color: "#000000", + category: "logic", + state: "solid", + behavior: behaviors.WALL, + tick: function(pixel) { + if (pixel.start == pixelTicks) { + pixel.color = "rgb(16, 24, 32)"; + } + +// if (lightmapEnabled && pixel.color) { +// var x = Math.floor(pixel.x / lightmapScale); +// var y = Math.floor(pixel.y / lightmapScale); +// lightmap[y][x] = { color: scaleList(rgbToArray(pixel.color), 2) }; +// } + } +}; From e99e08ae710cfa5e11e300561ed05e749945b4f7 Mon Sep 17 00:00:00 2001 From: redbirdly <155550833+redbirdly@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:15:43 +0800 Subject: [PATCH 07/10] Update circuitcore.js --- mods/circuitcore.js | 337 ++++++++++++++++++++++++-------------------- 1 file changed, 186 insertions(+), 151 deletions(-) diff --git a/mods/circuitcore.js b/mods/circuitcore.js index c214cc5c..39c4b35b 100644 --- a/mods/circuitcore.js +++ b/mods/circuitcore.js @@ -11,9 +11,11 @@ cc_settingsTab.registerSettings("OverHeating", cc_setting1); //cc_settingsTab.registerSettings("Setting 2", cc_setting2); settingsManager.registerTab(cc_settingsTab); -var dataVisualizationPalette16 = [ - "#000000", "#ff0000", "#ff7700", "#ffff00", "#00ff00", "#00ffff", "#0000ff", "#ff00ff", - "#777777", "#770000", "#773300", "#777700", "#007700", "#007777", "#000077", "#770077", +var colorPalette_4bit = [ + "#101820", "#37175F", "#5F1717", "#6F175F", + "#005F00", "#1563BF", "#7F401A", "#525252", + "#8F8F8F", "#EE8822", "#FF3027", "#FF47FF", + "#58E618", "#27FFDF", "#FFFF27", "#FFFFFF" ]; function hueLerp(value) { @@ -217,6 +219,61 @@ function setPin(pixel, pins, index, value, rotation=pixel.circuitRotation) { } // Circuits +elements.four_bit_selector_circuit = { + cc_stableTick: function(pixel) { + var pins = [ + // First 4-bit input (A) + [-1, -2, true], // A0 + [-3, -2, true], // A1 + [-5, -2, true], // A2 + [-7, -2, true], // A3 + + // Second 4-bit input (B) + [7, -2, true], // B0 + [5, -2, true], // B1 + [3, -2, true], // B2 + [1, -2, true], // B3 + + // Selection pin (Sel) + [9, 0, true], // Selection (Sel) + + // Output (O) + [-3, 2, false], // O0 (centered) + [-1, 2, false], // O1 (centered) + [1, 2, false], // O2 (centered) + [3, 2, false], // O3 (centered) + ]; + + initializeCircuit(pixel, pins, 17, 3); + + // Read inputs + var A = [ + checkPin(pixel, pins, 0), + checkPin(pixel, pins, 1), + checkPin(pixel, pins, 2), + checkPin(pixel, pins, 3) + ]; + + var B = [ + checkPin(pixel, pins, 4), + checkPin(pixel, pins, 5), + checkPin(pixel, pins, 6), + checkPin(pixel, pins, 7) + ]; + + var Sel = checkPin(pixel, pins, 8); // Selection pin + + // Select between A and B based on Sel + var output = Sel ? B : A; + + // Output the selected 4-bit value + setPin(pixel, pins, 9, output[0]); // O0 + setPin(pixel, pins, 10, output[1]); // O1 + setPin(pixel, pins, 11, output[2]); // O2 + setPin(pixel, pins, 12, output[3]); // O3 + } +}; + elements.four_bit_enabler_circuit = { centered: true, cc_stableTick: function(pixel) { @@ -442,9 +499,9 @@ elements.temperature_sensor = { var cellData = pixel.romData[cellAddress]; if (!(0 <= px && px < width && 0 <= py && py < height)) {continue;} - if (pixelMap[px][py] && pixelMap[px][py].element == "art") { + if (pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") { // if (address == cellAddress) {} - pixelMap[px][py].color = dataVisualizationPalette16[binaryArrayToNumber(cellData)]; + pixelMap[px][py].color = colorPalette_4bit[binaryArrayToNumber(cellData)]; } } } @@ -1277,6 +1334,70 @@ elements.four_bit_adder_circuit = { } }; +elements.four_bit_subtractor_circuit = { + cc_stableTick: function(pixel) { + var pins = [ + // First 4-bit number (A) + [-1, -2, true], // A3 + [-3, -2, true], // A2 + [-5, -2, true], // A1 + [-7, -2, true], // A0 + + // Second 4-bit number (B) + [7, -2, true], // B3 + [5, -2, true], // B2 + [3, -2, true], // B1 + [1, -2, true], // B0 + + // Borrow-in (B_in) + [9, 0, true], // Borrow-in (B_in) + + // Output difference (D) + [-1, 2, false], // D3 + [-3, 2, false], // D2 + [-5, 2, false], // D1 + [-7, 2, false], // D0 + [1, 2, false], // Borrow Out (B4) + ]; + + initializeCircuit(pixel, pins, 17, 3); + + // Read inputs + var A = [ + checkPin(pixel, pins, 0), + checkPin(pixel, pins, 1), + checkPin(pixel, pins, 2), + checkPin(pixel, pins, 3) + ]; + + var B = [ + checkPin(pixel, pins, 4), + checkPin(pixel, pins, 5), + checkPin(pixel, pins, 6), + checkPin(pixel, pins, 7) + ]; + + var B_in = checkPin(pixel, pins, 8); // Borrow-in + + // Calculate the difference and borrow + var difference = []; + var borrow = B_in; + + for (var i = 0; i < 4; i++) { + var bitDifference = A[i] - B[i] - borrow; + difference[i] = (bitDifference + 2) % 2; // Current bit difference + borrow = bitDifference < 0 ? 1 : 0; // Borrow for next bit + } + + // Output the difference + setPin(pixel, pins, 9, difference[0]); // D0 + setPin(pixel, pins, 10, difference[1]); // D1 + setPin(pixel, pins, 11, difference[2]); // D2 + setPin(pixel, pins, 12, difference[3]); // D3 + setPin(pixel, pins, 13, borrow); // Borrow Out (B4) + } +}; + function general_clock(speed, s2) { return function(pixel){ for (var i = 0; i < adjacentCoords.length; i++) { @@ -1343,6 +1464,7 @@ elements.custom_RGB_led = { ]; var color = { color: cc_scaleList([(l[0] * 2) + l[1], (l[2] * 2) + l[3], (l[4] * 2) + l[5]], (255 / 3) * 10) }; + if (color.color.some(value => isNaN(value))) {return;} if (lightmapEnabled && color.color[0] && color.color[1], color.color[2]) { lightmap[Math.floor(pixel.y / lightmapScale)][Math.floor(pixel.x / lightmapScale)] = color; @@ -1372,7 +1494,7 @@ var addDisplayCallback = function(pixel, pins, w, h) { if (!(0 <= px && px < width && 0 <= py && py < height)) {continue;} deletePixel(px, py); - createPixel("art", px, py); + createPixel("displayPixel", px, py); pixelMap[px][py].color = "rgb(16, 24, 32)"; } } @@ -1408,7 +1530,7 @@ elements.simple_seven_segment_display = { var px = pixel.x + x; var py = pixel.y + y; - if (pixelMap[px][py] && pixelMap[px][py].element == "art") { + if (pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") { if (hexGrid[y - 2][x - 1]) { pixelMap[px][py].color = "rgb(16, 230, 120)"; } else { @@ -1460,7 +1582,7 @@ elements.simple_double_seven_segment_display = { var px = pixel.x + x; var py = pixel.y + y; - if (pixelMap[px][py] && pixelMap[px][py].element == "art") { + if (pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") { if (hexGrid[y - 2][x - 1]) { pixelMap[px][py].color = "rgb(16, 230, 120)"; } else { @@ -1476,7 +1598,7 @@ elements.simple_double_seven_segment_display = { var px = pixel.x + x; var py = pixel.y + y; - if (pixelMap[px][py] && pixelMap[px][py].element == "art") { + if (pixelMap[px][py] && pixelMap[px][py].element == "displayPixel") { if (hexGrid2[y - 2][x - 5]) { pixelMap[px][py].color = "rgb(16, 230, 120)"; } else { @@ -1488,117 +1610,6 @@ elements.simple_double_seven_segment_display = { } }; -function general_display(w, h) { - return function(pixel) { - var pins = []; - - // X input (X0-Xn) - for (var i = 0; i < Math.ceil(Math.log2(w)); i++) { - pins.push([-1, (Math.ceil(Math.log2(w)) - i) * 2 - 1, true]); - } - - // Y input (Y0-Yn) - for (var i = 0; i < Math.ceil(Math.log2(h)); i++) { - pins.push([(Math.ceil(Math.log2(h)) - i) * 2 - 1, -1, true]); - } - - // Color input - pins.push([11, -1, true]); - - // Reset pin - pins.push([13, -1, true]); - - // Clock input - pins.push([15, -1, true]); - - // Initialize the circuit with the necessary pins - initializeCircuit(pixel, pins, w + 2, h + 2, false, pixel.circuitRotation, addDisplayCallback); - - // Read inputs - var X = []; - for (var i = 0; i < Math.ceil(Math.log2(w)); i++) { - X.push(checkPin(pixel, pins, i)); - } - - var Y = []; - for (var i = 0; i < Math.ceil(Math.log2(h)); i++) { - Y.push(checkPin(pixel, pins, Math.ceil(Math.log2(w)) + i)); - } - - var color = checkPin(pixel, pins, pins.length - 3); - var reset = checkPin(pixel, pins, pins.length - 2); - var clock = checkPin(pixel, pins, pins.length - 1); - - // Decode X and Y inputs to determine the pixel position - var x_pos = 0; - for (var i = 0; i < X.length; i++) { - x_pos += (X[i] ? 1 : 0) << i; - } - - var y_pos = 0; - for (var i = 0; i < Y.length; i++) { - y_pos += (Y[i] ? 1 : 0) << i; - } - - // Display dimension check - if (x_pos >= w || y_pos >= h) return; - - var px = pixel.x + 1 + x_pos; // Adjust for the display position - var py = pixel.y + 1 + y_pos; - - // Handle reset functionality - if (reset) { - for (var y = 1; y <= h; y++) { - for (var x = 1; x <= w; x++) { - var reset_px = pixel.x + x; - var reset_py = pixel.y + y; - if (pixelMap[reset_px] && pixelMap[reset_px][reset_py] && pixelMap[reset_px][reset_py].element == "art") { - pixelMap[reset_px][reset_py].color = "rgb(16, 230, 120)"; - } - } - } - return; - } - - // Update display on clock pulse - if (clock) { - if (pixelMap[px] && pixelMap[px][py] && pixelMap[px][py].element == "art") { - // Set the pixel color - pixelMap[px][py].color = color ? "rgb(16, 230, 120)" : "rgb(16, 230, 120)"; - } - } - }; -} - -elements.basic_mono_display_8x8 = { - cc_stableTick: general_display(8, 8), -}; - -elements.basic_mono_display_16x8 = { - cc_stableTick: general_display(16, 8), -}; - -elements.basic_mono_display_16x16 = { - cc_stableTick: general_display(16, 16), -}; - -elements.basic_mono_display_32x16 = { - cc_stableTick: general_display(32, 16), -}; - -elements.basic_mono_display_32x32 = { - cc_stableTick: general_display(32, 32), -}; - -elements.basic_mono_display_64x32 = { - cc_stableTick: general_display(64, 32), -}; - -elements.basic_mono_display_64x64 = { - cc_stableTick: general_display(64, 64), -}; - - function malfunction_chip(pixel) { var emptySpaces = []; @@ -1629,18 +1640,23 @@ function malfunction_chip(pixel) { } } -//elements.display = { -// color: "#444444", -// category: "logic", -// state: "solid", -// behavior: behaviors.WALL, -// hoverStat: function(pixel) { -// return `Circuit: ${pixel.corePosition}`; -// }, -// cc_stableTick: function(pixel) { -// -// } -//}; +elements.displayPixel = { + color: "#000000", + category: "logic", + state: "solid", + behavior: behaviors.WALL, + tick: function(pixel) { + if (pixel.start == pixelTicks) { + pixel.color = "rgb(16, 24, 32)"; + } + + if (lightmapEnabled && pixel.color) { + var x = Math.floor(pixel.x / lightmapScale); + var y = Math.floor(pixel.y / lightmapScale); + lightmap[y][x] = { color: scaleList(rgbToArray(pixel.color), 0.2) }; + } + } +}; elements.circuit_material = { color: "#444444", @@ -1777,13 +1793,24 @@ elements.logic_corrupter_machine = { }, } -elements.circuitCoreTutorial = { - color: "#33FF66", - category: "logic", - onSelect: function() { - window.open("https://redbirdly.github.io/circuitcore_tutorial.html"); - }, -} +// Create a new anchor element +var tutorialLink = document.createElement("a"); + +// Set the link's text content +tutorialLink.textContent = "CircuitCore Tutorial"; + +// Set the link's href attribute to point to the tutorial +tutorialLink.href = "https://redbirdly.github.io/circuitcore_tutorial.html"; + +// Set the link to open in a new tab +tutorialLink.target = "_blank"; + +// Style the link (optional) +tutorialLink.style.color = "#33FF66"; // Set the color of the link +tutorialLink.style.fontSize = "14px"; // Set the font size + +// Append the link to the body of the webpage +document.body.appendChild(tutorialLink); // cc_ is circuit core prefix const cc_BROWN = "#773317"; @@ -1800,6 +1827,7 @@ const cc_WHITE = "#DDDDDD"; var circuits = [ // Misc and I/O: brown + { circuit: elements.four_bit_selector_circuit, color: cc_BROWN, size: [17, 3, true] }, { circuit: elements.four_bit_enabler_circuit, color: cc_BROWN, size: [9, 3, true] }, { circuit: elements.randomizer, color: cc_BROWN }, { circuit: elements.four_bit_randomizer_circuit, color: cc_BROWN, size: [9, 3, true] }, @@ -1841,6 +1869,7 @@ var circuits = [ { circuit: elements.four_bit_D_flip_flop_circuit, color: cc_LIGHT_BLUE, size: [9, 3, true] }, // Addition/subtraction arithmetic: blue { circuit: elements.four_bit_adder_circuit, color: cc_BLUE, size: [17, 3, true] }, + { circuit: elements.four_bit_subtractor_circuit, color: cc_BLUE, size: [17, 3, true] }, { circuit: elements.four_bit_incrementer_circuit, color: cc_BLUE, size: [9, 3, true] }, // Complex circuits: lavender // Clocks: pink @@ -1852,13 +1881,6 @@ var circuits = [ { circuit: elements.simple_seven_segment_display, color: cc_WHITE, size: [5, 9, false] }, { circuit: elements.simple_double_seven_segment_display, color: cc_WHITE, size: [9, 9, false] }, { circuit: elements.custom_RGB_led, color: cc_WHITE, size: [3, 3, true] }, - { circuit: elements.basic_mono_display_8x8, color: cc_WHITE, size: [10, 10, false] }, - { circuit: elements.basic_mono_display_16x8, color: cc_WHITE, size: [18, 10, false] }, - { circuit: elements.basic_mono_display_16x16, color: cc_WHITE, size: [18, 18, false] }, - { circuit: elements.basic_mono_display_32x16, color: cc_WHITE, size: [34, 18, false] }, - { circuit: elements.basic_mono_display_32x32, color: cc_WHITE, size: [34, 34, false] }, - { circuit: elements.basic_mono_display_64x32, color: cc_WHITE, size: [66, 34, false] }, - { circuit: elements.basic_mono_display_64x64, color: cc_WHITE, size: [66, 66, false] }, ]; circuits.forEach(circuitInfo => { @@ -1947,15 +1969,28 @@ function drawCircuitExtras() { } function runLogicTick() { - for (var i = 0;i < currentPixels.length;i++) { - var pixel = currentPixels[i]; - if (elements[pixel.element].category == "logic") { - if (elements[pixel.element].cc_stableTick) { - elements[pixel.element].cc_stableTick(pixel); + if (paused) {return;} + for (var j = 0;j < 1;j++) { + for (var i = 0;i < currentPixels.length;i++) { + var pixel = currentPixels[i]; + if (elements[pixel.element].category == "logic") { + if (elements[pixel.element].cc_stableTick) { + elements[pixel.element].cc_stableTick(pixel); + } } } } } +function stabilizeLogicGates() { + var logicgatesElements = ["output","logic_wire","not_gate","and_gate","xor_gate","or_gate","nand_gate","nor_gate","nxor_gate","E2L_lever","E2L_button","L2E_constant","logic_transmitter","logic_receiver","logic_shock","logic_unshock"] + + for (var i = 0;i < logicgatesElements.length;i++) { + elements[logicgatesElements[i]].cc_stableTick = elements[logicgatesElements[i]].tick; + elements[logicgatesElements[i]].tick = null; + } +} + renderPostPixel(drawCircuitExtras); runEveryTick(runLogicTick); +runAfterLoad(stabilizeLogicGates); From 9d369de6e2cb080b0b6314136ab6041f6a663865 Mon Sep 17 00:00:00 2001 From: JustAGenericUsername <92590792+JustAGenericUsername@users.noreply.github.com> Date: Sat, 24 Aug 2024 15:14:04 -0400 Subject: [PATCH 08/10] ye --- mods/minecraft.js | 162 +++++++++++++++++++++++++++++++++++++++++- mods/nousersthings.js | 162 ++++++++++++++++++++++++++++++++++-------- mods/ores.js | 8 +-- 3 files changed, 299 insertions(+), 33 deletions(-) diff --git a/mods/minecraft.js b/mods/minecraft.js index 82c4f9c0..42d84d9e 100644 --- a/mods/minecraft.js +++ b/mods/minecraft.js @@ -591,7 +591,7 @@ let channelVar = "0" elements.sculk_wifi_transmitter = { color: "#142c47", category: "minecraft", - behaviors: behaviors.WALL, + behavior: behaviors.WALL, tempHigh: 250, stateHigh: "dirt", hoverStat: function(pixel){ @@ -643,4 +643,164 @@ elements.sculk_wifi_receiver = { tick: function(pixel){ if (!pixel.channel){pixel.channel = channelVar} } +} +drawRectangle = function(ctx, color, x, y, width, height, xoffset, yoffset){ + ctx.fillStyle = color; + ctx.fillRect(canvasCoord(x+xoffset), canvasCoord(y+yoffset), pixelSize*width, pixelSize*height) +} +autoFillDrawRectangle = function(ctx, pixel, width, height, xoffset, yoffset){ + ctx.fillStyle = pixel.color; + ctx.fillRect(canvasCoord(pixel.x+xoffset), canvasCoord(pixel.y+yoffset), pixelSize*width, pixelSize*height) +} +autoFillColorRectangle = function(ctx, pixel, color, width, height, xoffset, yoffset){ + ctx.fillStyle = color; + ctx.fillRect(canvasCoord(pixel.x+xoffset), canvasCoord(pixel.y+yoffset), pixelSize*width, pixelSize*height) +} +grabDistances = function(pixel){ + let element = pixel.element + // first we find upper not the same + let results = {} + for (let i = 0; i < height; i++){ + if (isEmpty(pixel.x, pixel.y-i, true) || pixelMap[pixel.x][pixel.y-i].element != element){ + results.top = i + if (isEmpty(pixel.x, pixel.y-i, true)){ + results.topelement = "air" + } else { + results.topelement = pixelMap[pixel.x][pixel.y-i].element + } + break; + } + } + // now bottom not same + for (let i = 0; i < height; i++){ + if (isEmpty(pixel.x, pixel.y+i, true) || pixelMap[pixel.x][pixel.y + i].element != element){ + results.bottom = i + if (isEmpty(pixel.x, pixel.y+i, true)){ + results.bottomelement = "air" + } else { + results.bottomelement = pixelMap[pixel.x][pixel.y + i].element + } + break; + } + } + return results +} +elements.dripstone_spike = { + color: "#927965", + category: "minecraft", + behavior: behaviors.WALL, + tempHigh: 1810, + stateHigh: "molten_dripstone", + density: 2550, + renderer: function(pixel, ctx){ + if (pixel.spikeType == 1){ + autoFillDrawRectangle(ctx, pixel, 1, 1/3, 0, 0) + autoFillDrawRectangle(ctx, pixel, 2/3, 1, 1/6, 0)} + else if (pixel.spikeType == 2){ + autoFillDrawRectangle(ctx, pixel, 2/3, 1, 1/6, 0) + } + else if (pixel.spikeType == 3){ + autoFillDrawRectangle(ctx, pixel, 2/3, 5/6, 1/6, 0) + autoFillDrawRectangle(ctx, pixel, 0.5, 1/3, 1/3, 2/3) + } + else if (pixel.spikeType == 4){ + autoFillDrawRectangle(ctx, pixel, 0.5, 1/3, 1/3, 0) + autoFillDrawRectangle(ctx, pixel, 1/3, 1/3, 1/3, 1/6) + autoFillDrawRectangle(ctx, pixel, 1/6, 0.5, 1/3, 1/3) + } + else{ + drawSquare(ctx, pixel.color, pixel.x, pixel.y) + } + }, + tick: function(pixel){ + let distance = grabDistances(pixel); + if (distance.bottom == 1) + {pixel.spikeType = 4} + else if (distance.bottom == 2) + {pixel.spikeType = 3} + else if (distance.bottom >= 3 && distance.top > 1) + {pixel.spikeType = 2} + else + {pixel.spikeType = 1} + if (!pixel.spikeType){console.log(distance)} + if (distance.topelement == "air" && distance.top == 1){ + // make the entire spike fall + let fallList = [] + for (let i = 0; i < height; i++){ + if (!isEmpty(pixel.x, pixel.y+i, true) && pixelMap[pixel.x][pixel.y+i].element == "dripstone_spike"){ + fallList.push(pixelMap[pixel.x][pixel.y+i]) + } else {break} + } + fallList = fallList.reverse(); + for (let i = 0; i 2 * (pixel.x - mousePos.x) + 0.5 * mouseSize) && (pixel.y - mousePos.y + mouseSize > -2 * (pixel.x - mousePos.x) + 0.5 * mouseSize)) { + deletePixel(pixel.x, pixel.y) + createPixel(circleElem, pixel.x, pixel.y) + } else { + deletePixel(pixel.x, pixel.y) + } + } +} function randomIntFromInterval(min, max) { // min and max included return Math.floor(Math.random() * (max - min + 1) + min) } @@ -3098,6 +3119,36 @@ let pistonStart = 0 let pistonEnd = 0 let pistonDistance = 1 let pistonCooldown = 10 +let pistonRepeat = 1 +let pistonRepeatCooldown = 1 +function pistonEmit(pixel, i){ + pixel.cooldown = pixel.pistonCooldown + pixel.rcooldown = pixel.pistonRepeatCooldown + var dir = [0-squareCoords[i][0], 0-squareCoords[i][1]] + var startx = pixel.x+(dir[0]*(pixel.pistonStart+1)) + var starty = pixel.y+(dir[1]*(pixel.pistonStart+1)) + var magnitude = pixel.pistonEnd + var endx = startx+(magnitude*dir[0]) + var endy = starty+(magnitude*dir[1]) + // console.log("Direction seems to be " + dir) + var jcoords + if (pixel.pullOrPush == 1){jcoords = lineCoords(startx, starty, endx, endy, 1)} + else {jcoords = lineCoords(endx, endy, startx, starty, 1)} + + + // console.log(startx + " is the starting x, " + starty + " is the starting y, " + endx + " is the ending x, " + endy + " is the ending y. Result is " + jcoords) + let pCoord = jcoords[0] + for (var j = 0; j < jcoords.length; j++) { + var lcoord = jcoords[j]; + var lx = lcoord[0]; + var ly = lcoord[1]; + if (!isEmpty(lx, ly, true)){ + tryMove(pixelMap[lx][ly], pCoord[0], pCoord[1], null, true) + } + pCoord[0] = lx; + pCoord[1] = ly; + } +} elements.specific_piston_ray_emitter = { color: "#517597", behavior: behaviors.WALL, @@ -3115,6 +3166,12 @@ elements.specific_piston_ray_emitter = { pistonDistance = ans4 var ans5 = parseInt(prompt("How many ticks should it wait to be charged again?", "6")) pistonCooldown = ans5 + var ans6 = parseInt(prompt("How many times should it repeat the push/pulling?", "1")) + pistonRepeat = ans6 + if (pistonRepeat != 1){ + var ans7 = parseInt(prompt("How many ticks should it wait between repeats?", "1")) + pistonRepeatCooldown = ans7 + } }, tick: function(pixel){ if (pixelTicks == pixel.start){ @@ -3123,8 +3180,13 @@ elements.specific_piston_ray_emitter = { pixel.pistonEnd = pistonEnd pixel.pistonDistance = pistonDistance pixel.pistonCooldown = pistonCooldown + pixel.pistonRepeat = pistonRepeat + pixel.pistonRepeatCooldown = pistonRepeatCooldown } if (!pixel.cooldown){pixel.cooldown = 0} + if (!pixel.rcooldown){pixel.rcooldown = 0} + if (!pixel.repeatAmounts){pixel.repeatAmounts = 0} + if (!pixel.fakei){pixel.fakei = 0} if (pixel.cooldown < 1){ for (var i = 0; i < adjacentCoords.length; i++) { var coord = squareCoords[i]; @@ -3132,34 +3194,21 @@ elements.specific_piston_ray_emitter = { var y = pixel.y+coord[1]; if (!isEmpty(x,y, true)){ if (pixelMap[x][y].charge && (pixelMap[x][y].element == "wire" || pixelMap[x][y].element == "insulated_wire")){ + pixel.repeatAmounts = pixel.pistonRepeat + pixel.fakei = i for (let r = 0; r < pixel.pistonDistance; r++){ - pixel.cooldown = pixel.pistonCooldown - var dir = [0-squareCoords[i][0], 0-squareCoords[i][1]] - var startx = pixel.x+(dir[0]*(pixel.pistonStart+1)) - var starty = pixel.y+(dir[1]*(pixel.pistonStart+1)) - var magnitude = pixel.pistonEnd - var endx = startx+(magnitude*dir[0]) - var endy = starty+(magnitude*dir[1]) - // console.log("Direction seems to be " + dir) - var jcoords - if (pixel.pullOrPush == 1){jcoords = lineCoords(startx, starty, endx, endy, 1)} - else {jcoords = lineCoords(endx, endy, startx, starty, 1)} - - // console.log(startx + " is the starting x, " + starty + " is the starting y, " + endx + " is the ending x, " + endy + " is the ending y. Result is " + jcoords) - let pCoord = jcoords[0] - for (var j = 0; j < jcoords.length; j++) { - var lcoord = jcoords[j]; - var lx = lcoord[0]; - var ly = lcoord[1]; - if (!isEmpty(lx, ly, true)){ - tryMove(pixelMap[lx][ly], pCoord[0], pCoord[1], null, true) - } - pCoord[0] = lx; - pCoord[1] = ly; - }} + pistonEmit(pixel, i); + } + pixel.repeatAmounts-- } } - }} else {pixel.cooldown -= 1} + }} else {pixel.cooldown --} + if (pixel.rcooldown < 1 && pixel.repeatAmounts > 0){ + for (let r = 0; r < pixel.pistonDistance; r++){ + pistonEmit(pixel, pixel.fakei); + } + pixel.repeatAmounts-- + } else {pixel.rcooldown --} }, insulate: true, } @@ -3610,4 +3659,61 @@ elements.copycat_filler = { } } } +} +/* +top left: canvasCoord(x), canvasCoord(y) +top right: canvasCoord(x)+pixelSize, canvasCoord(y) +bottom left: canvasCoord(x), canvasCoord(y)+pixelSize +bottom right: canvasCoord(x)+pixelSize, canvasCoord(y)+pixelSize +*/ +adjacentSidesToCanvas = function(x, y, px, py){ + if (x == 0 && y == -1){ + return [canvasCoord(px)+(0.5*pixelSize), canvasCoord(py)] + } + else if (x == 0 && y == 1){ + return [canvasCoord(px)+(0.5*pixelSize), canvasCoord(py)+pixelSize] + } + else if (x == -1 && y == 0){ + return [canvasCoord(px), canvasCoord(py)+(0.5*pixelSize)] + } + else if (x == 1 && y == 0){ + return [canvasCoord(px)+pixelSize, canvasCoord(py)+(0.5*pixelSize)] + } +} +drawRectangle = function(ctx, color, x, y, width, height, xoffset, yoffset){ + ctx.fillStyle = color; + ctx.fillRect(canvasCoord(x+xoffset), canvasCoord(y+yoffset), pixelSize*width, pixelSize*height) +} +elements.thin_pixel = { + color: "#747474", + behavior: behaviors.WALL, + category: "special", + renderer: function(pixel, ctx){ + let differentAdjacent = []; + for (let i = 0; i < adjacentCoords.length; i++) { + let x = adjacentCoords[i][0] + pixel.x; + let y = adjacentCoords[i][1] + pixel.y; + if (!isEmpty(x, y, true) && pixelMap[x][y].element == "thin_pixel") { + differentAdjacent.push(adjacentCoords[i]); + } + } + ctx.globalAlpha = 1 + differentAdjacent.forEach(adj => { + let canvasadjacentCoords = adjacentSidesToCanvas(adj[0], adj[1], pixel.x, pixel.y); + // if (!canvasadjacentCoords){ + // console.log(adj) + // return; + // } + //console.log(canvasadjacentCoords); + ctx.beginPath(); + ctx.moveTo(canvasCoord(pixel.x)+(0.5*pixelSize), canvasCoord(pixel.y)+(0.5*pixelSize)); + ctx.lineTo(canvasadjacentCoords[0], canvasadjacentCoords[1]); + ctx.strokeStyle = pixel.color; + if (pixelSize*0.24>=2){ctx.lineWidth = pixelSize*0.24}else{ctx.lineWidth = 2} + ctx.stroke(); + //console.log("line") + }); + ctx.fillStyle = pixel.color; + ctx.fillRect(canvasCoord(pixel.x+0.38), canvasCoord(pixel.y+0.38), pixelSize*0.24, pixelSize*0.24); + } } \ No newline at end of file diff --git a/mods/ores.js b/mods/ores.js index 4461c9ea..0174e51e 100644 --- a/mods/ores.js +++ b/mods/ores.js @@ -141,10 +141,10 @@ renderEachPixel(function(pixel, ctx) { } differentAdjacent.forEach(adj => { let canvasadjacentCoords = adjacentToCanvas(adj[0], adj[1], pixel.x, pixel.y); - if (!canvasadjacentCoords){ - console.log(adj) - return; - } + // if (!canvasadjacentCoords){ + // console.log(adj) + // return; + // } //console.log(canvasadjacentCoords); ctx.beginPath(); ctx.moveTo(canvasadjacentCoords[0][0], canvasadjacentCoords[0][1]); From c6e738e67ab8f76b3586cc1a803b3749a1499ade Mon Sep 17 00:00:00 2001 From: JustAGenericUsername <92590792+JustAGenericUsername@users.noreply.github.com> Date: Sat, 24 Aug 2024 15:15:21 -0400 Subject: [PATCH 09/10] a --- mods/nousersthings.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mods/nousersthings.js b/mods/nousersthings.js index c7a0b060..f0229f3a 100644 --- a/mods/nousersthings.js +++ b/mods/nousersthings.js @@ -3183,6 +3183,10 @@ elements.specific_piston_ray_emitter = { pixel.pistonRepeat = pistonRepeat pixel.pistonRepeatCooldown = pistonRepeatCooldown } + if (!pixel.pistonRepeat){ + pixel.pistonRepeat = pistonRepeat + pixel.pistonRepeatCooldown = pistonRepeatCooldown + } if (!pixel.cooldown){pixel.cooldown = 0} if (!pixel.rcooldown){pixel.rcooldown = 0} if (!pixel.repeatAmounts){pixel.repeatAmounts = 0} From 4da0a57e957d805abcaa851890a4b0321890d311 Mon Sep 17 00:00:00 2001 From: JustAGenericUsername <92590792+JustAGenericUsername@users.noreply.github.com> Date: Sat, 24 Aug 2024 16:03:27 -0400 Subject: [PATCH 10/10] ye --- mods/logicgates.js | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/mods/logicgates.js b/mods/logicgates.js index a88458bc..24698421 100644 --- a/mods/logicgates.js +++ b/mods/logicgates.js @@ -303,43 +303,37 @@ elements.E2L_button = { state: "solid", category: "logic", tick: function(pixel){ - if (pixel.start === pixelTicks){ - pixel.cooldown = 0; - pixel.toggleMode = 1; - } for (var i = 0; i < adjacentCoords.length; i++) { var coord = adjacentCoords[i]; var x = pixel.x+coord[0]; var y = pixel.y+coord[1]; if (!isEmpty(x,y,true)) { - if ((pixelMap[x][y].charge || pixelMap[x][y].chargeCD) && pixel.cooldown == 0){ - for (var i = 0; i < adjacentCoords.length; i++) { - var coord = adjacentCoords[i]; + if ((pixelMap[x][y].charge || pixelMap[x][y].chargeCD)){ + for (var j = 0; j < adjacentCoords.length; j++) { + var coord = adjacentCoords[j]; var x = pixel.x+coord[0]; var y = pixel.y+coord[1]; if (!isEmpty(x,y,true)) { if (pixelMap[x][y].element == "logic_wire"){ - if (pixel.toggleMode == 1){ pixelMap[x][y].lstate = 2 pixelMap[x][y].color = pixelColorPick(pixel, "#ffe49c"); - } else { - pixelMap[x][y].lstate = -2 - pixelMap[x][y].color = pixelColorPick(pixel, "#3d4d2c"); - } } } } - pixel.cooldown = 5 - if (pixel.toggleMode){ - pixel.toggleMode = 0; - } else { - pixel.toggleMode = 1; - } + return; } } } - if (pixel.cooldown){ - pixel.cooldown = pixel.cooldown - 1 + for (var i = 0; i < adjacentCoords.length; i++) { + var coord = adjacentCoords[i]; + var x = pixel.x+coord[0]; + var y = pixel.y+coord[1]; + if (!isEmpty(x,y,true)) { + if (pixelMap[x][y].element == "logic_wire" && pixelMap[x][y].lstate > 0){ + pixelMap[x][y].lstate = -2 + pixelMap[x][y].color = pixelColorPick(pixel, "#3d4d2c"); + } + } } } }