Skip to content

Commit

Permalink
Merge pull request #247 from GameModsBR/PN-95
Browse files Browse the repository at this point in the history
Makes the server log when it finds an unknown BlockId:Meta combination
  • Loading branch information
joserobjr committed May 10, 2020
2 parents bfd7515 + 2190b33 commit 1742ef8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Click the link above to see the future.
- [#246] Anvil checking the enchantment table property instead of the enchantment id
- [#246] Compatibility rules for unbreaking, fortune, mending, riptide, loyalty and channeling enchantments.

### Changed
- [#247] Invalid BlockId:Meta combinations now log an error when found. It logs only once.

## [1.2.0.1-PN] - 2020-05-08 ([Check the milestone](https://github.com/GameModsBR/PowerNukkit/milestone/8?closed=1))
Fixes several anvil issues.

Expand Down Expand Up @@ -220,3 +223,4 @@ Fixes several anvil issues.
[#240]: https://github.com/GameModsBR/PowerNukkit/issues/240
[#243]: https://github.com/GameModsBR/PowerNukkit/issues/243
[#246]: https://github.com/GameModsBR/PowerNukkit/issues/246
[#247]: https://github.com/GameModsBR/PowerNukkit/pull/247
11 changes: 5 additions & 6 deletions src/main/java/cn/nukkit/level/GlobalBlockPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import cn.nukkit.nbt.NBTIO;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.ListTag;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.*;

import java.io.BufferedInputStream;
import java.io.IOException;
Expand All @@ -24,6 +21,7 @@ public class GlobalBlockPalette {
private static final Map<String, Integer> stringToLegacyId = new HashMap<>();
private static final AtomicInteger runtimeIdAllocator = new AtomicInteger(0);
public static final byte[] BLOCK_PALETTE;
private static final Int2ObjectMap<IntSet> unknownRuntimeIds = new Int2ObjectOpenHashMap<>();

static {
legacyToRuntimeId.defaultReturnValue(-1);
Expand Down Expand Up @@ -105,9 +103,10 @@ public static int getOrCreateRuntimeId(int id, int meta) {
int legacyId = id << 6 | meta;
int runtimeId = legacyToRuntimeId.get(legacyId);
if (runtimeId == -1) {
//runtimeId = registerMapping(runtimeIdAllocator.incrementAndGet(), legacyId);
runtimeId = legacyToRuntimeId.get(248 << 6);
//throw new NoSuchElementException("Unmapped block registered id:" + id + " meta:" + meta);
if (unknownRuntimeIds.computeIfAbsent(id, k -> new IntOpenHashSet(5)).add(meta)) {
Server.getInstance().getLogger().error("Found an unknown BlockId:Meta combination: "+id+":"+meta+", replacing with an \"UPDATE!\" block.");
}
}
return runtimeId;
}
Expand Down

0 comments on commit 1742ef8

Please sign in to comment.