Skip to content

Seface-Studios/minecraft-spawn-egg-preview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minecraft Spawn Egg Preview

A very simple REST API for Minecraft Spawn Egg preview.

Note

Probably in the future the same logic will be applied to other game elements that use a customizable color matrix (leaves, water etc).

Endpoints

GET /<base_color>/<overlay_color>

Result DBCDC2/74A332 Ignore the image size for this example, we are usin a 32px image on the README just to be more simple to visualize.

Returns the full preview of a Spawn Egg. # is not parsed on the URL! Colors must be F0F0F0 instead of #F0F0F0. This URL will use the default image size of 128px.


GET /<size>/<base_color>/<overlay_color>

Result F6B201/37C3F2 Ignore the image size for this example, we are usin a 32px image on the README just to be more simple to visualize.

Same as the first endpoint but with specific size. Allowed Sizes: [16, 32, 64, 128, 256, 512]

Any other value will have the following formula applied:

$$ \text{x}(\text{size}) = \min\left(\max\left(16, 2^{\lceil \log_2(\text{size}) \rceil}\right), 512\right) $$

Passing the ?data=<boolean> argument

When passing this argument into any endpoint the API will return the JSON data of the Spawn Egg. The response will looks like this:

// http://localhost:5000/64/8073FF/D4FF7A?data=true

{
  "base64": "data:image/png;base64,...",
  "base_color": {
    "hex": "#8073FF",
    "matrix": [0.50..., 0, 0, 0, 0, 0, 0.45..., 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]
  },
  "overlay_color": {
    "hex": "#D4FF7A",
    "matrix": [0.83..., 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.47..., 0, 0, 0, 0, 0, 1, 0]
  },
  "size": 64,
  "filename": "64px-59c8477-c3fa-5bb6-a6ef-b1db4f521e6e.png",
  "uuid": "59c8477-c3fa-5bb6-a6ef-b1db4f521e6e"
}

Roadmap

  • A Visual Studio Code extension
    • The idea is create a side-project using this API to preview the Spawn Egg when hover at spawn_egg property from a client-side entity file of Minecraft Bedrock Edition resource pack. Can be util for Add-Ons developers that want to be sure to not repeat colors or put similar colos on base and overlay.

Logic

The main idea from the API is get the parsed HEX Color and convert into a Color Matrix and merge with Grayscale texture of the Spawn Egg. When both images are created, the system will merge into one and return the buffer as response.

Hexadecimal Color Color Matrix Preview
Spawn Egg Base #8073FF [0.5..., 0, 0, 0, 0, 0, 0.45.., 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] Spawn Egg Base Preview
Spawn Egg Overlay #D4FF7A [0.83..., 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.48..., 0, 0, 0, 0, 0, 1, 0] Spawn Egg Base Preview
ㅤㅤㅤ ㅤㅤㅤ ㅤㅤㅤ ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ
Spawn Egg Spawn Egg Preview

Similarity with the Spawn Egg generated by the game: 99.93%

Local Instalation

  • Download Python3
  • Create a new virtual environment and active
    $ py -m venv .venv && .\.venv\Scripts\activate
  • Install the dependencies
    $ py -m pip install -r requirements.txt
  • Execute the app
    $ py .\api\app.py

Releases

No releases published