Skip to content

Commit

Permalink
Add blocks to palette
Browse files Browse the repository at this point in the history
  • Loading branch information
mircokroon committed Mar 18, 2023
1 parent 323895f commit 1fb60e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/game/data/chunk/palette/BlockState.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public String toString() {
return "BlockState{" +
"name='" + name + '\'' +
", id=" + id +
", properties=" + properties +
// ", properties=" + properties +
'}';
}
}
5 changes: 5 additions & 0 deletions src/main/java/game/data/chunk/palette/GlobalPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public int getStateId(SpecificTag nbt) {
}

public void addBlockState(BlockState state) {
// skip existing states, these should be the same but might have different names
if (states.containsKey(state.getNumericId())) {
return;
}

states.put(state.getNumericId(), state);
nameStates.put(new BlockStateIdentifier(state.getName(), state.getProperties()), state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import game.data.WorldManager;
import game.data.chunk.Chunk;
import game.data.chunk.palette.GlobalPaletteProvider;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -80,6 +81,10 @@ private void handleRegistry(DataTypeProvider provider) {
registry.addId(provider.readString(), provider.readVarInt());
}

if (name.equals("minecraft:blocks")) {
registry.registerBlocks();
}

int numAliases = provider.readVarInt();
for (int i = 0; i < numAliases; i++) {
registry.addAlias(provider.readString());
Expand Down Expand Up @@ -139,4 +144,13 @@ public Tag toNbt() {

return tag;
}

/**
* Add blocks to the global palette
*/
public void registerBlocks() {
// since blockstates in 1.12.2 have half a byte of data at the end, we need to shift the
// blockstates we register to the global palette for the minimap to remain correct(ish)
ids.forEach(pair -> GlobalPaletteProvider.registerBlock(pair.getKey(), pair.getValue() << 4));
}
}

0 comments on commit 1fb60e7

Please sign in to comment.