├── Episode-01 ├── client │ └── client.js └── server │ └── server.js ├── Episode-02 ├── client │ └── client.js └── server │ └── server.js ├── Episode-03 ├── client │ └── client.js └── server │ └── server.js └── README.md /Episode-01/client/client.js: -------------------------------------------------------------------------------- 1 | var clientSystem = client.registerSystem(0, 0); 2 | const displaychat = "minecraft:display_chat_event"; 3 | // Setup which events to listen for 4 | clientSystem.initialize = function () { 5 | // set up your listenToEvents and register client-side components here. 6 | this.listenForEvent("minecraft:client_entered_world", (eventData) => this.clientJoined(eventData)); 7 | } 8 | 9 | 10 | clientSystem.clientJoined = function(eventData){ 11 | this.broadcastEvent(displaychat, "§aLoaded..."); 12 | } 13 | // per-tick updates 14 | clientSystem.update = function() { 15 | // Any logic that needs to happen every tick on the client. 16 | } -------------------------------------------------------------------------------- /Episode-01/server/server.js: -------------------------------------------------------------------------------- 1 | var serverSystem = server.registerSystem(0, 0); 2 | 3 | // Setup which events to listen for 4 | serverSystem.initialize = function () { 5 | // set up your listenToEvents and register server-side components here. 6 | } 7 | 8 | // per-tick updates 9 | serverSystem.update = function() { 10 | // Any logic that needs to happen every tick on the server. 11 | } -------------------------------------------------------------------------------- /Episode-02/client/client.js: -------------------------------------------------------------------------------- 1 | var clientSystem = client.registerSystem(0, 0); 2 | const displaychat = "minecraft:display_chat_event"; 3 | // Setup which events to listen for 4 | clientSystem.initialize = function () { 5 | // set up your listenToEvents and register client-side components here. 6 | this.listenForEvent("minecraft:client_entered_world", (eventData) => this.clientJoined(eventData)); 7 | } 8 | 9 | 10 | clientSystem.clientJoined = function(eventData){ 11 | this.broadcastEvent(displaychat, "§aLoaded..."); 12 | } 13 | // per-tick updates 14 | clientSystem.update = function() { 15 | // Any logic that needs to happen every tick on the client. 16 | } -------------------------------------------------------------------------------- /Episode-02/server/server.js: -------------------------------------------------------------------------------- 1 | var serverSystem = server.registerSystem(0, 0); 2 | const displaychat = "minecraft:display_chat_event"; 3 | 4 | // Setup which events to listen for 5 | serverSystem.initialize = function () { 6 | // set up your listenToEvents and register server-side components here. 7 | this.listenForEvent("minecraft:player_attacked_actor", (eventData) => this.spawnParticle(eventData)); 8 | } 9 | 10 | // per-tick updates 11 | serverSystem.update = function() { 12 | // Any logic that needs to happen every tick on the server. 13 | } 14 | 15 | serverSystem.spawnParticle = function(eventData){ 16 | 17 | const entity = eventData.attacked_entity; 18 | var entityPos = this.getComponent(entity, "minecraft:position"); 19 | var customParticle = { 20 | 'effect' : "minecraft:mobflame_emitter", 21 | 'dimension' : "overworld", 22 | 'position' : {x : entityPos.x, y : entityPos.y , z : entityPos.z } 23 | }; 24 | this.broadcastEvent("minecraft:spawn_particle_in_world", customParticle); 25 | this.broadcastEvent(displaychat, "§6Particle effect spawned at entity location."); 26 | } -------------------------------------------------------------------------------- /Episode-03/client/client.js: -------------------------------------------------------------------------------- 1 | let clientSystem = client.registerSystem(0, 0); 2 | const displaychat = "minecraft:display_chat_event"; 3 | // Setup which events to listen for 4 | clientSystem.initialize = function () { 5 | // set up your listenToEvents and register client-side components here. 6 | this.listenForEvent("minecraft:client_entered_world", (eventData) => this.clientJoined(eventData)); 7 | } 8 | 9 | 10 | clientSystem.clientJoined = function(eventData){ 11 | this.broadcastEvent(displaychat, "§aLoaded..."); 12 | } 13 | // per-tick updates 14 | clientSystem.update = function() { 15 | // Any logic that needs to happen every tick on the client. 16 | } -------------------------------------------------------------------------------- /Episode-03/server/server.js: -------------------------------------------------------------------------------- 1 | let serverSystem = server.registerSystem(0, 0); 2 | const displaychat = "minecraft:display_chat_event"; 3 | let customZombie; 4 | let id; 5 | // Setup which events to listen for 6 | serverSystem.initialize = function () { 7 | // set up your listenToEvents and register server-side components here. 8 | this.listenForEvent("minecraft:player_attacked_actor", (eventData) => this.spawnEntity(eventData)) 9 | this.listenForEvent("minecraft:entity_death", (eventData) => this.onEntityDeath(eventData)) 10 | } 11 | 12 | // per-tick updates 13 | serverSystem.update = function() { 14 | // Any logic that needs to happen every tick on the server. 15 | } 16 | 17 | serverSystem.onEntityDeath = function(eventData){ 18 | let entity = eventData.entity 19 | if(id == entity.id){ 20 | this.broadcastEvent(displaychat, "§6You have slain your custom entity. A new one may spawn!") 21 | customZombie = null 22 | id = null 23 | } 24 | 25 | } 26 | 27 | serverSystem.spawnEntity = function(eventData){ 28 | if(customZombie == null){ 29 | customZombie = this.createEntity("entity", "minecraft:zombie") 30 | id = customZombie.id 31 | let zombieName = this.createComponent(customZombie, "minecraft:nameable") 32 | zombieName.alwaysShow = true 33 | zombieName.name = "§cScary Zombie" 34 | this.applyComponentChanges(customZombie, zombieName) 35 | this.broadcastEvent(displaychat, `§aA custom zombie has spawned with id: §2${customZombie.id}`) 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Minecraft-BedRock-Scripting-Tutorial 2 | The Minecraft Script Engine uses the JavaScript language. 3 | You can write JavaScript scripts and bundle them with Behavior Packs to listen and respond to game events, get and modify data in components that entities have, and affect different parts of the game. 4 | --------------------------------------------------------------------------------