mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-09-27 14:52:57 +02:00
Tidy BlockEntity mappings
This commit introduces a small functional interface to make the type less ungodly. Also silences the warning about referencing subclasses in the superclass, it is fine in this case, we're just storing a reference to the constructor.
This commit is contained in:
parent
fca5da42f4
commit
1d98922bb2
@ -19,7 +19,14 @@
|
|||||||
@NBTDeserializer(BlockEntity.BlockEntityDeserializer.class)
|
@NBTDeserializer(BlockEntity.BlockEntityDeserializer.class)
|
||||||
public class BlockEntity {
|
public class BlockEntity {
|
||||||
private static final BlueNBT BLUENBT = new BlueNBT();
|
private static final BlueNBT BLUENBT = new BlueNBT();
|
||||||
private static final Map<String, Function<Map<String, Object>, ? extends BlockEntity>> ID_MAPPING = Map.of(
|
|
||||||
|
@FunctionalInterface
|
||||||
|
private interface BlockEntityInitializer {
|
||||||
|
BlockEntity create(Map<String, Object> data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("StaticInitializerReferencesSubClass")
|
||||||
|
private static final Map<String, BlockEntityInitializer> ID_MAPPING = Map.of(
|
||||||
"minecraft:sign", SignBlockEntity::new,
|
"minecraft:sign", SignBlockEntity::new,
|
||||||
"minecraft:skull", SkullBlockEntity::new,
|
"minecraft:skull", SkullBlockEntity::new,
|
||||||
"minecraft:banner", BannerBlockEntity::new
|
"minecraft:banner", BannerBlockEntity::new
|
||||||
@ -92,10 +99,10 @@ public BlockEntity read(NBTReader reader) throws IOException {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Function<Map<String, Object>, ? extends BlockEntity> instance = ID_MAPPING.getOrDefault(id, BlockEntity::new);
|
BlockEntityInitializer instance = ID_MAPPING.getOrDefault(id, BlockEntity::new);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return instance.apply(data);
|
return instance.create(data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.global.logError("Failed to instantiate BlockEntity instance!", e);
|
Logger.global.logError("Failed to instantiate BlockEntity instance!", e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user