From dcb64883523ca7bdf80401c22d31120a900d6e7d Mon Sep 17 00:00:00 2001 From: pennylicker6 Date: Mon, 4 Aug 2025 16:41:07 -0800 Subject: [PATCH] Update fission_physics.js new version from senseiollie --- mods/fission_physics.js | 96 ++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 53 deletions(-) diff --git a/mods/fission_physics.js b/mods/fission_physics.js index ee5171f0..f91d631b 100644 --- a/mods/fission_physics.js +++ b/mods/fission_physics.js @@ -1,9 +1,8 @@ -// Basic Fission Mod for Sandboxels -// Simulates simplified nuclear fission with uranium-235, neutrons, and boron control rods. +// === Basic Fission Mod === -// Uranium-235: emits 2-3 neutrons when hit by a neutron, heats up, no byproducts. this is by senseiollie. the creator +// --- Fissionable Uranium-235 --- elements.uranium235 = { - color: "#4a7023", // dark green (uranium oxide green) + color: "#6faa3d", // Classic green uranium behavior: behaviors.SOLID, category: "Energy", state: "solid", @@ -16,15 +15,20 @@ elements.uranium235 = { // Remove incoming neutron deletePixel(otherPixel.x, otherPixel.y); - // Increase heat + // Simulate heat pixel.temp += 200 + Math.random() * 100; - // Emit 2-3 new neutrons nearby + // Optional: transform uranium + changePixel(pixel, "lead"); + + // Emit 2–3 new neutrons let count = Math.floor(Math.random() * 2) + 2; - for(let i = 0; i < count; i++) { - let x = pixel.x + Math.floor(Math.random() * 3) - 1; - let y = pixel.y + Math.floor(Math.random() * 3) - 1; - if(!isEmpty(x, y)) continue; + for (let i = 0; i < count; i++) { + let dx = Math.floor(Math.random() * 3) - 1; + let dy = Math.floor(Math.random() * 3) - 1; + let x = pixel.x + dx; + let y = pixel.y + dy; + if (!isEmpty(x, y)) continue; createPixel("neutron", x, y); } } @@ -32,29 +36,39 @@ elements.uranium235 = { } }; -// Neutron particle: moves around and disappears after 500 ticks. -elements.neutron = { - color: "#dcdcdc", // light gray / off-white - behavior: [ - "M2|M1|M2", - "M1|DL|M1", - "M2|M1|M2" - ], - category: "Energy", - state: "gas", - density: 0.001, - temp: 20, - tick: function(pixel) { - pixel._neutronLife = (pixel._neutronLife || 0) + 1; - if(pixel._neutronLife > 500) { +// --- Add to existing neutron, don't replace it --- +if (elements.neutron) { + // Extend tick behavior + let oldTick = elements.neutron.tick; + elements.neutron.tick = function(pixel) { + // Preserve old tick behavior + if (oldTick) oldTick(pixel); + + // Lifespan decay (500 ticks) + if (!pixel._ticks) pixel._ticks = 0; + pixel._ticks++; + if (pixel._ticks > 500) { deletePixel(pixel.x, pixel.y); } - } -}; + }; -// Boron: solid that absorbs neutrons and heats up slightly. + // Let neutron pass slower through water + elements.neutron.customTick = function(pixel) { + let dirs = [[0,1],[0,-1],[1,0],[-1,0]]; + for (let dir of dirs) { + let x = pixel.x + dir[0]; + let y = pixel.y + dir[1]; + let other = pixelMap[x]?.[y]; + if (other && other.element === "water" && Math.random() < 0.2) { + return; // Skip tick 20% of the time near water + } + } + }; +} + +// --- Boron absorbs neutrons --- elements.boron = { - color: "#f5f0a1", // pale yellow + color: "#dcdcdc", // Light gray boron behavior: behaviors.SOLID, category: "Solids", state: "solid", @@ -70,27 +84,3 @@ elements.boron = { } }; -// Slow neutrons and some particles passing through water by 20%. -const slowThroughWater = ["neutron", "proton", "photon"]; -for(let elem of slowThroughWater) { - if(elements[elem]) { - elements[elem].customTick = function(pixel) { - let waterNearby = false; - let dirs = [[0,1],[0,-1],[1,0],[-1,0]]; - for(let dir of dirs) { - let x = pixel.x + dir[0]; - let y = pixel.y + dir[1]; - let other = pixelMap[x]?.[y]; - if(other && other.element === "water") { - waterNearby = true; - break; - } - } - if(waterNearby && Math.random() < 0.2) { - // Skip tick to slow particle - return; - } - } - } -} -