beapijs / beapi Goto Github PK
View Code? Open in Web Editor NEWMCBE GameTest Wrapper - Bedrock Edition API
License: MIT License
MCBE GameTest Wrapper - Bedrock Edition API
License: MIT License
Binary takes up a lot of space and scoreboard player names break after a certain threshold.
The following code example transpiles binary to and from a base 10 storage format by concurrent 0's with numbers higher than 1; In most cases saving up to 30%.
It allows for a temporary solution for storing more data in a document while chunking is being developed.
/**
* Binary "condenser" by nobu-sh
* LICENSE: https://www.apache.org/licenses/LICENSE-2.0
*
* Essentially when working with an alternative way to store
* persistent data in MCBE we decided to convert our documents
* to and from binary instead of JSON#stringify.
*
* We chose this method as it led to less issues with conflicting
* scoreboard names or data.
*
* However, not everything is perfect, binary takes up too much space
* so we decided on a new method of binary storage. It takes a tad bit
* longer to translate data however allows per a lot more storage on
* a scoreboard players name.
*
* Condensed binary essentially is a encoder/decoder that removes
* spaces and looks for zeros next to each other and uses base 10
* to overall condense the binary down a bit more.
*
* Since zeros are more common than ones in binary we are looking
* at possible total byte reductions of up to 30%!
*/
function strToBin(str: string): string {
return str.replace(/./g, char => `00${char.charCodeAt(0).toString(2)}`.slice(-8))
}
function binToStr(bin: string): string {
return bin.replace(/.{8}/g, chunk => String.fromCharCode(parseInt(chunk, 2)))
}
function binToCondensed(bin: string): string {
return bin.replace(/(0)\1+/g, m => `${m.length}`)
}
function condensedToBin(con: string): string {
return con.replace(/[2-9]/g, a => Array(+a).fill(0).join(''))
}
console.log("Normal Binary")
const bin = strToBin('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ `1234567890-=~!@#$%^&*()_+\\][;\',./<>?:"{}|')
console.log(bin.length)
const binStr = binToStr(bin)
console.log(binStr)
console.log("Condensed Binary")
const condensed = binToCondensed(bin)
console.log(condensed.length)
const uncondensed = condensedToBin(condensed)
const str = binToStr(uncondensed)
console.log(str)
Playground Link: Provided
So I talked to @PMK744 about this. So you can have data in the manifest.json for BeAPI with pack information that is passed to the api on build/bundle. As this would allow for easy pack configuration.
BeAPI Core Version
2.2.1
Create BeAPI Version
2.1.1
MCBE Version
Production 1.18.10
Describe the bug
When a player leaves a world (not the owner), the content log gets spammed with 1 of 2 messages, seemingly at random.
Sometimes it's this;
Other times it's "Failed to get property 'getEntitiesFromViewVector'"
To Reproduce
Expected behavior
The content log shouldn't be spammed
Put the API in a world and I activated all the experimental options and it did not work
Runtime id is currently a normal integer which may easily be bypassed with long runtimes thus an issue.
Create a BigInt polyfill for purejs as somepoint so this does not occur.
Documentation will be temporarily unpublished from gh pages as they document cv1 and not cv2.
OnScore - like on tag
OnDeath - for player
Is your feature request related to a problem? Please describe.
no
Describe the solution you'd like
So I've thought about how I could do the few things I was thinking of adding. Some of it all involves adding to the pack before it's built, as for bundling plugins and a config file into the bundle. I'm not sure if it's an option, I just thought I would ask.
Describe alternatives you've considered
Basically a npm module can have a setting called "BeApiExtension" where it just runs and puts the contents in a file for BeApi to read from on startup of the world or something. Where it can extend the classes before the globalthis override is run. This can be useful for adding additional command options to the base BeAPI command handler for example. As there may be modules that add two good features to the same class and you want to use them both without extra imports.
BeAPI Core Version
2.2.0
Create BeAPI Version
2.1.0
MCBE Version
Production
Describe the bug
Simply writing to the database leaves it undefined
To Reproduce
Steps to reproduce the behavior:
import { client, schema, SchemaTypes, modal, Player as beApiPlayer, DatabaseUtil, Dimension as beApiDimension, Location as beApiLocation } from 'beapi-core'
interface playerInterface {
bodyRotation: number,
dimensionName: beApiDimension,
headLocation: beApiLocation,
id: string,
isSneaking: boolean,
location: beApiLocation,
name: string,
nameTag: string,
selectedSlot: number,
velocity: Vector,
viewVector: Vector,
tags: string[],
scores: Record<string, any>,
components: Record<string, any>,
pack: Record<string, any>,
firstJoin: number,
lastJoin: number,
deaths: number,
joinCount: number,
}
const playerSchema = schema<playerInterface>({
bodyRotation: SchemaTypes.Number,
dimensionName: SchemaTypes.String,
headLocation: SchemaTypes.Map,
id: SchemaTypes.String,
isSneaking: SchemaTypes.Boolean,
location: SchemaTypes.Map,
name: SchemaTypes.String,
nameTag: SchemaTypes.String,
selectedSlot: SchemaTypes.Number,
velocity: SchemaTypes.Map,
viewVector: SchemaTypes.Map,
tags: SchemaTypes.Array,
scores: SchemaTypes.Map,
components: SchemaTypes.Map,
pack: SchemaTypes.String,
firstJoin: SchemaTypes.Number,
lastJoin: SchemaTypes.Number,
deaths: SchemaTypes.Number,
joinCount: SchemaTypes.Number
})
const joinModal = modal('d', playerSchema);
var joinDocument = joinModal.findAll({})[0];
console.log(joinDocument)
console.log(JSON.stringify(joinModal.findAll({})[0]))
// error occurs here because joinDocument is undefined
joinModal.write({
bodyRotation: 0,
dimensionName: 'overworld',
headLocation: { x: 0, y: 0, z: 0 },
id: '',
isSneaking: false,
location: { x: 0, y: 0, z: 0 },
name: '',
nameTag: '',
selectedSlot: 0,
velocity: { x: 0, y: 0, z: 0 },
viewVector: { x: 0, y: 0, z: 0 },
tags: [],
scores: {},
components: {},
pack: {},
firstJoin: 0,
lastJoin: 0,
deaths: 0,
joinCount: 1
})
console.log(JSON.stringify(joinModal.findAll({})[0]))
Expected behavior
The database to work like the example one works
database doc example ts
Screenshots
The log 1 doesn't apply as it was for debug purposes.
Additional context
Working on the project for IDEA, Plugin IPC Related
PlayerManager full on breaks when updating their nameTag.
Leaving this as a reminder for me.
Last updated: 4/2/2021
BeAPIs website uses a documentation framework called Docusaurus.
Docusaurus v2 is completely i18n localization ready. With that being said we want to translate BeAPIs website for
our non fluent English users.
Example of getting OS locale through node:
const env = process.env;
const language = env.LANG || env.LANGUAGE || env.LC_ALL || env.LC_MESSAGES;
↩
Crowdin offers a free plan for open source projects, read more here. ↩
I talked to @nobu-sh about this before but... I feel that there should be a couple of default modules that store data on a database so you can access data of offline players and see if the player exists etc. The key would be the player read only name, it could add a uuid to the player as if they change their name but that seems a bit far...
This could have a structure of
//obv the const is just for the example.
const player = {
name: "miner"
nameTag:"Miner7493"
tags:["fish","fishs"]
scores:{timer:100,deaths:4}
// this is the part I'm getting at...
pack:{
example:{
data:1
}
example2:{
data:2
}
}
On leave it would get all of the tags and scores and sync them to the database as if the player is offline it will check the database for the player for the information. Basically all the data that the player has stored or it stores only basic data like name, name tag and other stuff.
A configuration database made from the configuration of each pack on the would with options to configure each pack without having to re add the pack.
All of these should be able to be enabled/disabled in the main config. As a couple of additional default databases can allow for packs to access the same data. As it would use the packname (that is passed from the config) as a key name in the default databases. As if packs create separate databases for common things there will come a problem where each pack will add it's own database for players and that will inflate world sizes.
The only thing to really worry about is pack ipc with database saves and writes. I'm
Due to scoreboard player names having a character limit, the built in database can only store a small amount of data.
BeAPI Core Version
2.2.1
Create BeAPI Version
2.1.1
MCBE Version
Production 1.18.10
Describe the bug
When running this:
client.commands.register({
name: "ping",
description: "Test command"
}, (data) => {
data.sender.sendMessage("§ePong!")
for(const [,tags] of data.sender.getTags()) {
data.sender.sendMessage(tags)
}
})
The message that gets returned is only the second letter of each tag, ie
"a" from "rank"
"w" from "owner"
":" from "o:money"
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Every tag should have their whole name and text displayed
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.