Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Nov 26, 2023
1 parent 0406139 commit 47a9498
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 25 deletions.
109 changes: 99 additions & 10 deletions src/main/java/net/krlite/rei_collapsible_entries/REIClientPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.shedaniel.rei.api.common.entry.type.EntryType;
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import net.minecraft.block.Blocks;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -153,7 +154,7 @@ public void registerCollapsibleEntries(CollapsibleEntryRegistry registry) {
C.id("glass_blocks"),
tag(C.id("glass_blocks")),
entryStack ->
entryStack.getTagsFor().anyMatch(tag -> tag.equals(C.asItemTag("glass")))
entryStack.getTagsFor().anyMatch(tag -> tag.equals(C.asItemTag("glass_blocks")))
|| (entryStack.getType() != VanillaEntryTypes.FLUID
&& (TC.checkContains(entryStack.getIdentifier()) || AE2.checkContains(entryStack.getIdentifier()))
&& entryStack.getIdentifier().getPath().endsWith("glass")) // Special case for glass in TC & AE2
Expand Down Expand Up @@ -181,9 +182,46 @@ public void registerCollapsibleEntries(CollapsibleEntryRegistry registry) {
"signs", "hanging_signs", "leaves", "logs", "planks",
"stairs", "slabs", "doors", "trapdoors", "fence_gates",
"boats", "walls", "fences", "trim_templates",
"decorated_pot_sherds"
"decorated_pot_sherds", "swords", "shovels", "pickaxes",
"axes", "hoes", "small_flowers", "tall_flowers", "rails"
}).forEach(tag -> registerCollapsibleEntryFromTag(registry, MC, tag));

// Tools according to materials
{
final String[] MATERIALS = new String[]{ "wooden", "stone", "golden", "iron", "diamond", "netherite" };
final String[] TOOLS = new String[]{ "sword", "shovel", "pickaxe", "axe", "hoe" };

Arrays.stream(MATERIALS).forEach(material -> registry.group(
MC.id("tools", material),
col(MC.id("tools", material)),
entryStack -> MC.checkContains(entryStack.getIdentifier())
&& Arrays.stream(TOOLS)
.map(p -> joinAll(material, p))
.anyMatch(p -> entryStack.getIdentifier().getPath().equals(p))
));
}

// Armors according to materials & types
{
final String[] MATERIALS = new String[]{"leather", "chainmail", "iron", "diamond", "golden", "netherite"};
final String[] ARMORS = new String[]{"helmet", "chestplate", "leggings", "boots"};

Arrays.stream(MATERIALS).forEach(material -> registry.group(
MC.id("armors", material),
col(MC.id("armors", material)),
entryStack -> MC.checkContains(entryStack.getIdentifier())
&& Arrays.stream(ARMORS)
.map(p -> joinAll(material, p))
.anyMatch(p -> entryStack.getIdentifier().getPath().equals(p))
));

Arrays.stream(ARMORS).forEach(type -> registry.group(
MC.id("armor_types", type),
col(MC.id("armor_types", type)),
predicateTrailingIds(MC.id(type))
));
}

