Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Clear enchantments from all ItemGroups
Browse files Browse the repository at this point in the history
  • Loading branch information
florensie committed Jul 26, 2020
1 parent cf9a92c commit 91cd012
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/main/java/be/florens/eggtab/EggTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
import me.sargunvohra.mcmods.autoconfig1u.serializer.Toml4jConfigSerializer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.item.*;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Arrays;

/**
* The mod needs to be installed on the server too because it adds an item for the tab icon
*/
Expand All @@ -41,30 +38,26 @@ public void onInitializeClient() {
() -> new ItemStack(Items.CREEPER_SPAWN_EGG)
);

LOGGER.info("[Egg Tab] Moving spawn eggs");

// Do all the spawn eggs that have already been registered first
for (SpawnEggItem spawnEggItem : SpawnEggItem.getAll()) {
changeGroupIfEgg(spawnEggItem);
}

LOGGER.info("[Egg Tab] Now listening for new eggs");
LOGGER.info("[Egg Tab] Moving spawn eggs");
SpawnEggItem.getAll().forEach(EggTab::changeGroupIfEgg);

// Make sure we get any eggs that get registered in the future
LOGGER.info("[Egg Tab] Now listening for new eggs");
RegistryEntryAddedCallback.event(Registry.ITEM).register((rawId, id, item) -> changeGroupIfEgg(item));
}

// Enchanted Books group
if (CONFIG.booksGroup) {
LOGGER.info("[Egg Tab] Moving enchanted books");

// Remove enchantments from all groups
Arrays.stream(ItemGroup.GROUPS).forEach(ItemGroup::setEnchantments);

BOOK_GROUP = FabricItemGroupBuilder.build(
new Identifier(MOD_ID, "book_group"),
() -> new ItemStack(Items.ENCHANTED_BOOK)
).setEnchantments(EnchantmentTarget.values()); // Add all enchantments to new group

// Remove enchantments from Tools and Combat groups
ItemGroup.TOOLS.setEnchantments();
ItemGroup.COMBAT.setEnchantments();
}
}

Expand Down

0 comments on commit 91cd012

Please sign in to comment.