Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public interface InfoParser {
/**
* Priority of the parser for determining the order they are logged in chat,
* with lowest being first and highest being last.
* The is 100, and {@link com.cleanroommc.groovyscript.compat.vanilla.command.infoparser.InfoParserItem#priority()} is set to 1.
* The default for {@link com.cleanroommc.groovyscript.compat.vanilla.command.infoparser.GenericInfoParser GenericInfoParser} 100,
* and {@link com.cleanroommc.groovyscript.compat.vanilla.command.infoparser.InfoParserItem#priority() InfoParserItem.priority()} is set to 1.
*
* @return the priority of the Parser
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
package com.cleanroommc.groovyscript.api.infocommand;

import com.google.common.collect.ImmutableList;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
* To help gather information about items, blocks, the world, etc.
* GroovyScript adds {@link InfoParser}s, which will provide information to the player
* using data from an {@link InfoParserPackage}.
* <p>
* This is currently only used for commands related to {@link com.cleanroommc.groovyscript.command.BaseInfoCommand BaseInfoCommand}.
*
* @see com.cleanroommc.groovyscript.compat.vanilla.command.infoparser.StandardInfoParserRegistry StandardInfoParserRegistry
*/
public class InfoParserRegistry {

private static final List<InfoParser> INFO_PARSERS = new ArrayList<>();
private static final List<String> IDS = new ArrayList<>();

public static void addInfoParser(InfoParser command) {
INFO_PARSERS.add(command);
/**
* Register the given info parser.
*/
public static void addInfoParser(InfoParser parser) {
INFO_PARSERS.add(parser);
INFO_PARSERS.sort(Comparator.comparing(InfoParser::priority));
}

/**
* @return all registered info parsers
*/
public static List<InfoParser> getInfoParsers() {
return INFO_PARSERS.stream().sorted(Comparator.comparing(InfoParser::priority)).collect(Collectors.toList());
return ImmutableList.copyOf(INFO_PARSERS);
}

/**
* @return the ids of all registered info parsers
*/
public static List<String> getIds() {
return INFO_PARSERS.stream().sorted(Comparator.comparing(InfoParser::priority)).map(InfoParser::id).collect(Collectors.toList());
// generate the list
if (IDS.size() != INFO_PARSERS.size()) {
IDS.clear();
for (var parser : INFO_PARSERS) {
IDS.add(parser.id());
}
}
return ImmutableList.copyOf(IDS);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.cleanroommc.groovyscript.compat.mods.jei;

import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage;
import com.cleanroommc.groovyscript.compat.vanilla.command.infoparser.GenericInfoParser;
import com.cleanroommc.groovyscript.core.mixin.jei.ModRegistryAccessor;
import com.cleanroommc.groovyscript.helper.StyleConstant;
import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.oredict.OreDictionary;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -36,6 +38,11 @@ public String text(@NotNull IRecipeCategory entry, boolean colored, boolean pret
@Override
@SuppressWarnings("rawtypes")
public void parse(InfoParserPackage info) {
// only runs client-side
if (!FMLCommonHandler.instance().getSide().isClient()) {
GroovyLog.get().debug("Attempted to check the JEI tab via info parser server-side");
return;
}
if (info.getStack().isEmpty()) return;

// this gets all categories the item appears on - and there isn't any inbuilt method to get *just* catalysts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import org.jetbrains.annotations.NotNull;

import java.util.Iterator;
Expand All @@ -14,6 +15,10 @@ public class InfoParserItem extends GenericInfoParser<ItemStack> {

public static final InfoParserItem instance = new InfoParserItem();

private static void copyToClipboard(String text) {
GuiScreen.setClipboardString(text);
}

@Override
public int priority() {
return 1;
Expand All @@ -39,7 +44,8 @@ public void iterate(List<ITextComponent> messages, @NotNull Iterator<ItemStack>
if (entries.hasNext()) {
ItemStack entry = entries.next();
messages.add(information(entry, prettyNbt));
GuiScreen.setClipboardString(copyText(entry, prettyNbt));
// can only copy to clipboard if a client is running this
if (FMLCommonHandler.instance().getSide().isClient()) copyToClipboard(copyText(entry, false));
}
while (entries.hasNext()) {
messages.add(information(entries.next(), prettyNbt));
Expand Down