Skip to content

Instantly share code, notes, and snippets.

@Tomcc
Tomcc / client_blob_cache.md
Last active April 9, 2024 08:46
A description of the new Client Cache for server developers

Client Blob Cache

What's the Client Blob Cache

The Client Blob Cache is a new Bedrock optimization - it allows blocks and biomes to be cached on Clients to avoid resending identical chunks over and over. Chunks and biomes make up the vast majority of network traffic in a lot of common cases (eg. login, teleport or dimension switches) but at the same time, they rarely change. Allowing the Client to reuse chunks it has seen in the past can save a ton of traffic and latency!

The Client Cache is a Content Addressed Storage (a bit like git) that stores Blobs and retrieves them based on their full hashes (BlobIds). This means that the cache doesn't actually know about Chunks - in the future, we might start using it for more types of data, like skins or data driven entities.

A nice thing we get from the CAS approach is that the cache is persistent: returning players will be able to reuse content that was sent them in previous sessions or even previous sessions in different servers as long as tha

fn interpret(cpu: &mut CPU, instr: usize) unsafe {
match instr {
0x0 => {
cpu.NOP();
cpu.PC += 1;
cpu.run_cycles(4);
},
0x1 => {
cpu.LD(cpu.BC.BC, cpu.immediateU16());
cpu.PC += 3;
@Tomcc
Tomcc / runtimeid_table.json
Last active August 20, 2021 23:57
RuntimeID temporary static lookup table
[
{
"data": 0,
"id": 0,
"name": "minecraft:air",
"runtimeID": 0
},
{
"data": 0,
"id": 1,
@Tomcc
Tomcc / blockstate_protocol.md
Last active April 9, 2024 08:42
Block Changes in Beta 1.2.13

Block Storage & Network Protocol Changes

Paletted chunks & removing BlockIDs brings a few big changes to how blocks are represented. In Bedrock, Blocks used to be represented by their 8 bit ID and 4 bit data; this means that we can only represent 256 blocks and 16 variants for each block. As it happens we ran out of IDs in Update Aquatic, so we had to do something about it :)

After this change, we can represent infinite types of Blocks and infinite BlockStates, just like in Java. BlockStates are what is sent over the network as they are roughly equivalent to the old ID+data information, eg. they're all the information attached to a block.

BlockStates are serialized in two ways:

PersistentID: a PersistentID is a NBT tag containing the BlockState name and its variant number; for example

void Level::makeScene() {
auto defaultMaterial = Phys::Material{ "default" };
defaultMaterial.density = 0.1f;
addChild([&] {
int side = 100;
auto heightmap = make_shared<std::vector<float>>(makeHeightmap(side, side));
template<typename T>
class const_optional {
public:
optional(); //invalid constructor
optional(const T& obj); //valid constructor
const T& unwrap() const;
operator bool() const;
"explode":{
"base_power_min": 4,
"base_power_max": 5,
"explosion_power": 1.5,
"explosion_power_modifier": 5,
"causes_fire": false,
"remove_entity_on_explode": true
}
//hellolaunch
//First, we'll clear the terminal screen to make it look nice
CLEARSCREEN.
//schedule an update for the thrust value
SET TOTALTHRUST TO 0.
when ALT:RADAR > 1000 THEN {
LIST ENGINES in ALL_ENGINES.
{
"name": "fish.pufferfish.raw",
"id": 206,
"icon": "fish_raw_puffer_fish",
"use_animation": "eat",
"use_duration": 32,
"max_damage": 0,
"stacked_by_data": true,
"food": {
@Tomcc
Tomcc / pufferfish.json
Created October 29, 2015 10:29
pufferfish
{
"name": "fish.pufferfish.raw",
"id": 206,
"icon": "fish_raw_puffer_fish",
"use_animation": "eat",
"use_duration": 32,
"max_damage": 0,
"stacked_by_data": true,
"food": {