Skip to content

Commit

Permalink
Initial files for MakeCode project
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Dec 1, 2023
1 parent 6ba595b commit 8de52c5
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["ms-edu.pxt-vscode-web"]
}
29 changes: 29 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"editor.formatOnType": true,
"files.autoSave": "afterDelay",
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/built/**": true,
"**/node_modules/**": true,
"**/yotta_modules/**": true,
"**/yotta_targets": true,
"**/pxt_modules/**": true,
"**/.pxt/**": true
},
"files.associations": {
"*.blocks": "html",
"*.jres": "json"
},
"search.exclude": {
"**/built": true,
"**/node_modules": true,
"**/yotta_modules": true,
"**/yotta_targets": true,
"**/pxt_modules": true,
"**/.pxt": true
},
"files.exclude": {
"**/pxt_modules": true,
"**/.pxt": true
}
}
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'github-pages', group: :jekyll_plugins
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all: deploy

build:
pxt build

deploy:
pxt deploy

test:
pxt test
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

> Open this page at [https://thsparks.github.io/mob-menagerie/](https://thsparks.github.io/mob-menagerie/)
## Use as Extension

This repository can be added as an **extension** in MakeCode.

* open [https://minecraft.makecode.com/](https://minecraft.makecode.com/)
* click on **New Project**
* click on **Extensions** under the gearwheel menu
* search for **https://github.com/thsparks/mob-menagerie** and import

## Edit this project

To edit this repository in MakeCode.

* open [https://minecraft.makecode.com/](https://minecraft.makecode.com/)
* click on **Import** then click on **Import URL**
* paste **https://github.com/thsparks/mob-menagerie** and click import

#### Metadata (used for search, rendering)

* for PXT/minecraft
<script src="https://makecode.com/gh-pages-embed.js"></script><script>makeCodeRender("{{ site.makecode.home_url }}", "{{ site.github.owner_name }}/{{ site.github.repository_name }}");</script>
8 changes: 8 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
makecode:
target: minecraft
platform: minecraft
home_url: https://minecraft.makecode.com/
theme: jekyll-theme-slate
include:
- assets
- README.md
1 change: 1 addition & 0 deletions _history

Large diffs are not rendered by default.

202 changes: 202 additions & 0 deletions custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/**
* Mob Menagerie
*/
//% weight=100 color=#0fbc11 icon="\uf7ab"
namespace Menagerie {

const mmBuilder: builder.Builder = new builder.Builder();

/**
* Create a Sniffer Sanctuary
* @param width Width of the sanctuary (x axis)
* @param depth Depth of the sanctuary (z axis)
* @param position Position of the center of the sanctuary
*/
//% block="create sniffer sanctuary with width %width depth %depth at %position"
//% position.shadow=minecraftCreatePosition
export function createSnifferSanctuary(width: number, depth: number, position: Position): void {
// Fix the position so it doesn't move if the player moves
position = position.toWorld();

createEnclosure(width, depth, position, MOSS_BLOCK, MOSSY_COBBLESTONE_WALL);

decorateEnclosure(width, depth, position, [TORCHFLOWER], 0.1, 0.3);

// Spawn sniffers
spawnMobs(width, depth, position, [AnimalMob.Sniffer], 0.01, 0.02);
}

/**
* Create an Allay Aviary
* @param width Width of the aviary (x axis)
* @param width Height of the aviary (y axis)
* @param depth Depth of the aviary (z axis)
* @param position Position of the center of the aviary
*/
//% block="create allay aviary with width %width height %height depth %depth at %position"
//% position.shadow=minecraftCreatePosition
export function createAllayAviary(width: number, height: number, depth: number, position: Position): void {
// Fix the position so it doesn't move if the player moves
position = position.toWorld();

const minCorner = getMinCornerOfSquare(width, depth, position).move(CardinalDirection.Down, 1);
const maxCorner = positions.add(minCorner, pos(width - 1, height, depth - 1)); // Floor is not included in height, hence no -1 on height.
blocks.fill(GLASS, minCorner, maxCorner, FillOperation.Hollow);

const maxFloorCorner = positions.add(minCorner, pos(width - 1, 0, depth - 1));
blocks.fill(CHISELED_QUARTZ_BLOCK, minCorner, maxFloorCorner, FillOperation.Replace)

// Spawn allays
spawnMobs(width, depth, position, [AnimalMob.Allay], 0.3, 0.5);
}

/**
* Create a Strider Shelter
* @param width Width of the shelter (x axis)
* @param depth Depth of the shelter (z axis)
* @param position Position of the center of the shelter
*/
//% block="create strider shelter with width %width depth %depth at %position"
//% position.shadow=minecraftCreatePosition
export function createStriderShelter(width: number, depth: number, position: Position): void {
// Fix the position so it doesn't move if the player moves
position = position.toWorld();

// Bone block with data 4 rotates it so the "circle" side is not visible
createEnclosure(width, depth, position, NETHERRACK, CRIMSON_FENCE)

decorateEnclosure(width, depth, position, [FIRE], 0.05, 0.1);
if (width > 5 && depth > 5) {
// We have enough space to add some lava, but we need to keep it close to the center
decorateEnclosure(width - 2, depth - 2, position.move(CardinalDirection.Down, 1), [LAVA], 0.6, 0.8, NETHERRACK);
}

// Spawn striders
spawnMobs(width, depth, position, [AnimalMob.Strider], 0.05, 0.1);
}

/**
* Create a Spooky Stable
* @param width Width of the stable (x axis)
* @param depth Depth of the stable (z axis)
* @param position Position of the center of the stable
*/
//% block="create spooky stable with width %width depth %depth at %position"
//% position.shadow=minecraftCreatePosition
export function createSpookyStable(width: number, depth: number, position: Position): void {
// Fix the position so it doesn't move if the player moves
position = position.toWorld();

// Bone block with data 4 rotates it so the "circle" side is not visible
createEnclosure(width, depth, position, blocks.blockWithData(BONE_BLOCK, 4), WARPED_FENCE)

// Spawn spooky horses
spawnMobs(width, depth, position, [AnimalMob.ZombieHorse, AnimalMob.SkeletonHorse], 0.01, 0.02);
}

/**
* Create a Mooshroom Meadow
* @param width Width of the meadow (x axis)
* @param depth Depth of the meadow (z axis)
* @param position Position of the center of the meadow
*/
//% block="create mooshroom meadow with width %width depth %depth at %position"
//% position.shadow=minecraftCreatePosition
export function createMooshroomMeadow(width: number, depth: number, position: Position): void {
// Fix the position so it doesn't move if the player moves
position = position.toWorld();

createEnclosure(width, depth, position, MYCELIUM, SPRUCE_FENCE)

// Add sporadic mushrooms
const mushrooms = [
RED_MUSHROOM,
BROWN_MUSHROOM
]
decorateEnclosure(width, depth, position, mushrooms, 0.01, 0.02);

// Spawn mooshrooms
spawnMobs(width, depth, position, [AnimalMob.MushroomCow], 0.02, 0.03);
}

function spawnMobs(width: number, depth: number, position: Position, mobsToSpawn: number[], minDensity: number, maxDensity: number,) {
const [innerMin, innerMax] = getInnerSquareBounds(width, depth, position);
const area = (width - 2) * (depth - 2);
const minCount = Math.floor(area * minDensity);
const maxCount = Math.floor(area * maxDensity);

// At least one of each mob
const count = Math.max(mobsToSpawn.length, randint(minCount, maxCount));

for (let i = 0; i < count; i++) {
mobs.spawn(mobsToSpawn[i % mobsToSpawn.length], randpos(innerMin, innerMax));
}
}

function decorateEnclosure(
width: number,
depth: number,
position: Position,
items: number[],
minDensity: number,
maxDensity: number,
replaceBlock: number = 0) { // 0 = AIR
const [innerMin, innerMax] = getInnerSquareBounds(width, depth, position);
const area = (width - 2) * (depth - 2);
const minCount = Math.floor(area * minDensity);
const maxCount = Math.floor(area * maxDensity);
const count = randint(minCount, maxCount);
for (let i = 0; i < count; i++) {
const item = items[randint(0, items.length - 1)];
const pos = randpos(innerMin, innerMax);
if (blocks.testForBlock(replaceBlock, pos)) {
blocks.place(item, pos);
}
}
}

function getMinCornerOfSquare(width: number, depth: number, center: Position) {
return positions.add(center, pos(-(width / 2), 0, -(depth / 2)));
}

function getInnerSquareBounds(width: number, depth: number, center: Position) {
const innerMin = positions.add(getMinCornerOfSquare(width, depth, center), pos(1, 0, 1));
const innerMax = positions.add(innerMin, pos(width - 3, 0, depth - 3));
return [innerMin, innerMax];
}

function createEnclosure(width: number, depth: number, position: Position, floorMaterial: number, wallMaterial: number) {
const startPosition = getMinCornerOfSquare(width, depth, position);
mmBuilder.teleportTo(startPosition);

// Build walls
mmBuilder.teleportTo(startPosition);
mmBuilder.mark();
mmBuilder.face(CompassDirection.East) // +X
mmBuilder.move(SixDirection.Forward, width - 1);
mmBuilder.fill(wallMaterial)

mmBuilder.mark();
mmBuilder.face(CompassDirection.South); // +Z
mmBuilder.move(SixDirection.Forward, depth - 1);
mmBuilder.line(wallMaterial)

const farCorner = mmBuilder.position();

mmBuilder.mark();
mmBuilder.face(CompassDirection.West) // -X
mmBuilder.move(SixDirection.Forward, width - 1);
mmBuilder.line(wallMaterial)

mmBuilder.mark();
mmBuilder.face(CompassDirection.North) // -Z
mmBuilder.move(SixDirection.Forward, depth - 1);
mmBuilder.line(wallMaterial)

// Build floor
mmBuilder.move(SixDirection.Down, 1);
mmBuilder.mark();
mmBuilder.teleportTo(farCorner.move(CardinalDirection.Down, 1));
mmBuilder.fill(floorMaterial, FillOperation.Replace);
}
}
1 change: 1 addition & 0 deletions main.blocks
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="FYVw{+-j[T:Zh@U6k,OQ">num3</variable><variable id="*Bm[(B/l+q*Cz7q7/u8P">num1</variable><variable id="|Co?@~4k7P?n)K+HB.iV">num2</variable></variables></xml>
44 changes: 44 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
def on_on_chat(num1, num2):
Menagerie.create_sniffer_sanctuary(num1, num2, pos(0, 0, 0))
player.on_chat("t", on_on_chat)

def on_on_chat2(num12, num22):
Menagerie.create_sniffer_sanctuary(num12, num22, pos(0, 0, 0))
player.on_chat("sniff", on_on_chat2)

def on_on_chat3(num13, num23, num3):
Menagerie.create_allay_aviary(num13,
num23,
num3,
pos_camera(0, 0, Math.ceil(num3 / 2) + 3))
player.on_chat("fly", on_on_chat3)

def on_on_chat4(num14, num24):
Menagerie.create_strider_shelter(num14, num24, pos(0, 0, 0))
player.on_chat("stride", on_on_chat4)

def on_on_chat5(num15, num25):
Menagerie.create_mooshroom_meadow(num15, num25, pos(0, 0, 0))
player.on_chat("moo", on_on_chat5)

def on_on_chat6(num16, num26):
Menagerie.create_spooky_stable(num16, num26, pos(0, 0, 0))
player.on_chat("boo", on_on_chat6)

def on_on_chat7():
agent.teleport_to_player()
player.say(agent.inspect(AgentInspection.DATA, FORWARD))
player.on_chat("i", on_on_chat7)

def on_on_chat8():
if not blocks.test_for_block(AIR, pos(0, -1, 0)):
blocks.fill(GRASS,
pos_camera(-25, -1, 0),
pos_camera(25, -1, 50),
FillOperation.REPLACE)
blocks.fill(AIR,
pos_camera(-25, 0, 0),
pos_camera(25, 10, 50),
FillOperation.REPLACE)
mobs.kill(mobs.target(ALL_ENTITIES))
player.on_chat("clear", on_on_chat8)
43 changes: 43 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
player.onChat("moo", function (num1, num2) {
Menagerie.createMooshroomMeadow(num1, num2, pos(0, 0, 0))
})
player.onChat("sniff", function (num1, num2) {
Menagerie.createSnifferSanctuary(num1, num2, pos(0, 0, 0))
})
player.onChat("stride", function (num1, num2) {
Menagerie.createStriderShelter(num1, num2, pos(0, 0, 0))
})
player.onChat("boo", function (num1, num2) {
Menagerie.createSpookyStable(num1, num2, pos(0, 0, 0))
})
player.onChat("fly", function (num1, num2, num3) {
Menagerie.createAllayAviary(
num1,
num2,
num3,
posCamera(0, 0, Math.ceil(num3 / 2) + 3)
)
})
player.onChat("clear", function () {
if (!(blocks.testForBlock(AIR, pos(0, -1, 0)))) {
blocks.fill(
GRASS,
posCamera(-25, -1, 0),
posCamera(25, -1, 50),
FillOperation.Replace
)
}
blocks.fill(
AIR,
posCamera(-25, 0, 0),
posCamera(25, 10, 50),
FillOperation.Replace
)
mobs.kill(
mobs.target(ALL_ENTITIES)
)
})
player.onChat("i", function () {
agent.teleportToPlayer()
player.say(agent.inspect(AgentInspection.Data, FORWARD))
})
Loading

0 comments on commit 8de52c5

Please sign in to comment.