Skip to content

Commit

Permalink
v2 stash (#8)
Browse files Browse the repository at this point in the history
* upd: mcstructure output

- Renamed typings to types/index.ts
- Added .mcstructure generator
- Added flipbook to GIF

* upd: Manifest w/ scripts

* removed: Pixel art functions

* upd: WSS types import

* upd: Read file in compiler

* upd: Improved structure output

- Successful mcstructure output - except it prints image on its side

* upd: Upright structure output

* upd: Rotate image to display upright

* upd: Imports / Server functions

* feat: BP script

- Updated paths

* feat: Model classes

* feat: Created test structure

* feat: 🍔

- Added burger pixel art

* feat: Stable Diffusion support in WSS

* fix: Flipbooks & structures

* upd: Version change

* upd: Build script

* wip: Stash!

- v2 dead-end code
  • Loading branch information
jasonjgardner authored Feb 6, 2024
1 parent 53c35f5 commit b7a0c95
Show file tree
Hide file tree
Showing 80 changed files with 5,218 additions and 710 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ jobs:
- name: Upload docs
uses: actions/upload-artifact@v2
with:
name: 🌈.zip
name: docs.zip
path: |
dist/docs.zip
23 changes: 23 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Docs

on:
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
with:
name: docs
path: docs.zip
- uses: actions/checkout@v2
with:
ref: docs
fetch-depth: 0
- name: Commit docs
run: |
git config --global user.name "GitHub Actions"
10 changes: 9 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"version": "0.3.0",
"configurations": [
{
"type": "minecraft-js",
"request": "attach",
"name": "Wait for Minecraft Debug Connections",
"mode": "listen",
"localRoot": "${workspaceFolder}/",
"port": 19144
},
{
"request": "launch",
"name": "Build",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
},
"[jsonc]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
},
"editor.formatOnSave": true
}
172 changes: 172 additions & 0 deletions bds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import { load } from "https://deno.land/[email protected]/dotenv/mod.ts";
import { Application } from "https://deno.land/x/oak/mod.ts";
import { Image, decode, GIF } from "imagescript/mod.ts";
import { convertImage } from "./src/components/ImagePrinter.ts";
import assemble from "./src/components/_assemble.ts";
import openai from "npm:openai@^3.2.1";
import { Axis } from "./types/index.ts";

const { Configuration, OpenAIApi } = openai;

const env = await load();
const OPENAI_API_KEY = env.OPENAI_API_KEY || Deno.env.get("OPENAI_API_KEY") ||
"";

const configuration = new Configuration({
apiKey: OPENAI_API_KEY,
});

const client = new OpenAIApi(configuration);

const colorList = [
"yellow",
"amber",
"orange",
"deep_orange",
"red",
"pink",
"purple",
"deep_purple",
"indigo",
"blue",
"light_blue",
"cyan",
"teal",
"light_green",
"green",
"lime",
];

let lastColor = 0;
let lastFrame = 0;
let lastMaterialIdx = 0;

const material = ["glass","negative", "glowing", "metallic"];
// const imageRes = await fetch(
// "https://raw.githubusercontent.com/jasonjgardner/minecraft-rtx-rainbow/main/src/assets/pixel_art/chest.png",
// );
// const imageData = await imageRes.arrayBuffer();
const imageData = await Deno.readFile("./src/assets/pixel_art/big.jpeg")
// const decoded = await decode(imageData, false) as GIF;

const mask = (await Image.decode(await Deno.readFile("./src/assets/mask/tunnel_mask.png"))).invert();
const depth = (await Image.decode(await Deno.readFile("./src/assets/mask/poly_depth.png")));
const axises = ["x", "y", "z"];

