mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-09 05:46:26 +01:00
5ff194cbc8
- Rename ReloadRenderersEvent to ReloadLevelRendererEvent - Rename Engine#renderCrumblingInstances to #renderCrumbling - Make all mixin classes package-private and abstract - Make all event classes final and document which event bus they are posted on - Add EndClientResourceReloadEvent - Replace some usages of ReloadLevelRendererEvent with EndClientResourceReloadEvent, including ModelHolder and ModelCache - Always add all existing entities from world to VisualizationManagerImpl on construction if level is instanceof Level - Delete all VisualizationManagerImpls on resource reload - Improve MemoryBlock utility - Add MemoryBlock#copyTo(MemoryBlock) - Remove MemoryBlock#reallocTracked and make #realloc create a tracked block if and only if the existing block is tracked - Fix reallocating a debug memory block creating a regular memory block - Change BakedModelBufferer to only invoke the result consumer if the data is not empty - Improve BackendArgument - Fix classloading BackendArgument early causing it to return incomplete suggestions - Always allow specifying namespace, allow matching only by path, and always display suggested IDs with namespace
59 lines
2.1 KiB
Java
59 lines
2.1 KiB
Java
package com.jozufozu.flywheel.config;
|
|
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
import com.jozufozu.flywheel.api.backend.Backend;
|
|
import com.jozufozu.flywheel.lib.util.ResourceUtil;
|
|
import com.mojang.brigadier.StringReader;
|
|
import com.mojang.brigadier.arguments.ArgumentType;
|
|
import com.mojang.brigadier.context.CommandContext;
|
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
|
import com.mojang.brigadier.suggestion.Suggestions;
|
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
|
|
|
import net.minecraft.commands.SharedSuggestionProvider;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
public class BackendArgument implements ArgumentType<Backend> {
|
|
private static final List<String> EXAMPLES = List.of("off", "flywheel:off", "instancing");
|
|
|
|
private static final DynamicCommandExceptionType ERROR_UNKNOWN_BACKEND = new DynamicCommandExceptionType(arg -> {
|
|
return Component.literal("Unknown backend '" + arg + "'");
|
|
});
|
|
|
|
public static final BackendArgument INSTANCE = new BackendArgument();
|
|
|
|
@Override
|
|
public Backend parse(StringReader reader) throws CommandSyntaxException {
|
|
ResourceLocation id = ResourceUtil.readFlywheelDefault(reader);
|
|
Backend backend = Backend.REGISTRY.get(id);
|
|
|
|
if (backend == null) {
|
|
throw ERROR_UNKNOWN_BACKEND.createWithContext(reader, id.toString());
|
|
}
|
|
|
|
return backend;
|
|
}
|
|
|
|
@Override
|
|
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
|
String input = builder.getRemaining().toLowerCase(Locale.ROOT);
|
|
for (ResourceLocation id : Backend.REGISTRY.getAllIds()) {
|
|
String idStr = id.toString();
|
|
if (SharedSuggestionProvider.matchesSubStr(input, idStr) || SharedSuggestionProvider.matchesSubStr(input, id.getPath())) {
|
|
builder.suggest(idStr);
|
|
}
|
|
}
|
|
return builder.buildFuture();
|
|
}
|
|
|
|
@Override
|
|
public Collection<String> getExamples() {
|
|
return EXAMPLES;
|
|
}
|
|
}
|