mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Remove StructureArgument to work around vanilla issue, clean up custom arguments
This commit is contained in:
1 parent
5efa373d7f
commit
f777aba227
5 files changed
+33
-131
No files matched your search
@@ -30,6 +30,7 @@ import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.server.command.ConfigCommand;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
import net.minecraftforge.server.command.ForgeArguments;
|
||||
import net.minecraftforge.server.command.ForgeCommand;
|
||||
import net.minecraftforge.server.command.ModIdArgument;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
@@ -133,8 +134,7 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook
|
||||
VersionChecker.startVersionCheck();
|
||||
}
|
||||
|
||||
//ArgumentTypes.register("forge:enum", EnumArgument.class, new EnumArgument.Serialzier()); //This can't register, it breaks vanilla clients. As the packet serailzier doesn't discard unknown data
|
||||
ArgumentTypes.register("forge:modid", ModIdArgument.class, new ArgumentSerializer<>(ModIdArgument::modIdArgument));
|
||||
ForgeArguments.register();
|
||||
}
|
||||
|
||||
public void serverStarting(FMLServerStartingEvent evt)
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package net.minecraftforge.common.command;
|
||||
|
||||
import com.google.common.collect.Streams;
|
||||
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.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.ISuggestionProvider;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.ResourceLocationException;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.gen.feature.structure.Structure;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
public class StructureArgument implements ArgumentType<ResourceLocation>
|
||||
{
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("minecraft:village", "Mansion");
|
||||
public static final DynamicCommandExceptionType STRUCTURE_UNKNOWN_TYPE = new DynamicCommandExceptionType((p_211367_0_) ->
|
||||
{
|
||||
return new TranslationTextComponent("structure.notFound", p_211367_0_);
|
||||
});
|
||||
|
||||
public static StructureArgument structure()
|
||||
{
|
||||
return new StructureArgument();
|
||||
}
|
||||
|
||||
public static SuggestionProvider<CommandSource> suggestions()
|
||||
{
|
||||
return (ctx, sb) -> ISuggestionProvider.suggest(Streams.concat(
|
||||
GameData.getStructureMap().values().stream().map(Structure::getStructureName),
|
||||
GameData.getStructureFeatures().keySet().stream().map(ResourceLocation::toString)), sb);
|
||||
}
|
||||
|
||||
public static ResourceLocation getStructureId(CommandContext<CommandSource> context, String name) throws CommandSyntaxException
|
||||
{
|
||||
return checkIfStructureExists(context.getArgument(name, ResourceLocation.class));
|
||||
}
|
||||
|
||||
private static ResourceLocation checkIfStructureExists(ResourceLocation id) throws CommandSyntaxException
|
||||
{
|
||||
if (id.getNamespace().equals("minecraft"))
|
||||
{
|
||||
// Special case vanilla hardcoded names, for vanilla compat
|
||||
Structure<?> structure = GameData.getStructureMap().values().stream()
|
||||
.filter(s -> s.getStructureName().equalsIgnoreCase(id.getPath()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (structure != null)
|
||||
return id;
|
||||
}
|
||||
GameData.getStructureFeatures().getValue(id).orElseThrow(() -> STRUCTURE_UNKNOWN_TYPE.create(id));
|
||||
return id;
|
||||
}
|
||||
|
||||
private static final SimpleCommandExceptionType INVALID_EXCEPTION = new SimpleCommandExceptionType(new TranslationTextComponent("argument.id.invalid"));
|
||||
|
||||
public ResourceLocation parse(StringReader reader) throws CommandSyntaxException
|
||||
{
|
||||
// Logic taken from ResourceLocation.read, but made case-insensitive
|
||||
int cursor = reader.getCursor();
|
||||
try
|
||||
{
|
||||
while (reader.canRead() && ResourceLocation.isValidPathCharacter(Character.toLowerCase(reader.peek())))
|
||||
{
|
||||
reader.skip();
|
||||
}
|
||||
|
||||
String s = reader.getString().substring(cursor, reader.getCursor());
|
||||
ResourceLocation rl = new ResourceLocation(s.toLowerCase(Locale.ROOT));
|
||||
return checkIfStructureExists(rl);
|
||||
}
|
||||
catch (ResourceLocationException e)
|
||||
{
|
||||
reader.setCursor(cursor);
|
||||
throw INVALID_EXCEPTION.createWithContext(reader);
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<String> getExamples()
|
||||
{
|
||||
return EXAMPLES;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
public class ForgeArguments
|
||||
{
|
||||
public static void register()
|
||||
{
|
||||
/*
|
||||
* We can't actually add any of these, because vanilla clients will choke on unknown argument types
|
||||
* So our custom arguments will not validate client-side, but they do still work
|
||||
ArgumentTypes.register("forge:enum", EnumArgument.class, new EnumArgument.Serializer());
|
||||
ArgumentTypes.register("forge:modid", ModIdArgument.class, new ArgumentSerializer<>(ModIdArgument::modIdArgument));
|
||||
ArgumentTypes.register("forge:structure_type", StructureArgument.class, new ArgumentSerializer<>(StructureArgument::structure));
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -19,16 +19,14 @@
|
||||
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
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.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import net.minecraft.command.ISuggestionProvider;
|
||||
import net.minecraft.command.arguments.IArgumentSerializer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
|
||||
@@ -58,22 +56,4 @@ public class ModIdArgument implements ArgumentType<String> {
|
||||
public Collection<String> getExamples() {
|
||||
return EXAMPLES;
|
||||
}
|
||||
|
||||
public static class Serialzier implements IArgumentSerializer<ModIdArgument> {
|
||||
|
||||
@Override
|
||||
public void write(ModIdArgument argument, PacketBuffer buffer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModIdArgument read(PacketBuffer buffer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ModIdArgument argument, JsonObject json) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user