// Enchanted books
registry.group(
MC.id("enchanted_books"),
Expand All @@ -205,20 +243,33 @@ public void registerCollapsibleEntries(CollapsibleEntryRegistry registry) {
predicateIds(Registries.ITEM.getId(Items.PAINTING))
);

// Goat Horns
// Goat horns
registry.group(
MC.id("goat_horns"),
col(MC.id("goat_horns")),
predicateIds(Registries.ITEM.getId(Items.GOAT_HORN))
);

// Goat Horns
// Suspicious stews
registry.group(
MC.id("suspicious_stews"),
col(MC.id("suspicious_stews")),
predicateIds(Registries.ITEM.getId(Items.SUSPICIOUS_STEW))
);

// Banner patterns
registry.group(
MC.id("banner_patterns"),
col(MC.id("banner_patterns")),
predicateTrailingIds(MC.id("banner_pattern"))
);

// Horse armors
registry.group(
MC.id("horse_armors"),
col(MC.id("horse_armors")),
predicateTrailingIds(MC.id("horse_armor"))
);

// Potions
Arrays.stream(new String[]{ null, "lingering", "splash" }).forEach(prefix -> registry.group(
Expand All @@ -229,8 +280,8 @@ public void registerCollapsibleEntries(CollapsibleEntryRegistry registry) {

// Colored blocks
Arrays.stream(new String[]{
"terracotta", "glazed_terracotta",
"concrete", "concrete_powder"
"terracotta", "glazed_terracotta", "concrete",
"concrete_powder", "wool", "carpet"
}).forEach(type -> registry.group(
MC.id("blocks", type),
col(MC.id("blocks", type)),
Expand All @@ -239,12 +290,50 @@ public void registerCollapsibleEntries(CollapsibleEntryRegistry registry) {
.collect(Collectors.toList()))
));

// Miscellaneous
// Corals
{
final String[] TYPES = new String[]{ "tube", "brain", "bubble", "fire", "horn" };
final String[] PREFIXES = new String[]{ null, "dead" };
final String[] POSTFIXES = new String[]{ "coral", "coral_fan", "coral_block" };

Arrays.stream(POSTFIXES).forEach(postfix -> registry.group(
MC.id("blocks", postfix),
col(MC.id("blocks", postfix)),
entryStack -> MC.checkContains(entryStack.getIdentifier())
&& Arrays.stream(TYPES)
.map(p -> joinAll(p, postfix))
.flatMap(p -> Arrays.stream(PREFIXES)
.map(pp -> joinAll(pp, p)))
.anyMatch(p -> entryStack.getIdentifier().getPath().equals(p))
));
}

// Skulls and heads
{
final String[] TYPES = new String[]{ "skull", "head" };

registry.group(
MC.id("blocks", "skull_and_head"),
col(MC.id("blocks", "skull_and_head")),
entryStack -> MC.checkContains(entryStack.getIdentifier())
&& Arrays.stream(TYPES)
.anyMatch(p -> entryStack.getIdentifier().getPath().endsWith(p))
);
}

// Lights
registry.group(
MC.id("blocks", "light"),
col(MC.id("blocks", "light")),
predicateTrailingIds(Registries.BLOCK.getId(Blocks.LIGHT))
);

// Blocks
Arrays.stream(new String[]{
"button", "pressure_plate", "banner_pattern"
"button", "pressure_plate", "copper", "sapling"
}).forEach(type -> registry.group(
MC.id("misc", type),
col(MC.id("misc", type)),
MC.id("blocks", type),
col(MC.id("blocks", type)),
predicateTrailingIds(MC.id(type))
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package net.krlite.rei_collapsible_entries;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.krlite.rei_collapsible_entries.client.listener.ClientCommandRegistryListener;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
Expand All @@ -18,6 +21,7 @@ public class REICollapsibleEntries implements ClientModInitializer {

@Override
public void onInitializeClient() {
ClientCommandRegistrationCallback.EVENT.register(new ClientCommandRegistryListener());
}

enum ModEntry {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.krlite.rei_collapsible_entries.client.command;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.krlite.rei_collapsible_entries.REICollapsibleEntries;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;

public class HeldItemInfoCommand implements Command<FabricClientCommandSource> {
@Override
@SuppressWarnings("all")
public int run(CommandContext<FabricClientCommandSource> context) {
ItemStack stack = context.getSource().getPlayer().getMainHandStack();
Identifier itemId = Registries.ITEM.getId(stack.getItem());

if (stack.isOf(Items.AIR))
return 0;

// Tags
if (stack.getItem().getRegistryEntry().streamTags().findAny().isPresent())
context.getSource().sendFeedback(streamTags(stack));

return SINGLE_SUCCESS;
}

@SuppressWarnings("deprecation")
private Text streamTags(ItemStack stack) {
return stack.getItem().getRegistryEntry().streamTags()
.map(tag -> Text.translatable("command." + REICollapsibleEntries.ID + ".held_item_info.tag_prefix")
.formatted(Formatting.GRAY, Formatting.ITALIC)
.append(Text.literal(tag.id().toString())
.styled(style -> style
.withColor(Formatting.YELLOW)
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Text.literal(tag.id().toString()).formatted(Formatting.YELLOW)
))
.withClickEvent(new ClickEvent(
ClickEvent.Action.COPY_TO_CLIPBOARD,
tag.id().toString())
))
))
.reduce((a, b) -> a.append(" ").append(b)).orElse(Text.empty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.krlite.rei_collapsible_entries.client.listener;

import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.krlite.rei_collapsible_entries.REICollapsibleEntries;
import net.krlite.rei_collapsible_entries.client.command.HeldItemInfoCommand;
import net.minecraft.command.CommandRegistryAccess;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public class ClientCommandRegistryListener implements ClientCommandRegistrationCallback {
@Override
public void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
dispatcher.register(literal(REICollapsibleEntries.ID).then(literal("i").executes(new HeldItemInfoCommand())));
}
}
50 changes: 45 additions & 5 deletions src/main/resources/assets/rei_collapsible_entries/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
"tag.minecraft.fences" : "Fences",
"tag.minecraft.trim_templates" : "Trim Templates",
"tag.minecraft.decorated_pot_sherds": "Decorated Pot Sherds",
"tag.minecraft.swords" : "Swords",
"tag.minecraft.shovels" : "Shovels",
"tag.minecraft.pickaxes" : "Pickaxes",
"tag.minecraft.axes" : "Axes",
"tag.minecraft.hoes" : "Hoes",
"tag.minecraft.small_flowers" : "Flowers",
"tag.minecraft.tall_flowers" : "Tall Flowers",
"tag.minecraft.rails" : "Rails",

"tag.catwalksinc.filled_paint_rolls": "§6Filled Paint Rollers",

Expand Down Expand Up @@ -67,18 +75,46 @@
"col.minecraft.paintings" : "Paintings",
"col.minecraft.goat_horns" : "Goat Horns",
"col.minecraft.suspicious_stews": "Suspicious Stews",
"col.minecraft.banner_patterns" : "Banner Patterns",
"col.minecraft.horse_armors" : "Horse Armors",

"col.minecraft.spawn_eggs": "Spawn Eggs",
"col.minecraft.buckets" : "Fluid Buckets",

"col.minecraft.blocks/light" : "Lights",
"col.minecraft.blocks/terracotta" : "Terracotta",
"col.minecraft.blocks/glazed_terracotta": "Glazed Terracotta",
"col.minecraft.blocks/concrete" : "Concretes",
"col.minecraft.blocks/concrete_powder" : "Concrete Powders",

"col.minecraft.misc/button" : "Buttons",
"col.minecraft.misc/pressure_plate": "Pressure Plates",
"col.minecraft.misc/banner_pattern": "Banner Patterns",
"col.minecraft.blocks/wool" : "Wools",
"col.minecraft.blocks/carpet" : "Carpets",
"col.minecraft.blocks/button" : "Buttons",
"col.minecraft.blocks/pressure_plate" : "Pressure Plates",
"col.minecraft.blocks/copper" : "Copper Blocks",
"col.minecraft.blocks/sapling" : "Saplings",
"col.minecraft.blocks/coral" : "Corals",
"col.minecraft.blocks/coral_fan" : "Coral Fans",
"col.minecraft.blocks/coral_block" : "Coral Blocks",
"col.minecraft.blocks/skull_and_head" : "Skulls and Heads",

"col.minecraft.tools/wooden" : "Wooden Tools",
"col.minecraft.tools/stone" : "Stone Tools",
"col.minecraft.tools/golden" : "Golden Tools",
"col.minecraft.tools/iron" : "Iron Tools",
"col.minecraft.tools/diamond" : "Diamond Tools",
"col.minecraft.tools/netherite": "Netherite Tools",

"col.minecraft.armors/leather" : "Leather Armors",
"col.minecraft.armors/chainmail": "Chainmail Armors",
"col.minecraft.armors/iron" : "Iron Armors",
"col.minecraft.armors/diamond" : "Diamond Armors",
"col.minecraft.armors/golden" : "Golden Armors",
"col.minecraft.armors/netherite": "Netherite Armors",

"col.minecraft.armor_types/helmet" : "Caps and Helmets",
"col.minecraft.armor_types/chestplate": "Tunics and Chestplates",
"col.minecraft.armor_types/leggings" : "Pants and Leggings",
"col.minecraft.armor_types/boots" : "Boots",

"col.minecraft.lingering_potions": "Lingering Potions",
"col.minecraft.splash_potions" : "Splash Potions",
Expand Down Expand Up @@ -163,5 +199,9 @@
"col.promenade.piles": "Piles",

"col.promenade.blocks/mushroom" : "Mushrooms",
"col.promenade.blocks/mushroom_block": "Mushroom Blocks"
"col.promenade.blocks/mushroom_block": "Mushroom Blocks",



"command.rei_collapsible_entries.held_item_info.tag_prefix": "#"
}
Loading

0 comments on commit 47a9498

Please sign in to comment.