async function printImage() {
const blockLibrary = assemble(["glass_pane", "brick_lit"]).filter((b) =>
b.behaviorId.includes(material[lastMaterialIdx])
);

const commands: string[] = [];

// if (lastFrame >= decoded.length) {
// lastFrame = 0;
// }

if (lastMaterialIdx >= material.length) {
lastMaterialIdx = 0;
}

commands.push(
...convertImage(
// decoded[lastFrame].resize(72, Image.RESIZE_AUTO),
(await decode(imageData, false)).resize(64, Image.RESIZE_AUTO) as Image,
blockLibrary,
[0, 0, 20],
axises[lastFrame % 3] as Axis,
undefined,
mask,
),
);

lastFrame += 1;
lastMaterialIdx += 1;

return commands;
}

const app = new Application();

function getBlockName(color: string, material: string, level = 50, tint = 500) {
return `rainbow:${color}_${tint}_${material}_${level}`;
}

function getBlocks(tint = 500) {
const colors = [
"yellow",
"amber",
"orange",
"deep_orange",
"red",
"pink",
"purple",
"deep_purple",
"indigo",
"blue",
"light_blue",
"cyan",
"teal",
"light_green",
"green",
"lime",
];

const materials = ["glowing"];
const levels = [25];

const blockList = [];

for (const color of colors) {
for (const material of materials) {
for (const level of levels) {
blockList.push(getBlockName(color, material, level, tint));
}
}
}

return blockList;
}

let cameraVector = [10, 20, 10];

app.use(async (ctx) => {
if (ctx.request.method !== "GET") {

console.log(ctx.request)
}

ctx.response.headers.set("Content-Type", "text/plain");

if (lastColor >= colorList.length) {
lastColor = 0;
}

if (lastMaterialIdx >= material.length) {
lastMaterialIdx = 0;
}

const lines = [
// ...await printImage(),
// '/setblock ~ ~9 ~ redstone_block',
// '/setblock ~ ~10 ~ tnt',
`/setblock ~ ~-1 ~ ${getBlockName(colorList[lastColor], material[lastMaterialIdx], 50, 500)}`,
`/execute at @e[type=!player] as @e[r=5] at @s run setblock ~ ~-1 ~ ${getBlockName(colorList[lastColor], material[lastMaterialIdx], 50, 800)}`,
`/execute at @e[type=!player] as @e[r=5] at @s run fill ~-4 ~-1 ~3 ~4 ~-1 ~5 ${getBlockName(colorList[lastColor], material[lastMaterialIdx], 50, 200)}`,
]


// Update camera vector to move camera in circle around player
// cameraVector = [
// Math.sin(Date.now() / 1000) * 5,
// Math.sin(Date.now() / 1000) * 5,
// Math.cos(Date.now() / 1000) * 5,
// ]

lastColor += 1;
lastMaterialIdx += 1;

ctx.response.body = JSON.stringify({ command: lines.join(";"), target: "eljaysun", tick: 5 });
});

await app.listen({ port: 8000 });
8 changes: 5 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"tasks": {
"test": "deno run --allow-read --allow-net --allow-env --allow-write --inspect ./src/mod.ts --DEPLOY true",
"build": "deno run --allow-read --allow-net --allow-env --allow-write ./src/mod.ts",
"test": "deno run -A --unstable ./src/mod.ts --DEPLOY true",
"test:preview": "deno run --allow-read --allow-net --allow-env --allow-write --allow-run --inspect ./src/mod.ts --DEPLOY true --PREVIEW true",
"build": "deno run -A --unstable ./src/mod.ts",
"art": "deno run --allow-read --allow-net --allow-env --allow-write ./src/mod.ts --ART_DIR ./px",
"serve": "deno run --allow-read --allow-net --allow-env --allow-write --unstable --allow-ffi ./serve.ts"
"serve": "deno run -A --unstable ./serve.ts",
"build:data": "gh release download --skip-existing -D ./cache -A zip -R Mojang/bedrock-samples -O bedrock-samples.zip && Expand-Archive -Path ./cache/bedrock-samples.zip -D ./cache"
},
"fmt": {
"files": {
Expand Down
Loading

0 comments on commit b7a0c95

Please sign in to comment.