Skip to content

Commit

Permalink
Fixed upgrade command not actually working
Browse files Browse the repository at this point in the history
- Fixed UpgradeArgumentType to be of the type ResourceLocation as expected by the game
  • Loading branch information
50ap5ud5 committed Dec 27, 2023
1 parent ab66408 commit 6f488fc
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
import whocraft.tardis_refined.common.capability.upgrades.Upgrades;
import whocraft.tardis_refined.common.tardis.TardisDesktops;
import whocraft.tardis_refined.common.tardis.themes.DesktopTheme;
import whocraft.tardis_refined.common.tardis.themes.ShellTheme;
import whocraft.tardis_refined.constants.ModMessages;

import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class UpgradeArgumentType implements ArgumentType<Upgrade> {
public class UpgradeArgumentType implements ArgumentType<ResourceLocation> {

private static final Collection<String> EXAMPLES = Stream.of(Upgrades.COORDINATE_INPUT).map((upgrade) -> {
return upgrade != null ? upgrade.getId().toString() : "";
Expand All @@ -34,13 +35,9 @@ public static UpgradeArgumentType upgradeArgumentType() {
}

@Override
public Upgrade parse(StringReader reader) throws CommandSyntaxException {
ResourceLocation location = ResourceLocation.read(reader);
Upgrade upgrade = Upgrades.UPGRADE_DEFERRED_REGISTRY.getRegistry().get(location);
if (upgrade != null) {
return upgrade;
}
throw INVALID_UPGRADE_EXCEPTION.create(location); }
public ResourceLocation parse(StringReader reader) throws CommandSyntaxException {
return ResourceLocation.read(reader);
}

@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
Expand All @@ -60,4 +57,12 @@ public static Upgrade getUpgrade(CommandContext<CommandSourceStack> context, Str
else
return upgrade;
}

public static ResourceLocation getUpgradeId(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
ResourceLocation resourcelocation = context.getArgument(name, ResourceLocation.class);
if (Upgrades.UPGRADE_REGISTRY.get(resourcelocation) == null)
throw INVALID_UPGRADE_EXCEPTION.create(resourcelocation);
else
return resourcelocation;
}
}

0 comments on commit 6f488fc

Please sign in to comment.