mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-21 15:41:38 +01:00
Add dummy block handler
This commit is contained in:
parent
74073f13b5
commit
3c04da9ae9
@ -154,10 +154,10 @@ public class AnvilLoader implements IChunkLoader {
|
||||
|
||||
final String tileEntityID = te.getString("id");
|
||||
if (tileEntityID != null) {
|
||||
final var handler = BLOCK_MANAGER.getHandler(tileEntityID);
|
||||
var handler = BLOCK_MANAGER.getHandler(tileEntityID);
|
||||
if (handler == null) {
|
||||
LOGGER.warn("Block {} does not have any corresponding handler, world will load anyway.", tileEntityID);
|
||||
continue;
|
||||
LOGGER.warn("Block {} does not have any corresponding handler, default to dummy.", tileEntityID);
|
||||
handler = BlockHandler.Dummy.get(tileEntityID);
|
||||
}
|
||||
block = block.withHandler(handler);
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Interface used to provide block behavior. Set with {@link Block#withHandler(BlockHandler)}.
|
||||
@ -282,4 +284,28 @@ public interface BlockHandler {
|
||||
return blockPosition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler used for loaded blocks with unknown namespace
|
||||
* in order to do not lose the information while saving, and for runtime debugging purpose.
|
||||
*/
|
||||
class Dummy implements BlockHandler {
|
||||
private static final Map<String, BlockHandler> DUMMY_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static @NotNull BlockHandler get(@NotNull String namespace) {
|
||||
return DUMMY_CACHE.computeIfAbsent(namespace, s -> new Dummy(NamespaceID.from(namespace)));
|
||||
}
|
||||
|
||||
private final NamespaceID namespaceID;
|
||||
|
||||
private Dummy(NamespaceID namespaceID) {
|
||||
this.namespaceID = namespaceID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull NamespaceID getNamespaceId() {
|
||||
return namespaceID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user