Git Product home page Git Product logo

beapi's People

Contributors

dependabot[bot] avatar jrcarl624 avatar nobu-sh avatar pmk744 avatar xfallen54x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

beapi's Issues

Proposal: Condensed Binary

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

Idea: Configuration

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.

Content Log is spammed when a player leaves the world


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;
image
Other times it's "Failed to get property 'getEntitiesFromViewVector'"

To Reproduce

  1. Join a world with BeAPI and GameTest Framework enabled
  2. Get an alt or another player to join the world
  3. Get the alt or other player to leave
  4. See the content log

Expected behavior
The content log shouldn't be spammed

It doesn't work for me

Put the API in a world and I activated all the experimental options and it did not work

TODO: Runtime ID BigInt

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.

Idea: Bundled on build rather than sending prebuilt bundles to user

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

  1. There could be a light and main version as the light could be prebundled.
  2. There could be a rebuild-beapi command in the create-bapi module. This would reduce pack development build times while still allowing for easy testing and configuration. As when you change your config it would just have to be rebuilt.
  3. If there is an option for files to be accessible from outside a mjs file that would work too, as I thought to use a config file in the root dir. ie beapi.config.js

Idea: API Extensions

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.

Database Errors


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
image
The log 1 doesn't apply as it was for debug purposes.
Additional context
Working on the project for IDEA, Plugin IPC Related

Help us translate the BeAPI website

Last updated: 4/2/2021

Help us translate the BeAPI website

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.

Roadmap before translation ready

  • Possible CLI translations via os locale 1
  • Register BeAPI for Crowdin open-source plan 2
  • Integrate Crowdin with Docusaurus i18n 3
  • Spend countless hours blacklisting mdx keys in Crowdin ;-;
  • Reach out to other communities to help translate :)

Translation process

  • Optionally get familiar with the Docusaurus i18n support
  • Ensure your language is also translated for the CLI (Prioritize CLI translations first)
  • Sign-up on Crowdin and join the BeAPI project
  • Get familiar with the Crowdin translation UI, as you will need to use it to translate JSON and Markdown files
  • Ask for your locale to be enabled on Crowdin (if not already enabled)
  • Translate the content

More info will be made available once roadmap is complete!

Footnotes

  1. Example of getting OS locale through node:

    const env = process.env;
    const language = env.LANG || env.LANGUAGE || env.LC_ALL || env.LC_MESSAGES;
    
  2. Crowdin offers a free plan for open source projects, read more here.

  3. Implementation documentation located here.

Idea: Plugin IPC Related

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

getTags() only returns the second letter of the tags of an entity


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:

  1. Use a for loop for a getTags() array
  2. Give yourself a few random tags
  3. Attempt to print each tag
  4. Observe only the second letter of each tag is outputted

Expected behavior
Every tag should have their whole name and text displayed

Screenshots
The last line is after running /tag @s list
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.