Skip to content

Instantly share code, notes, and snippets.

@lukeeey
Last active October 27, 2018 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeeey/fee381de5b1d4696e595e51446360773 to your computer and use it in GitHub Desktop.
Save lukeeey/fee381de5b1d4696e595e51446360773 to your computer and use it in GitHub Desktop.
An example of what i would like to see in the Minecraft: Bedrock scripting api

An example of what i would like to be part of the Scripting API in Minecraft: Bedrock Edition.

Multi-file support as well, please. I dont want to make a 2000 line server mod, thanks.

// PLEASE add this. I love OOP and it will encourage more developers to accept the defeat of not using C# and instead using javascript.
// I dont know if theres currently a way to create a new block, but i would encourage you, Mojang, to make it **this** way.
class CustomBlock extends minecraft.Block {
constructor() {
super('minecraft:custom_block');
}
getName() {
return 'Custom Block';
}
onInteract(world, pos, player) {
if(world.name == 'LuckyBlockArena') {
player.sendChat(`You clicked the block at ${pos.x}, ${pos.y}, ${pos.z}!`);
}
}
}
class CustomEntity extends minecraft.Entity {
constructor() {
super('minecraft:custom_entity');
}
getName() {
return 'Custom Entity';
}
onDeath(world, pos, entity) {
if(world.name == 'LuckyBlockArena') {
world.broadcastChat(entity.name + ' died!');
}
}
}
// Here are some examples of what the world and player objects (passed to onInteract() in CustomBlock.js) could look like.
// Maybe some of this could be replaced with the component system or by allowing us to read the NBT instead.
// I'm just a fan of a nice API so i thought i'd give an example
world {
name: 'LuckyBlockArena',
dimension: 'overworld',
gamerules: {
doDaylightCycle: true,
commandBlockOutput: false
},
spawnpoint: {
x: 9, y: 9, z: 9
},
difficulty: 'peaceful',
defaultGamemode: 'survival'
}
// And the player stuff
player {
sendChat(string): function,
setPosition(x, y, z): function,
position: {
x: 9, y: 9, z: 9
},
name: string,
uuid: string
}
// I know this will probably never make its way into the API, but it was worth a try.
var system = client.registerSystem(0, 0);
system.initialize = function() { // cant this be onInitialize, to clarify the fact its an event?
this.registerBlock(new CustomBlock());
this.registerEntity(new CustomEntity());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment