Skip to content

Commit 397a6f9

Browse files
committed
Fixed dimension loading, made graves spawn zombies
1 parent 8730292 commit 397a6f9

3 files changed

Lines changed: 74 additions & 46 deletions

File tree

behavior_packs/whynot/blocks/gravestone.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
"*": {
1111
"texture": "gravestone"
1212
}
13-
}
13+
},
14+
"minecraft:tick": {
15+
"interval_range": [5, 5],
16+
"looping": true
17+
},
18+
"whynot:gravestone_component": {}
1419
}
1520
}
1621
}

behavior_packs/whynot/entities/michael_zombie.json

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,12 @@
77
"is_spawnable": true,
88
"is_summonable": true
99
},
10-
"component_groups": {
11-
"minecraft:zombie_baby": {
12-
"minecraft:is_baby": {},
13-
"minecraft:scale": {"value": 0.5},
14-
"minecraft:movement": {"value": 0.35}
15-
},
16-
"minecraft:zombie_adult": {
17-
"minecraft:movement": {"value": 0.23}
18-
},
19-
"minecraft:can_break_doors": {
20-
"minecraft:annotation.break_door": {}
21-
}
22-
},
2310

2411
"components": {
2512
"minecraft:is_hidden_when_invisible": {},
2613
"minecraft:nameable": {},
14+
// "minecraft:movement": {"value": 0.23},
15+
2716

2817
// Zombie Components
2918
"minecraft:type_family": {
@@ -42,12 +31,12 @@
4231
},
4332
"minecraft:burns_in_daylight": {},
4433
"minecraft:movement.basic": {},
45-
"minecraft:navigation.walk": {
46-
"is_amphibious": true,
47-
"can_pass_doors": true,
48-
"can_walk": true,
49-
"can_break_doors": true
50-
},
34+
// "minecraft:navigation.walk": {
35+
// "is_amphibious": true,
36+
// "can_pass_doors": true,
37+
// "can_walk": false,
38+
// "can_break_doors": true
39+
// },
5140
"minecraft:jump.static": {},
5241
"minecraft:can_climb": {},
5342
"minecraft:health": {
@@ -359,19 +348,19 @@
359348
"is_pushable_by_piston": true
360349
},
361350
"minecraft:conditional_bandwidth_optimization": {}
362-
},
363-
364-
"events": {
365-
"minecraft:as_adult": {
366-
"add": {
367-
"component_groups": ["minecraft:zombie_adult"]
368-
}
369-
},
370-
"minecraft:as_baby": {
371-
"add": {
372-
"component_groups": ["minecraft:zombie_baby"]
373-
}
374-
}
375351
}
352+
353+
// "events": {
354+
// "minecraft:as_adult": {
355+
// "add": {
356+
// "component_groups": ["minecraft:zombie_adult"]
357+
// }
358+
// },
359+
// "minecraft:as_baby": {
360+
// "add": {
361+
// "component_groups": ["minecraft:zombie_baby"]
362+
// }
363+
// }
364+
// }
376365
}
377366
}

scripts/addons/michael/michael.ts

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,62 @@
1-
import { VECTOR3_UP, VECTOR3_ZERO } from "@minecraft/math";
2-
import { Dimension, StartupEvent, VanillaEntityIdentifier, world, World } from "@minecraft/server";
1+
import { VECTOR3_DOWN, VECTOR3_UP, VECTOR3_ZERO } from "@minecraft/math";
2+
import { BlockCustomComponent, Dimension, StartupEvent, system, VanillaEntityIdentifier, world, World } from "@minecraft/server";
33
import { V3 } from "../../math/vectorUtils";
44
import { ActionFormData } from "@minecraft/server-ui";
55

66
const MichaelDimID = "whynot:michael_dimension"
77
let michaelDim: Dimension
88
export function main() {
99
michaelDim = world.getDimension(MichaelDimID)
10-
world.structureManager.place("whynot:michael_structure", michaelDim, V3.make(-1, 0, -4))
11-
michaelDim.getEntities({type: "whynot:michael_zombie"}).forEach(entity => entity.remove())
12-
michaelDim.spawnEntity("whynot:michael_zombie" as VanillaEntityIdentifier, V3.make(22, 1, 0))
10+
world.tickingAreaManager.createTickingArea("whynot:michael_ticking", {dimension: michaelDim, from: V3.make(19, 0, 0), to: V3.make(21, 2, 0)})
11+
1312
world.afterEvents.playerInteractWithBlock.subscribe(ev => {
13+
if (ev.player.dimension == michaelDim) return
1414
if (ev.block.typeId != "whynot:gravestone") return
15-
const form = new ActionFormData()
16-
form.title("Gravestone")
17-
form.body("Here lies the king of pop, do you accept his challenge?")
18-
form.button("Yes")
19-
form.button("Yes")
20-
form.show(ev.player).finally(() => {
21-
ev.player.teleport(VECTOR3_UP, {dimension: michaelDim})
22-
})
15+
2316
})
2417

18+
19+
system.runInterval(tick, 1)
20+
21+
}
22+
let battleStarted = false
23+
function tick() {
24+
let michael = michaelDim.getEntities({type: "whynot:michael_zombie"})[0]
25+
if (!michael) return
26+
let playerNear = michaelDim.getPlayers({maxDistance: 4, location: michael.location, closest: 1}).length > 0
27+
if (playerNear && !battleStarted) {
28+
michael.applyImpulse(V3.make(0, 1, 0))
29+
battleStarted = true
30+
}
31+
if (battleStarted && !michael.isOnGround && michael.getVelocity().y < 0.0) {
32+
michaelDim.setBlockType(V3.add(michael.location, VECTOR3_DOWN), "minecraft:stone")
33+
}
2534
}
2635
export function startup(ev: StartupEvent) {
2736
ev.dimensionRegistry.registerCustomDimension(MichaelDimID);
37+
ev.blockComponentRegistry.registerCustomComponent("whynot:gravestone_component", {
38+
onPlayerInteract(ev) {
39+
if (!ev.player) return
40+
if (ev.dimension == michaelDim) return
41+
world.structureManager.place("whynot:michael_structure", michaelDim, V3.make(-1, 0, -4))
42+
43+
michaelDim.getEntities({type: "whynot:michael_zombie"}).forEach(entity => entity.remove())
44+
system.runTimeout(() => {
45+
michaelDim.spawnEntity("whynot:michael_zombie" as VanillaEntityIdentifier, V3.make(20.5, 1.0, 0.5))
46+
}, 25)
47+
48+
const form = new ActionFormData()
49+
form.title("Gravestone")
50+
form.body("Here lies the king of pop, do you accept his challenge?")
51+
form.button("Yes")
52+
form.button("Yes")
53+
form.show(ev.player).finally(() => {
54+
ev.player?.teleport(V3.make(0.5, 1.0, 0.5), {dimension: michaelDim})
55+
})
56+
},
57+
onTick(ev) {
58+
if (ev.dimension != michaelDim) return
59+
michaelDim.spawnEntity("whynot:dancer_zombie" as VanillaEntityIdentifier, ev.block.location)
60+
}
61+
})
2862
}

0 commit comments

Comments
 (0)