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]);