From 60022ba86c40e45f3d2f415d960fd17da26cd8e1 Mon Sep 17 00:00:00 2001 From: Dragon-Seeker Date: Wed, 17 Apr 2024 18:08:31 -0500 Subject: [PATCH] Switch to mojmap and fix any issues within #15 --- .gitignore | 1 + build.gradle | 15 +- .../condensed_creative/CondensedCreative.java | 10 +- .../client/SlotRenderUtils.java | 64 ++-- .../compat/ItemGroupVariantHandler.java | 32 +- .../data/BuiltinEntries.java | 251 ++++++------- .../data/CondensedEntriesLoader.java | 74 ++-- .../CreativeInventoryScreenHandlerDuck.java | 7 +- .../condensed_creative/entry/Entry.java | 2 +- .../entry/impl/CondensedItemEntry.java | 101 +++-- .../entry/impl/ItemEntry.java | 2 +- .../mixins/CreativeScreenHandlerAccessor.java | 10 - .../mixins/ItemGroupAccessor.java | 11 - .../mixins/ItemStackSetAccessor.java | 8 +- .../mixins/NbtCompoundAccessor.java | 15 - .../client/CreativeInventoryScreenMixin.java | 220 +++++------ .../CreativeModeInventoryScreenAccessor.java | 12 + .../client/CreativeModeTabAccessor.java | 10 + .../client/CreativeModeTabsAccessor.java | 15 + .../client/CreativeScreenHandlerAccessor.java | 10 + .../mixins/client/HandledScreenAccessor.java | 10 +- .../mixins/client/HandledScreenMixin.java | 26 +- .../registry/CondensedEntryRegistry.java | 92 ++--- .../util/CondensedInventory.java | 87 +++-- .../util/ItemGroupHelper.java | 14 +- .../condensedCreativeCommon.mixins.json | 7 +- .../condensed_creative_common.accesswidener | 35 +- .../fabric/CondensedCreativeFabric.java | 15 +- .../fabric/compat/owo/OwoCompat.java | 31 +- .../compat/owo/OwoItemGroupHandler.java | 8 +- .../mixins/client/HandledScreenMixin.java | 18 +- .../client/CreativeInventoryScreenMixin.java | 352 ------------------ .../mixins/client/HandledScreenMixin.java | 18 +- settings.gradle | 1 + 34 files changed, 606 insertions(+), 978 deletions(-) delete mode 100644 common/src/main/java/io/wispforest/condensed_creative/mixins/CreativeScreenHandlerAccessor.java delete mode 100644 common/src/main/java/io/wispforest/condensed_creative/mixins/ItemGroupAccessor.java delete mode 100644 common/src/main/java/io/wispforest/condensed_creative/mixins/NbtCompoundAccessor.java create mode 100644 common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeInventoryScreenAccessor.java create mode 100644 common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeTabAccessor.java create mode 100644 common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeTabsAccessor.java create mode 100644 common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeScreenHandlerAccessor.java delete mode 100644 neoforge/src/main/java/io/wispforest/condensed_creative/neoforge/mixins/client/CreativeInventoryScreenMixin.java diff --git a/.gitignore b/.gitignore index 25ae5a5..3577ec2 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ bin/ run/ /old-buildstuff/ /old-src/ +remappedSrc/ diff --git a/build.gradle b/build.gradle index 744681b..783a228 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false } architectury { @@ -14,12 +14,17 @@ subprojects { silentMojangMappingsLicense() } + repositories { + maven { url "https://maven.parchmentmc.org" } + } + dependencies { minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" - // The following line declares the mojmap mappings, you may use other mappings as well - //mappings loom.officialMojangMappings() - // The following line declares the yarn mappings you may select this one as well. - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + + mappings loom.layered() { + officialMojangMappings() + parchment("org.parchmentmc.data:parchment-1.20.4:2024.04.14@zip") + } } } diff --git a/common/src/main/java/io/wispforest/condensed_creative/CondensedCreative.java b/common/src/main/java/io/wispforest/condensed_creative/CondensedCreative.java index 8bcde9d..4c6c1c2 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/CondensedCreative.java +++ b/common/src/main/java/io/wispforest/condensed_creative/CondensedCreative.java @@ -6,8 +6,8 @@ import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.ConfigHolder; import me.shedaniel.autoconfig.serializer.GsonConfigSerializer; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.InteractionResult; public class CondensedCreative { @@ -28,7 +28,7 @@ public static void onInitializeClient(boolean debugEnv) { MAIN_CONFIG.registerSaveListener((configHolder, condensedCreativeConfig) -> { CondensedEntryRegistry.refreshEntrypoints(); - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; }); for(CondensedCreativeInitializer initializer : LoaderSpecificUtils.getEntryPoints()){ @@ -48,8 +48,8 @@ public static boolean isDeveloperMode(){ return DEBUG_ENV || DEBUG; } - public static Identifier createID(String path){ - return new Identifier(MODID, path); + public static ResourceLocation createID(String path){ + return new ResourceLocation(MODID, path); } //--------------------------------------------------------------------------------------------------------- diff --git a/common/src/main/java/io/wispforest/condensed_creative/client/SlotRenderUtils.java b/common/src/main/java/io/wispforest/condensed_creative/client/SlotRenderUtils.java index b27fcf8..b2624e7 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/client/SlotRenderUtils.java +++ b/common/src/main/java/io/wispforest/condensed_creative/client/SlotRenderUtils.java @@ -6,23 +6,21 @@ import io.wispforest.condensed_creative.entry.impl.CondensedItemEntry; import io.wispforest.condensed_creative.util.CondensedInventory; import me.shedaniel.math.Color; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.screen.slot.Slot; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.Slot; public class SlotRenderUtils { - private static final Identifier PLUS_ICON = CondensedCreative.createID("textures/gui/plus_logo.png"); - private static final Identifier MINUS_ICON = CondensedCreative.createID("textures/gui/minus_logo.png"); + private static final ResourceLocation PLUS_ICON = CondensedCreative.createID("textures/gui/plus_logo.png"); + private static final ResourceLocation MINUS_ICON = CondensedCreative.createID("textures/gui/minus_logo.png"); - public static void renderExtraIfEntry(HandledScreen screen, DrawContext context, Slot slot){ - if(!(screen instanceof CreativeInventoryScreen && slot.inventory instanceof CondensedInventory inv)) return; + public static void renderExtraIfEntry(AbstractContainerScreen screen, GuiGraphics context, Slot slot){ + if(!(screen instanceof CreativeModeInventoryScreen && slot.container instanceof CondensedInventory inv)) return; - Entry entryStack = inv.getEntryStack(slot.getIndex()); + Entry entryStack = inv.getEntryStack(slot.getContainerSlot()); if(!(entryStack instanceof CondensedItemEntry entry)) return; @@ -67,49 +65,45 @@ public static void renderExtraIfEntry(HandledScreen screen, DrawContext context, } if(!entry.isChild) { - Identifier id = !CondensedItemEntry.CHILD_VISIBILITY.get(entry.condensedID) ? PLUS_ICON : MINUS_ICON; + ResourceLocation id = !CondensedItemEntry.CHILD_VISIBILITY.get(entry.condensedID) ? PLUS_ICON : MINUS_ICON; - context.drawTexture(id, minX, minY, 160, 0, 0, 16, 16, 16, 16); + context.blit(id, minX, minY, 160, 0, 0, 16, 16, 16, 16); } } - @Unique - public static boolean isSlotAbovePartOfCondensedEntry(Slot slot, Identifier condensedID){ - int topSlotIndex = slot.getIndex() - 9; + private static boolean isSlotAbovePartOfCondensedEntry(Slot slot, ResourceLocation condensedID){ + int topSlotIndex = slot.getContainerSlot() - 9; return topSlotIndex >= 0 && - ((CondensedInventory) slot.inventory).getEntryStack(topSlotIndex) instanceof CondensedItemEntry condensedItemEntry && + ((CondensedInventory) slot.container).getEntryStack(topSlotIndex) instanceof CondensedItemEntry condensedItemEntry && condensedID == condensedItemEntry.condensedID; } - @Unique - public static boolean isSlotBelowPartOfCondensedEntry(Slot slot, Identifier condensedID){ - int bottomSlotIndex = slot.getIndex() + 9; + private static boolean isSlotBelowPartOfCondensedEntry(Slot slot, ResourceLocation condensedID){ + int bottomSlotIndex = slot.getContainerSlot() + 9; - return bottomSlotIndex < slot.inventory.size() && - ((CondensedInventory) slot.inventory).getEntryStack(bottomSlotIndex) instanceof CondensedItemEntry condensedItemEntry && + return bottomSlotIndex < slot.container.getContainerSize() && + ((CondensedInventory) slot.container).getEntryStack(bottomSlotIndex) instanceof CondensedItemEntry condensedItemEntry && condensedID == condensedItemEntry.condensedID; } - @Unique - public static boolean isSlotLeftPartOfCondensedEntry(Slot slot, Identifier condensedID){ - if(((slot.id) % 9 == 0)) return false; + private static boolean isSlotLeftPartOfCondensedEntry(Slot slot, ResourceLocation condensedID){ + if(((slot.index) % 9 == 0)) return false; - int leftSlotIndex = slot.getIndex() - 1; + int leftSlotIndex = slot.getContainerSlot() - 1; - return leftSlotIndex < slot.inventory.size() && - ((CondensedInventory) slot.inventory).getEntryStack(leftSlotIndex) instanceof CondensedItemEntry condensedItemEntry && + return leftSlotIndex < slot.container.getContainerSize() && + ((CondensedInventory) slot.container).getEntryStack(leftSlotIndex) instanceof CondensedItemEntry condensedItemEntry && condensedID == condensedItemEntry.condensedID; } - @Unique - public static boolean isSlotRightPartOfCondensedEntry(Slot slot, Identifier condensedID){ - if(((slot.id) % 9 == 8)) return false; + private static boolean isSlotRightPartOfCondensedEntry(Slot slot, ResourceLocation condensedID){ + if(((slot.index) % 9 == 8)) return false; - int rightSlotIndex = slot.getIndex() + 1; + int rightSlotIndex = slot.getContainerSlot() + 1; - return rightSlotIndex < slot.inventory.size() && - ((CondensedInventory) slot.inventory).getEntryStack(rightSlotIndex) instanceof CondensedItemEntry condensedItemEntry && + return rightSlotIndex < slot.container.getContainerSize() && + ((CondensedInventory) slot.container).getEntryStack(rightSlotIndex) instanceof CondensedItemEntry condensedItemEntry && condensedID == condensedItemEntry.condensedID; } } diff --git a/common/src/main/java/io/wispforest/condensed_creative/compat/ItemGroupVariantHandler.java b/common/src/main/java/io/wispforest/condensed_creative/compat/ItemGroupVariantHandler.java index 0db83bf..88ce21e 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/compat/ItemGroupVariantHandler.java +++ b/common/src/main/java/io/wispforest/condensed_creative/compat/ItemGroupVariantHandler.java @@ -1,24 +1,24 @@ package io.wispforest.condensed_creative.compat; -import net.minecraft.item.ItemGroup; -import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.CreativeModeTab; /** * A Handler for ItemGroups that may have various tabs within the given ItemGroup */ -public abstract class ItemGroupVariantHandler { +public abstract class ItemGroupVariantHandler { - private static final Map> VARIANT_HANDLERS = new HashMap<>(); + private static final Map> VARIANT_HANDLERS = new HashMap<>(); private final Class clazz; - private final Identifier id; + private final ResourceLocation id; - protected ItemGroupVariantHandler(Class clazz, Identifier id){ + protected ItemGroupVariantHandler(Class clazz, ResourceLocation id){ this.clazz = clazz; this.id = id; } @@ -29,7 +29,7 @@ protected ItemGroupVariantHandler(Class clazz, Identifier id){ * Attempts to register a given {@link ItemGroupVariantHandler} to the main registry * with check to see if an existing handler for the same ItemGroup clazz exists */ - public static void registerOptional(ItemGroupVariantHandler handler){ + public static void registerOptional(ItemGroupVariantHandler handler){ for (ItemGroupVariantHandler value : VARIANT_HANDLERS.values()) { if(value.clazz.equals(handler.clazz)) return; } @@ -40,7 +40,7 @@ public static void registerOptional(ItemGroupVariantHandle /** * Register a given {@link ItemGroupVariantHandler} to the main registry */ - public static void register(ItemGroupVariantHandler handler){ + public static void register(ItemGroupVariantHandler handler){ var id = handler.getIdentifier(); if(VARIANT_HANDLERS.containsKey(id)){ @@ -54,7 +54,7 @@ public static void register(ItemGroupVariantHandler han * Attempt to return an any handler for the given ItemGroup or null if not none are found */ @Nullable - public static ItemGroupVariantHandler getHandler(ItemGroup itemGroup){ + public static ItemGroupVariantHandler getHandler(CreativeModeTab itemGroup){ for (var handler : VARIANT_HANDLERS.values()) { if(handler.isVariant(itemGroup)) return handler; } @@ -72,30 +72,30 @@ public static Collection> getHandlers(){ //-- /** - * @return whether the {@link ItemGroup} is of the targeted variant + * @return whether the {@link CreativeModeTab} is of the targeted variant */ - public final boolean isVariant(ItemGroup group){ + public final boolean isVariant(CreativeModeTab group){ return clazz.isInstance(group); } /** * Unique Identifier representing the Variant handler */ - public final Identifier getIdentifier(){ + public final ResourceLocation getIdentifier(){ return this.id; } //-- /** - * @return Collection of all selected tabs of the given {@link ItemGroup} Variant + * @return Collection of all selected tabs of the given {@link CreativeModeTab} Variant */ - public abstract Collection getSelectedTabs(ItemGroup group); + public abstract Collection getSelectedTabs(CreativeModeTab group); /** - * @return Get max tabs supported by this {@link ItemGroup} Variant + * @return Get max tabs supported by this {@link CreativeModeTab} Variant */ - public abstract int getMaxTabs(ItemGroup group); + public abstract int getMaxTabs(CreativeModeTab group); //-- diff --git a/common/src/main/java/io/wispforest/condensed_creative/data/BuiltinEntries.java b/common/src/main/java/io/wispforest/condensed_creative/data/BuiltinEntries.java index 1bfa043..c8691e7 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/data/BuiltinEntries.java +++ b/common/src/main/java/io/wispforest/condensed_creative/data/BuiltinEntries.java @@ -6,32 +6,33 @@ import io.wispforest.condensed_creative.entry.impl.CondensedItemEntry; import io.wispforest.condensed_creative.registry.CondensedCreativeInitializer; import io.wispforest.condensed_creative.registry.CondensedEntryRegistry; -import net.minecraft.block.*; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentLevelEntry; -import net.minecraft.enchantment.EnchantmentTarget; -import net.minecraft.entity.SpawnGroup; -import net.minecraft.entity.decoration.painting.PaintingEntity; -import net.minecraft.entity.decoration.painting.PaintingVariant; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.item.*; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionUtil; -import net.minecraft.potion.Potions; -import net.minecraft.registry.Registries; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.registry.tag.BlockTags; -import net.minecraft.registry.tag.ItemTags; -import net.minecraft.registry.tag.PaintingVariantTags; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.DyeColor; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.util.Util; +import net.minecraft.ChatFormatting; +import net.minecraft.Util; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.PaintingVariantTags; +import net.minecraft.tags.TagKey; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.entity.decoration.Painting; +import net.minecraft.world.entity.decoration.PaintingVariant; +import net.minecraft.world.item.*; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.PotionUtils; +import net.minecraft.world.item.alchemy.Potions; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentCategory; +import net.minecraft.world.item.enchantment.EnchantmentInstance; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.*; +import net.minecraft.world.level.block.state.properties.WoodType; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -61,13 +62,13 @@ public class BuiltinEntries implements CondensedCreativeInitializer { (woodType) -> "*_button" ); - private static final List creatures = List.of( - SpawnGroup.CREATURE, - SpawnGroup.AXOLOTLS, - SpawnGroup.AMBIENT, - SpawnGroup.WATER_CREATURE, - SpawnGroup.WATER_AMBIENT, - SpawnGroup.UNDERGROUND_WATER_CREATURE + private static final List creatures = List.of( + MobCategory.CREATURE, + MobCategory.AXOLOTLS, + MobCategory.AMBIENT, + MobCategory.WATER_CREATURE, + MobCategory.WATER_AMBIENT, + MobCategory.UNDERGROUND_WATER_CREATURE ); @Override @@ -78,15 +79,15 @@ public void registerCondensedEntries(boolean refreshed) { // .toggleStrictFiltering(true) // .addToItemGroup(ItemGroups.BUILDING_BLOCKS); - WoodType.stream().forEach(signType -> { - Identifier identifier = new Identifier(signType.name()); + WoodType.values().forEach(signType -> { + ResourceLocation identifier = new ResourceLocation(signType.name()); List woodItemStacks = new ArrayList<>(); WOOD_BLOCK_TYPES.forEach(blockType -> { - Item item = Registries.ITEM.get(new Identifier(identifier.getNamespace(), blockType.apply(identifier.getPath()).replace("*", identifier.getPath()))); + Item item = BuiltInRegistries.ITEM.get(new ResourceLocation(identifier.getNamespace(), blockType.apply(identifier.getPath()).replace("*", identifier.getPath()))); - if(item != Items.AIR) woodItemStacks.add(item.getDefaultStack()); + if(item != Items.AIR) woodItemStacks.add(item.getDefaultInstance()); }); if(woodItemStacks.isEmpty()){ @@ -96,18 +97,18 @@ public void registerCondensedEntries(boolean refreshed) { } if(signType == WoodType.BAMBOO){ - woodItemStacks.add(0, Items.BAMBOO_BLOCK.getDefaultStack()); - woodItemStacks.add(1, Items.STRIPPED_BAMBOO_BLOCK.getDefaultStack()); + woodItemStacks.add(0, Items.BAMBOO_BLOCK.getDefaultInstance()); + woodItemStacks.add(1, Items.STRIPPED_BAMBOO_BLOCK.getDefaultInstance()); - woodItemStacks.add(5, Items.BAMBOO_MOSAIC.getDefaultStack()); - woodItemStacks.add(6, Items.BAMBOO_MOSAIC_STAIRS.getDefaultStack()); - woodItemStacks.add(7, Items.BAMBOO_MOSAIC_SLAB.getDefaultStack()); + woodItemStacks.add(5, Items.BAMBOO_MOSAIC.getDefaultInstance()); + woodItemStacks.add(6, Items.BAMBOO_MOSAIC_STAIRS.getDefaultInstance()); + woodItemStacks.add(7, Items.BAMBOO_MOSAIC_SLAB.getDefaultInstance()); } CondensedEntryRegistry.fromItemStacks(identifier, woodItemStacks.get(0), woodItemStacks) .toggleStrictFiltering(true) .setEntryOrder(CondensedItemEntry.EntryOrder.ITEMGROUP_ORDER) - .addToItemGroup(ItemGroups.BUILDING_BLOCKS); + .addToItemGroup(CreativeModeTabs.BUILDING_BLOCKS); }); Map stoneTypes = Map.ofEntries( @@ -124,11 +125,11 @@ public void registerCondensedEntries(boolean refreshed) { Map.entry("copper", Items.COPPER_BLOCK)); stoneTypes.forEach((type, startingItem) -> { - Identifier identifier = new Identifier(type); + ResourceLocation identifier = new ResourceLocation(type); List stoneItemStacks = new ArrayList<>(); - Registries.BLOCK.getIds().forEach(identifier1 -> { + BuiltInRegistries.BLOCK.keySet().forEach(identifier1 -> { String path = identifier1.getPath(); if(!identifier1.getNamespace().equals("minecraft") || !path.contains(type)) return; @@ -137,14 +138,14 @@ public void registerCondensedEntries(boolean refreshed) { .filter((type1) -> path.contains(type1) && !type1.equals(type) && type1.contains(type)) .toList(); - if(listOfMatches.isEmpty()) stoneItemStacks.add(Registries.ITEM.get(identifier1).getDefaultStack()); + if(listOfMatches.isEmpty()) stoneItemStacks.add(BuiltInRegistries.ITEM.get(identifier1).getDefaultInstance()); }); if (!stoneItemStacks.isEmpty()) { CondensedEntryRegistry.fromItemStacks(identifier, startingItem, stoneItemStacks) .toggleStrictFiltering(true) .setEntryOrder(CondensedItemEntry.EntryOrder.ITEMGROUP_ORDER) - .addToItemGroup(ItemGroups.BUILDING_BLOCKS); + .addToItemGroup(CreativeModeTabs.BUILDING_BLOCKS); } else { LOGGER.warn("The given material Type [{}] seems to have not matched anything!", type); } @@ -152,61 +153,61 @@ public void registerCondensedEntries(boolean refreshed) { CondensedEntryRegistry.of(CondensedCreative.createID("signs"), Items.OAK_SIGN, item -> fromTags(item, ItemTags.SIGNS, ItemTags.HANGING_SIGNS)) - .addToItemGroup(ItemGroups.FUNCTIONAL); + .addToItemGroup(CreativeModeTabs.FUNCTIONAL_BLOCKS); CondensedEntryRegistry.of(CondensedCreative.createID("infested_blocks"), Items.OAK_SIGN, item -> item instanceof BlockItem bi && bi.getBlock() instanceof InfestedBlock) - .addToItemGroup(ItemGroups.FUNCTIONAL); + .addToItemGroup(CreativeModeTabs.FUNCTIONAL_BLOCKS); CondensedEntryRegistry.ofSupplier(CondensedCreative.createID("paintings"), Items.PAINTING, () -> { List paintingVariantStacks = new ArrayList<>(); - Registries.PAINTING_VARIANT.streamEntries() - .filter(pv -> pv.isIn(PaintingVariantTags.PLACEABLE)) + BuiltInRegistries.PAINTING_VARIANT.holders() + .filter(pv -> pv.is(PaintingVariantTags.PLACEABLE)) .sorted(Comparator.comparing( - RegistryEntry::value, + Holder::value, Comparator.comparingInt(pv -> pv.getHeight() * pv.getWidth()).thenComparing(PaintingVariant::getWidth) )) .forEach(paintingVariant -> { ItemStack itemStack = new ItemStack(Items.PAINTING); - PaintingEntity.writeVariantToNbt(itemStack.getOrCreateSubNbt("EntityTag"), paintingVariant); + Painting.storeVariant(itemStack.getOrCreateTagElement("EntityTag"), paintingVariant); paintingVariantStacks.add(itemStack); }); return paintingVariantStacks; }) - .addToItemGroup(ItemGroups.FUNCTIONAL); + .addToItemGroup(CreativeModeTabs.FUNCTIONAL_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("wools"), Blocks.WHITE_WOOL, ItemTags.WOOL) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.COLORED_BLOCKS); + .addToItemGroup(CreativeModeTabs.COLORED_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("terracotta"), Blocks.TERRACOTTA, ItemTags.TERRACOTTA) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.COLORED_BLOCKS); + .addToItemGroup(CreativeModeTabs.COLORED_BLOCKS); CondensedEntryRegistry.of(CondensedCreative.createID("concrete"), Blocks.WHITE_CONCRETE, (item) -> { if(!(item instanceof BlockItem))return false; - String itemPath = Registries.ITEM.getId(item).getPath(); + String itemPath = BuiltInRegistries.ITEM.getKey(item).getPath(); return itemPath.contains("concrete") && !itemPath.contains("powder"); }) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.COLORED_BLOCKS); + .addToItemGroup(CreativeModeTabs.COLORED_BLOCKS); CondensedEntryRegistry.of(CondensedCreative.createID("concrete_powder"), Blocks.WHITE_CONCRETE_POWDER, (item) -> { if(!(item instanceof BlockItem)) return false; - String itemPath = Registries.ITEM.getId(item).getPath(); + String itemPath = BuiltInRegistries.ITEM.getKey(item).getPath(); return itemPath.contains("concrete") && itemPath.contains("powder"); }) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.COLORED_BLOCKS); + .addToItemGroup(CreativeModeTabs.COLORED_BLOCKS); CondensedEntryRegistry.fromItems(CondensedCreative.createID("ores"), Blocks.IRON_ORE, Stream.of(Blocks.COAL_ORE, Blocks.DEEPSLATE_COAL_ORE, @@ -219,37 +220,37 @@ public void registerCondensedEntries(boolean refreshed) { Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE, Blocks.NETHER_GOLD_ORE, Blocks.NETHER_QUARTZ_ORE ).map(Block::asItem).toList()) - .addToItemGroup(ItemGroups.NATURAL); + .addToItemGroup(CreativeModeTabs.NATURAL_BLOCKS); CondensedEntryRegistry.of(CondensedCreative.createID("glass"), Blocks.WHITE_STAINED_GLASS, (item) -> { - var path = Registries.ITEM.getId(item).getPath(); + var path = BuiltInRegistries.ITEM.getKey(item).getPath(); return path.contains("glass") && !path.contains("pane"); }) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.COLORED_BLOCKS); + .addToItemGroup(CreativeModeTabs.COLORED_BLOCKS); //------------------------------- CondensedEntryRegistry.fromTag(CondensedCreative.createID("carpets"), Blocks.WHITE_CARPET, ItemTags.WOOL_CARPETS) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.COLORED_BLOCKS); + .addToItemGroup(CreativeModeTabs.COLORED_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("candles"), Blocks.WHITE_CANDLE, ItemTags.CANDLES) .toggleStrictFiltering(true) - .addToItemGroups(ItemGroups.COLORED_BLOCKS, ItemGroups.FUNCTIONAL); + .addToItemGroups(CreativeModeTabs.COLORED_BLOCKS, CreativeModeTabs.FUNCTIONAL_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("beds"), Blocks.WHITE_BED, ItemTags.BEDS) .toggleStrictFiltering(true) - .addToItemGroups(ItemGroups.COLORED_BLOCKS, ItemGroups.FUNCTIONAL); + .addToItemGroups(CreativeModeTabs.COLORED_BLOCKS, CreativeModeTabs.FUNCTIONAL_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("banners"), Blocks.WHITE_BANNER, ItemTags.BANNERS) .toggleStrictFiltering(true) - .addToItemGroups(ItemGroups.COLORED_BLOCKS, ItemGroups.FUNCTIONAL); + .addToItemGroups(CreativeModeTabs.COLORED_BLOCKS, CreativeModeTabs.FUNCTIONAL_BLOCKS); // CondensedEntryRegistry.fromTag(CondensedCreative.createID("walls"), Blocks.COBBLESTONE_WALL, ItemTags.WALLS) @@ -264,99 +265,99 @@ public void registerCondensedEntries(boolean refreshed) { CondensedEntryRegistry.of(CondensedCreative.createID("glass_panes"), Blocks.GLASS_PANE, (item) -> { - var path = Registries.ITEM.getId(item).getPath(); + var path = BuiltInRegistries.ITEM.getKey(item).getPath(); return path.contains("glass") && path.contains("pane"); }) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.COLORED_BLOCKS); + .addToItemGroup(CreativeModeTabs.COLORED_BLOCKS); CondensedEntryRegistry.of(CondensedCreative.createID("corals"), Blocks.BRAIN_CORAL, - predicateWithVanillaCheck((item) -> item instanceof BlockItem blockItem && blockItem.getBlock() instanceof CoralParentBlock)) - .addToItemGroup(ItemGroups.NATURAL); + predicateWithVanillaCheck((item) -> item instanceof BlockItem blockItem && blockItem.getBlock() instanceof BaseCoralPlantTypeBlock)) + .addToItemGroup(CreativeModeTabs.NATURAL_BLOCKS); CondensedEntryRegistry.of(CondensedCreative.createID("glazed_terracotta"), Blocks.WHITE_GLAZED_TERRACOTTA, predicateWithVanillaCheck((item) -> item instanceof BlockItem blockItem && blockItem.getBlock() instanceof GlazedTerracottaBlock)) - .addToItemGroup(ItemGroups.COLORED_BLOCKS); + .addToItemGroup(CreativeModeTabs.COLORED_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("shulkers"), Blocks.SHULKER_BOX, BlockTags.SHULKER_BOXES) .toggleStrictFiltering(true) - .addToItemGroups(ItemGroups.COLORED_BLOCKS, ItemGroups.FUNCTIONAL); + .addToItemGroups(CreativeModeTabs.COLORED_BLOCKS, CreativeModeTabs.FUNCTIONAL_BLOCKS); //------------------------------- CondensedEntryRegistry.fromTag(CondensedCreative.createID("buttons"), Blocks.STONE_BUTTON, ItemTags.BUTTONS) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.REDSTONE); + .addToItemGroup(CreativeModeTabs.REDSTONE_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("pressure_plates"), Blocks.STONE_PRESSURE_PLATE, BlockTags.PRESSURE_PLATES) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.REDSTONE); + .addToItemGroup(CreativeModeTabs.REDSTONE_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("doors"), Blocks.IRON_DOOR, BlockTags.DOORS) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.REDSTONE); + .addToItemGroup(CreativeModeTabs.REDSTONE_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("trapdoors"), Blocks.IRON_TRAPDOOR, BlockTags.TRAPDOORS) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.REDSTONE); + .addToItemGroup(CreativeModeTabs.REDSTONE_BLOCKS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("fence_gates"), Blocks.OAK_FENCE_GATE, BlockTags.FENCE_GATES) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.REDSTONE); + .addToItemGroup(CreativeModeTabs.REDSTONE_BLOCKS); //------------------------------- - CondensedEntryRegistry.of(CondensedCreative.createID(SpawnGroup.CREATURE.toString().toLowerCase()), Items.BEE_SPAWN_EGG, - isSpawnEggItem(spawnEggItem -> creatures.contains(spawnEggItem.getEntityType(null).getSpawnGroup()))) - .addToItemGroup(ItemGroups.SPAWN_EGGS); + CondensedEntryRegistry.of(CondensedCreative.createID(MobCategory.CREATURE.toString().toLowerCase()), Items.BEE_SPAWN_EGG, + isSpawnEggItem(spawnEggItem -> creatures.contains(spawnEggItem.getType(null).getCategory()))) + .addToItemGroup(CreativeModeTabs.SPAWN_EGGS); - CondensedEntryRegistry.of(CondensedCreative.createID(SpawnGroup.MONSTER.toString().toLowerCase()), Items.ZOMBIE_SPAWN_EGG, - isSpawnEggItem(spawnEggItem -> spawnEggItem.getEntityType(null).getSpawnGroup() == SpawnGroup.MONSTER)) - .addToItemGroup(ItemGroups.SPAWN_EGGS); + CondensedEntryRegistry.of(CondensedCreative.createID(MobCategory.MONSTER.toString().toLowerCase()), Items.ZOMBIE_SPAWN_EGG, + isSpawnEggItem(spawnEggItem -> spawnEggItem.getType(null).getCategory() == MobCategory.MONSTER)) + .addToItemGroup(CreativeModeTabs.SPAWN_EGGS); - CondensedEntryRegistry.of(CondensedCreative.createID(SpawnGroup.MISC.toString().toLowerCase()), Items.VILLAGER_SPAWN_EGG, - isSpawnEggItem(spawnEggItem -> spawnEggItem.getEntityType(null).getSpawnGroup() == SpawnGroup.MISC)) - .addToItemGroup(ItemGroups.SPAWN_EGGS); + CondensedEntryRegistry.of(CondensedCreative.createID(MobCategory.MISC.toString().toLowerCase()), Items.VILLAGER_SPAWN_EGG, + isSpawnEggItem(spawnEggItem -> spawnEggItem.getType(null).getCategory() == MobCategory.MISC)) + .addToItemGroup(CreativeModeTabs.SPAWN_EGGS); // CondensedEntryRegistry.of(CondensedCreative.createID("spawn_eggs"), Items.AXOLOTL_SPAWN_EGG, item -> item instanceof SpawnEggItem) // .addToItemGroup(ItemGroups.SPAWN_EGGS); CondensedEntryRegistry.fromTag(CondensedCreative.createID("music_discs"), Items.MUSIC_DISC_13, ItemTags.MUSIC_DISCS) - .addToItemGroup(ItemGroups.TOOLS); + .addToItemGroup(CreativeModeTabs.TOOLS_AND_UTILITIES); CondensedEntryRegistry.fromTag(CondensedCreative.createID("boats"), Items.OAK_BOAT, ItemTags.BOATS) .toggleStrictFiltering(true) - .addToItemGroup(ItemGroups.TOOLS); + .addToItemGroup(CreativeModeTabs.TOOLS_AND_UTILITIES); - ItemGroup combat = Registries.ITEM_GROUP.get(ItemGroups.COMBAT); + CreativeModeTab combat = BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.COMBAT); addPotionBasedEntries(Items.TIPPED_ARROW, combat, 0, "Arrows", CondensedCreative.getConfig().defaultEntriesConfig.tippedArrows); EntryTypeCondensing potion = CondensedCreative.getConfig().defaultEntriesConfig.potions; { - Set stacks = ItemStackSet.create(); + Set stacks = ItemStackLinkedSet.createTypeAndTagSet(); - for (SuspiciousStewIngredient susStewIngr : SuspiciousStewIngredient.getAll()) { + for (SuspiciousEffectHolder susStewIngr : SuspiciousEffectHolder.getAllEffectHolders()) { stacks.add(Util.make(new ItemStack(Items.SUSPICIOUS_STEW), stack -> { - SuspiciousStewItem.addEffectsToStew(stack, susStewIngr.getStewEffects()); + SuspiciousStewItem.appendMobEffects(stack, susStewIngr.getSuspiciousEffects()); })); } CondensedEntryRegistry.fromItemStacks(CondensedCreative.createID("suspicious_stews"), stacks.iterator().next(), stacks) - .addToItemGroup(ItemGroups.FOOD_AND_DRINK); + .addToItemGroup(CreativeModeTabs.FOOD_AND_DRINKS); } - ItemGroup foodAndDrink = Registries.ITEM_GROUP.get(ItemGroups.FOOD_AND_DRINK); + CreativeModeTab foodAndDrink = BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.FOOD_AND_DRINKS); addPotionBasedEntries(Items.POTION, foodAndDrink, 0, "Potions", potion); addPotionBasedEntries(Items.SPLASH_POTION, foodAndDrink, 1, "Potions", potion); @@ -366,18 +367,18 @@ public void registerCondensedEntries(boolean refreshed) { CondensedEntryRegistry.fromItems(CondensedCreative.createID("dyes"), Items.WHITE_DYE, Arrays.stream(DyeColor.values()) - .map(dyeColor -> Registries.ITEM.get(new Identifier(dyeColor.getName() + "_dye"))) + .map(dyeColor -> BuiltInRegistries.ITEM.get(new ResourceLocation(dyeColor.getName() + "_dye"))) .filter(item -> item != Items.AIR) .toList() - ).addToItemGroup(ItemGroups.INGREDIENTS); + ).addToItemGroup(CreativeModeTabs.INGREDIENTS); addEnchantmentEntries(); CondensedEntryRegistry.fromTag(CondensedCreative.createID("pottery_sherds"), Items.ANGLER_POTTERY_SHERD, ItemTags.DECORATED_POT_SHERDS) - .addToItemGroup(ItemGroups.INGREDIENTS); + .addToItemGroup(CreativeModeTabs.INGREDIENTS); CondensedEntryRegistry.of(CondensedCreative.createID("templates"), Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE, i -> i instanceof SmithingTemplateItem) - .addToItemGroup(ItemGroups.INGREDIENTS); + .addToItemGroup(CreativeModeTabs.INGREDIENTS); //--------------------- } @@ -387,27 +388,27 @@ private static void addEnchantmentEntries(){ if(entryTypeCondensing == EntryTypeCondensing.NONE) return; - Set targets = EnumSet.allOf(EnchantmentTarget.class); + Set targets = EnumSet.allOf(EnchantmentCategory.class); List allEnchantmentBooks = new ArrayList<>(); - for (Enchantment enchantment : Registries.ENCHANTMENT) { - if (!targets.contains(enchantment.target)) continue; + for (Enchantment enchantment : BuiltInRegistries.ENCHANTMENT) { + if (!targets.contains(enchantment.category)) continue; List enchantmentBooks = new ArrayList<>(); for (int i = enchantment.getMinLevel(); i <= enchantment.getMaxLevel(); ++i) { - enchantmentBooks.add(EnchantedBookItem.forEnchantment(new EnchantmentLevelEntry(enchantment, i))); + enchantmentBooks.add(EnchantedBookItem.createForEnchantment(new EnchantmentInstance(enchantment, i))); } if(entryTypeCondensing == EntryTypeCondensing.SEPARATE_COLLECTIONS){ - MutableText mutableText = Text.translatable(enchantment.getTranslationKey()); + MutableComponent mutableText = Component.translatable(enchantment.getDescriptionId()); - mutableText.formatted(Formatting.WHITE); + mutableText.withStyle(ChatFormatting.WHITE); - CondensedEntryRegistry.fromItemStacks(CondensedCreative.createID(enchantment.getTranslationKey()), enchantmentBooks.get(0), enchantmentBooks) + CondensedEntryRegistry.fromItemStacks(CondensedCreative.createID(enchantment.getDescriptionId()), enchantmentBooks.get(0), enchantmentBooks) .setTitle(mutableText) - .addToItemGroup(ItemGroups.INGREDIENTS); + .addToItemGroup(CreativeModeTabs.INGREDIENTS); } else { allEnchantmentBooks.addAll(enchantmentBooks); } @@ -415,20 +416,20 @@ private static void addEnchantmentEntries(){ if(!allEnchantmentBooks.isEmpty()){ CondensedEntryRegistry.fromItemStacks(CondensedCreative.createID("enchantment_books"), Items.ENCHANTED_BOOK, allEnchantmentBooks) - .addToItemGroup(ItemGroups.INGREDIENTS); + .addToItemGroup(CreativeModeTabs.INGREDIENTS); } } - private static void addPotionBasedEntries(Item potionBasedItem, ItemGroup targetGroup, int wordIndex, String pluralizedWord, EntryTypeCondensing entryTypeCondensing){ + private static void addPotionBasedEntries(Item potionBasedItem, CreativeModeTab targetGroup, int wordIndex, String pluralizedWord, EntryTypeCondensing entryTypeCondensing){ if(entryTypeCondensing == EntryTypeCondensing.NONE) return; - Map, List> sortedPotions = new LinkedHashMap<>(); + Map, List> sortedPotions = new LinkedHashMap<>(); - for (Potion potion : Registries.POTION) { + for (Potion potion : BuiltInRegistries.POTION) { if (potion == Potions.EMPTY) continue; - List effects = potion.getEffects().stream() - .map(StatusEffectInstance::getEffectType).toList(); + List effects = potion.getEffects().stream() + .map(MobEffectInstance::getEffect).toList(); sortedPotions.computeIfAbsent(effects, statusEffects -> new ArrayList<>()).add(potion); } @@ -438,22 +439,22 @@ private static void addPotionBasedEntries(Item potionBasedItem, ItemGroup target sortedPotions.forEach((statusEffects, potions) -> { List potionItems = new ArrayList<>(); - potions.forEach(p -> potionItems.add(PotionUtil.setPotion(new ItemStack(potionBasedItem), p))); + potions.forEach(p -> potionItems.add(PotionUtils.setPotion(new ItemStack(potionBasedItem), p))); if (potionItems.isEmpty()) return; if(entryTypeCondensing == EntryTypeCondensing.SEPARATE_COLLECTIONS) { - String translationKey = potionItems.get(0).getTranslationKey(); + String translationKey = potionItems.get(0).getDescriptionId(); CondensedEntryRegistry.fromItemStacks(CondensedCreative.createID(translationKey), potionItems.get(0), potionItems) .setTitleSupplier(() -> { - String[] words = Text.translatable(translationKey).getString() + String[] words = Component.translatable(translationKey).getString() .split(" "); words[wordIndex] = pluralizedWord; - return Text.literal(StringUtils.join(words, " ")) - .formatted(Formatting.WHITE); + return Component.literal(StringUtils.join(words, " ")) + .withStyle(ChatFormatting.WHITE); }) .addToItemGroup(targetGroup); } else { @@ -462,7 +463,7 @@ private static void addPotionBasedEntries(Item potionBasedItem, ItemGroup target }); if(!allPotionItems.isEmpty()){ - Identifier itemId = Registries.ITEM.getId(potionBasedItem); + ResourceLocation itemId = BuiltInRegistries.ITEM.getKey(potionBasedItem); String[] words = itemId.getPath().split("_"); @@ -475,7 +476,7 @@ private static void addPotionBasedEntries(Item potionBasedItem, ItemGroup target } } - private static final Predicate vanillaItemsOnly = item -> Objects.equals(Registries.ITEM.getId(item).getNamespace(), "minecraft"); + private static final Predicate vanillaItemsOnly = item -> Objects.equals(BuiltInRegistries.ITEM.getKey(item).getNamespace(), "minecraft"); private static Predicate predicateWithVanillaCheck(Predicate mainPredicate){ return (item) -> BuiltinEntries.vanillaItemsOnly.and(mainPredicate).test(item); @@ -486,16 +487,16 @@ private static Predicate isSpawnEggItem(Predicate predicate) } @SafeVarargs - private static boolean fromTags(Item item, TagKey ...tagKeys){ + private static boolean fromTags(Item item, TagKey ...tagKeys){ if(tagKeys.length == 0) return false; boolean isInTag = false; for(TagKey tagKey: tagKeys) { - if (tagKey.isOf(RegistryKeys.ITEM)) { - isInTag = item.getRegistryEntry().isIn((TagKey) tagKey); - } else if (tagKey.isOf(RegistryKeys.BLOCK)) { - isInTag = item instanceof BlockItem blockItem && blockItem.getBlock().getRegistryEntry().isIn((TagKey) tagKey); + if (tagKey.isFor(Registries.ITEM)) { + isInTag = item.builtInRegistryHolder().is((TagKey) tagKey); + } else if (tagKey.isFor(Registries.BLOCK)) { + isInTag = item instanceof BlockItem blockItem && blockItem.getBlock().builtInRegistryHolder().is((TagKey) tagKey); } else { LOGGER.warn("It seems that a Condensed Entry was somehow registered with Tag that isn't part of the Item or Block Registry"); } diff --git a/common/src/main/java/io/wispforest/condensed_creative/data/CondensedEntriesLoader.java b/common/src/main/java/io/wispforest/condensed_creative/data/CondensedEntriesLoader.java index b905980..cc2bd2f 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/data/CondensedEntriesLoader.java +++ b/common/src/main/java/io/wispforest/condensed_creative/data/CondensedEntriesLoader.java @@ -7,50 +7,50 @@ import io.wispforest.condensed_creative.entry.impl.CondensedItemEntry; import io.wispforest.condensed_creative.registry.CondensedEntryRegistry; import io.wispforest.condensed_creative.util.ItemGroupHelper; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemGroups; -import net.minecraft.registry.Registries; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.resource.JsonDataLoader; -import net.minecraft.resource.ResourceManager; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.JsonHelper; -import net.minecraft.util.profiler.Profiler; import org.slf4j.Logger; import java.util.*; import java.util.function.Function; import java.util.stream.Stream; - -public class CondensedEntriesLoader extends JsonDataLoader { +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; +import net.minecraft.tags.TagKey; +import net.minecraft.util.GsonHelper; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.CreativeModeTabs; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; + +public class CondensedEntriesLoader extends SimpleJsonResourceReloadListener { private static final Logger LOGGER = LogUtils.getLogger(); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); - private static final Map LOCAL_ENTRIES = new HashMap<>(); + private static final Map LOCAL_ENTRIES = new HashMap<>(); private static boolean checkLocalEntries = false; - private static final List BLACKLISTED_ITEM_GROUPS = Stream.of( - ItemGroups.HOTBAR, - ItemGroups.SEARCH, - ItemGroups.OPERATOR - ).map(Registries.ITEM_GROUP::get).toList(); + private static final List BLACKLISTED_ITEM_GROUPS = Stream.of( + CreativeModeTabs.HOTBAR, + CreativeModeTabs.SEARCH, + CreativeModeTabs.OP_BLOCKS + ).map(BuiltInRegistries.CREATIVE_MODE_TAB::get).toList(); public CondensedEntriesLoader() { super(GSON, "condensed_entries"); } @Override - protected void apply(Map prepared, ResourceManager manager, Profiler profiler) { + protected void apply(Map prepared, ResourceManager manager, ProfilerFiller profiler) { LOGGER.info("[CondensedEntriesLoader]: Starting loading!"); if(!CondensedEntryRegistry.RESOURCE_LOADED_ENTRIES.isEmpty()) CondensedEntryRegistry.RESOURCE_LOADED_ENTRIES.clear(); - List ITEM_GROUPS = new ArrayList<>(ItemGroups.getGroups()); + List ITEM_GROUPS = new ArrayList<>(CreativeModeTabs.allTabs()); ITEM_GROUPS.removeAll(BLACKLISTED_ITEM_GROUPS); @@ -65,11 +65,11 @@ protected void apply(Map prepared, ResourceManager mana LOGGER.info("[CondensedEntriesLoader]: Ending loading!"); } - private static List deserializeFile(Identifier id, JsonObject json, List itemGroups) { + private static List deserializeFile(ResourceLocation id, JsonObject json, List itemGroups) { Map jsonMap = json.asMap(); if(json.has("debug_entries")){ - boolean debug_entries = JsonHelper.getBoolean(json, "debug_entries"); + boolean debug_entries = GsonHelper.getAsBoolean(json, "debug_entries"); if(debug_entries && !CondensedCreative.isDeveloperMode()) return List.of(); @@ -86,7 +86,7 @@ private static List deserializeFile(Identifier id, JsonObjec JsonObject entriesJson = json.getAsJsonObject("sharded_entries"); for(Map.Entry entryJson : entriesJson.entrySet()){ - Identifier entryId = Identifier.tryParse(entryJson.getKey()); + ResourceLocation entryId = ResourceLocation.tryParse(entryJson.getKey()); if(entryId == null){ LOGGER.error("[CondensedEntryLoader]: A given Condensed Entry has a invalid Identifier: [FileID: {}, EntryID: {}]", id, entryJson.getKey()); @@ -105,10 +105,10 @@ private static List deserializeFile(Identifier id, JsonObjec List entries = new ArrayList<>(); for(Map.Entry itemGroupEntries : jsonMap.entrySet()){ - Identifier itemGroupId = new Identifier(itemGroupEntries.getKey()); + ResourceLocation itemGroupId = new ResourceLocation(itemGroupEntries.getKey()); - Optional possibleItemGroup = itemGroups.stream() - .filter(group -> Objects.equals(Registries.ITEM_GROUP.getId(group), itemGroupId)).findFirst(); + Optional possibleItemGroup = itemGroups.stream() + .filter(group -> Objects.equals(BuiltInRegistries.CREATIVE_MODE_TAB.getKey(group), itemGroupId)).findFirst(); if(possibleItemGroup.isEmpty()){ LOGGER.error("[CondensedEntryLoader]: A Invaild Itemgroup name was given so no Entries are loaded from it: [FileID: {}, GroupID: {}]", id, itemGroupId); @@ -169,14 +169,14 @@ private static List deserializeFile(Identifier id, JsonObjec return entries; } - private static Optional deserializeEntry(Identifier fileID, String key, JsonElement jsonData){ + private static Optional deserializeEntry(ResourceLocation fileID, String key, JsonElement jsonData){ if(!(jsonData instanceof JsonObject jsonObject)) { LOGGER.error("[CondensedEntryLoader]: A given Entry was attempted to be read but was malformed: [FileID: {}, EntryID: {}]", fileID, key); return Optional.empty(); } - Identifier entryId = Identifier.tryParse(key); + ResourceLocation entryId = ResourceLocation.tryParse(key); if(entryId == null){ LOGGER.error("[CondensedEntryLoader]: A given Condensed Entry has a invalid Identifier: [FileID: {}, EntryID: {}]", fileID, key); @@ -193,7 +193,7 @@ private static Optional deserializeEntry(Identifier Item item; try { - item = JsonHelper.getItem(jsonObject, "base_item").value(); + item = GsonHelper.getAsItem(jsonObject, "base_item").value(); } catch (JsonSyntaxException e){ LOGGER.warn("[CondensedEntryLoader]: The Base Item for a given entry was found to be malformed in some way: [FileID: {}, EntryID: {}]", fileID, key); LOGGER.warn(e.getMessage()); @@ -202,19 +202,19 @@ private static Optional deserializeEntry(Identifier } if (jsonObject.has("item_tag")) { - TagKey itemTagKey = TagKey.of(RegistryKeys.ITEM, Identifier.tryParse(JsonHelper.getString(jsonObject, "item_tag"))); + TagKey itemTagKey = TagKey.create(Registries.ITEM, ResourceLocation.tryParse(GsonHelper.getAsString(jsonObject, "item_tag"))); builder = CondensedEntryRegistry.fromTag(entryId, item, itemTagKey); } else if (jsonObject.has("block_tag")) { - TagKey itemTagKey = TagKey.of(RegistryKeys.BLOCK, Identifier.tryParse(JsonHelper.getString(jsonObject, "block_tag"))); + TagKey itemTagKey = TagKey.create(Registries.BLOCK, ResourceLocation.tryParse(GsonHelper.getAsString(jsonObject, "block_tag"))); builder = CondensedEntryRegistry.fromTag(entryId, item, itemTagKey); } else if (jsonObject.has("items")) { List items = new ArrayList<>(); - JsonHelper.getArray(jsonObject, "items").forEach(jsonElement -> items.add(JsonHelper.asItem(jsonElement, jsonElement.getAsString()).value())); + GsonHelper.getAsJsonArray(jsonObject, "items").forEach(jsonElement -> items.add(GsonHelper.convertToItem(jsonElement, jsonElement.getAsString()).value())); builder = CondensedEntryRegistry.fromItems(entryId, item, items); } else { @@ -243,7 +243,7 @@ private static Optional deserializeEntry(Identifier builder.setTitleFromTag(); } } else { - Text text = Text.Serialization.fromJsonTree(element); + Component text = Component.Serializer.fromJson(element); builder.setTitle(text); } @@ -257,7 +257,7 @@ private static Optional deserializeEntry(Identifier JsonElement element = jsonObject.get("description"); try { - Text text = Text.Serialization.fromJsonTree(element); + Component text = Component.Serializer.fromJson(element); builder.setDescription(text); } catch (JsonParseException e){ diff --git a/common/src/main/java/io/wispforest/condensed_creative/ducks/CreativeInventoryScreenHandlerDuck.java b/common/src/main/java/io/wispforest/condensed_creative/ducks/CreativeInventoryScreenHandlerDuck.java index e7c00b9..89fd501 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/ducks/CreativeInventoryScreenHandlerDuck.java +++ b/common/src/main/java/io/wispforest/condensed_creative/ducks/CreativeInventoryScreenHandlerDuck.java @@ -1,16 +1,15 @@ package io.wispforest.condensed_creative.ducks; import io.wispforest.condensed_creative.entry.Entry; -import net.minecraft.item.ItemStack; -import net.minecraft.util.collection.DefaultedList; - import java.util.Collection; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; public interface CreativeInventoryScreenHandlerDuck { void markEntryListDirty(); - DefaultedList getDefaultEntryList(); + NonNullList getDefaultEntryList(); default boolean addToDefaultEntryList(ItemStack stack) { return this.getDefaultEntryList().add(Entry.of(stack)); diff --git a/common/src/main/java/io/wispforest/condensed_creative/entry/Entry.java b/common/src/main/java/io/wispforest/condensed_creative/entry/Entry.java index 2d01f41..31e295f 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/entry/Entry.java +++ b/common/src/main/java/io/wispforest/condensed_creative/entry/Entry.java @@ -1,7 +1,7 @@ package io.wispforest.condensed_creative.entry; import io.wispforest.condensed_creative.entry.impl.ItemEntry; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; public interface Entry { diff --git a/common/src/main/java/io/wispforest/condensed_creative/entry/impl/CondensedItemEntry.java b/common/src/main/java/io/wispforest/condensed_creative/entry/impl/CondensedItemEntry.java index 39e75c6..8585161 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/entry/impl/CondensedItemEntry.java +++ b/common/src/main/java/io/wispforest/condensed_creative/entry/impl/CondensedItemEntry.java @@ -5,17 +5,17 @@ import io.wispforest.condensed_creative.entry.Entry; import io.wispforest.condensed_creative.registry.CondensedEntryRegistry; import io.wispforest.condensed_creative.util.ItemGroupHelper; -import net.minecraft.block.Block; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.*; -import net.minecraft.registry.Registries; -import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; +import net.minecraft.ChatFormatting; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.*; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.Block; import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.text.WordUtils; import org.jetbrains.annotations.ApiStatus; @@ -23,7 +23,6 @@ import org.slf4j.Logger; import java.util.*; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; @@ -33,17 +32,17 @@ public class CondensedItemEntry extends ItemEntry { private static final Logger LOGGER = LogUtils.getLogger(); - public static final Map CHILD_VISIBILITY = new HashMap<>(); + public static final Map CHILD_VISIBILITY = new HashMap<>(); //------------------------------------------- - public final Identifier condensedID; + public final ResourceLocation condensedID; @Nullable private Supplier> childrenSupplier = null; - @Nullable private Supplier condensedEntryTitleBuilder = null; + @Nullable private Supplier condensedEntryTitleBuilder = null; - private Text condensedEntryTitle; + private Component condensedEntryTitle; private boolean compareToItem = false; @@ -57,11 +56,11 @@ public class CondensedItemEntry extends ItemEntry { //------------------------------------------- - private @Nullable Text descriptionText = null; + private @Nullable Component descriptionText = null; private @Nullable Consumer> entrySorting = null; - private @Nullable TagKey tagKey = null; + private @Nullable TagKey tagKey = null; //------------------------------------------- @@ -73,19 +72,19 @@ public class CondensedItemEntry extends ItemEntry { //------------------------------------------- - private CondensedItemEntry(Identifier identifier, ItemStack defaultStack, boolean isChild) { + private CondensedItemEntry(ResourceLocation identifier, ItemStack defaultStack, boolean isChild) { super(defaultStack); this.condensedID = identifier; this.isChild = isChild; - this.condensedEntryTitle = Text.of(Arrays.stream(identifier.getPath().split("_")).map(WordUtils::capitalize).collect(Collectors.joining(" "))); + this.condensedEntryTitle = Component.nullToEmpty(Arrays.stream(identifier.getPath().split("_")).map(WordUtils::capitalize).collect(Collectors.joining(" "))); CHILD_VISIBILITY.put(identifier, false); } @ApiStatus.Internal - private static CondensedItemEntry createChild(Identifier condensedID, ItemStack defaultItemstack) { + private static CondensedItemEntry createChild(ResourceLocation condensedID, ItemStack defaultItemstack) { return new CondensedItemEntry(condensedID, defaultItemstack, true); } @@ -95,27 +94,27 @@ public static class Builder { public final CondensedItemEntry currentEntry; - public Builder(Identifier condensedID, ItemStack defaultItemstack, Supplier> entryListSupplier) { + public Builder(ResourceLocation condensedID, ItemStack defaultItemstack, Supplier> entryListSupplier) { this.currentEntry = new CondensedItemEntry(condensedID, defaultItemstack, false); this.currentEntry.childrenSupplier = entryListSupplier; } - public Builder(Identifier condensedID, ItemStack defaultItemstack, Collection entries) { + public Builder(ResourceLocation condensedID, ItemStack defaultItemstack, Collection entries) { this.currentEntry = new CondensedItemEntry(condensedID, defaultItemstack, false); this.currentEntry.childrenSupplier = () -> new ArrayList<>(entries); } - public Builder(Identifier condensedID, ItemStack defaultItemstack, @Nullable Predicate entryPredicate, @Nullable TagKey tagKey) { + public Builder(ResourceLocation condensedID, ItemStack defaultItemstack, @Nullable Predicate entryPredicate, @Nullable TagKey tagKey) { this.currentEntry = new CondensedItemEntry(condensedID, defaultItemstack, false); if(entryPredicate != null) { this.currentEntry.childrenSupplier = () -> { List stacks = new ArrayList<>(); - Registries.ITEM.forEach(item1 -> { - if (entryPredicate.test(item1)) stacks.add(item1.getDefaultStack()); + BuiltInRegistries.ITEM.forEach(item1 -> { + if (entryPredicate.test(item1)) stacks.add(item1.getDefaultInstance()); }); return stacks; @@ -153,18 +152,18 @@ public Builder useItemComparison(boolean value){ } /** - * Sets the tooltip title text to be based of the given {@link Text} Supplier + * Sets the tooltip title text to be based of the given {@link Component} Supplier */ - public Builder setTitleSupplier(Supplier condensedEntryTitle){ + public Builder setTitleSupplier(Supplier condensedEntryTitle){ this.currentEntry.condensedEntryTitleBuilder = condensedEntryTitle; return this; } /** - * Sets the tooltip title text to be based of the given {@link Text} + * Sets the tooltip title text to be based of the given {@link Component} */ - public Builder setTitle(Text condensedEntryTitle){ + public Builder setTitle(Component condensedEntryTitle){ this.currentEntry.condensedEntryTitle = condensedEntryTitle; return this; @@ -175,7 +174,7 @@ public Builder setTitle(Text condensedEntryTitle){ */ public Builder setTitleFromTag(){ if(this.currentEntry.tagKey != null){ - this.currentEntry.condensedEntryTitle = Text.of(Arrays.stream(this.currentEntry.tagKey.id().getPath().split("_")).map(WordUtils::capitalize).collect(Collectors.joining(" "))); + this.currentEntry.condensedEntryTitle = Component.nullToEmpty(Arrays.stream(this.currentEntry.tagKey.location().getPath().split("_")).map(WordUtils::capitalize).collect(Collectors.joining(" "))); } return this; @@ -184,7 +183,7 @@ public Builder setTitleFromTag(){ /** * Adds description onto the Entries tooltip */ - public Builder setDescription(Text description){ + public Builder setDescription(Component description){ this.currentEntry.descriptionText = description; return this; @@ -219,40 +218,40 @@ public Builder toggleStrictFiltering(boolean value){ } /** - * Used to add the {@link CondensedItemEntry} to a certain {@link ItemGroup} + * Used to add the {@link CondensedItemEntry} to a certain {@link CreativeModeTab} */ - public CondensedItemEntry addToItemGroup(ItemGroup itemGroup){ + public CondensedItemEntry addToItemGroup(CreativeModeTab itemGroup){ return addToItemGroup(itemGroup, -1); } - public CondensedItemEntry addToItemGroup(RegistryKey itemGroup){ + public CondensedItemEntry addToItemGroup(ResourceKey itemGroup){ return addToItemGroup(itemGroup, -1); } /** - * Used to add the {@link CondensedItemEntry} to a certain {@link ItemGroup} with tab index support if using a Supported ItemGroup Variant with tabs + * Used to add the {@link CondensedItemEntry} to a certain {@link CreativeModeTab} with tab index support if using a Supported ItemGroup Variant with tabs */ - public CondensedItemEntry addToItemGroup(ItemGroup itemGroup, int tabIndex){ + public CondensedItemEntry addToItemGroup(CreativeModeTab itemGroup, int tabIndex){ return addToItemGroup(ItemGroupHelper.of(itemGroup, tabIndex), true); } - public CondensedItemEntry addToItemGroup(RegistryKey itemGroup, int tabIndex){ + public CondensedItemEntry addToItemGroup(ResourceKey itemGroup, int tabIndex){ return addToItemGroup(ItemGroupHelper.of(itemGroup, tabIndex), true); } - public List addToItemGroups(ItemGroup ...groups){ + public List addToItemGroups(CreativeModeTab ...groups){ return this.addToItemGroups(true, Arrays.stream(groups).map(group -> ItemGroupHelper.of(group, 0)).toArray(ItemGroupHelper[]::new)); } @SafeVarargs - public final List addToItemGroups(RegistryKey... groups){ + public final List addToItemGroups(ResourceKey... groups){ return this.addToItemGroups(true, Arrays.stream(groups).map(group -> ItemGroupHelper.of(group, 0)).toArray(ItemGroupHelper[]::new)); } public List addToItemGroups(boolean addToMainEntriesMap, ItemGroupHelper... helpers){ List condensedItemEntries = new ArrayList<>(); - CondensedItemEntry.Builder builder = this; + Builder builder = this; for(ItemGroupHelper helper : helpers){ condensedItemEntries.add(builder.addToItemGroup(helper, addToMainEntriesMap)); @@ -329,19 +328,19 @@ public List getChildren(){ if(childrenSupplier != null) return childrenSupplier.get(); if(tagKey != null) { - Registries.ITEM.forEach(item1 -> { if (withinEntriesTag(item1)) stacks.add(item1.getDefaultStack()); }); + BuiltInRegistries.ITEM.forEach(item1 -> { if (withinEntriesTag(item1)) stacks.add(item1.getDefaultInstance()); }); } return stacks; } - private boolean withinEntriesTag(Item item) { + private boolean withinEntriesTag(Item item) { if(tagKey == null) return false; - if(tagKey.isOf(RegistryKeys.ITEM)){ - return item.getRegistryEntry().isIn((TagKey) tagKey); - } else if(tagKey.isOf(RegistryKeys.BLOCK)) { - return item instanceof BlockItem blockItem && blockItem.getBlock().getRegistryEntry().isIn((TagKey) tagKey); + if(tagKey.isFor(Registries.ITEM)){ + return item.builtInRegistryHolder().is((TagKey) tagKey); + } else if(tagKey.isFor(Registries.BLOCK)) { + return item instanceof BlockItem blockItem && blockItem.getBlock().builtInRegistryHolder().is((TagKey) tagKey); } else { LOGGER.warn("[CondensedEntryRegistry]: It seems that a Condensed Entry was somehow registered with Tag that isn't part of the Item or Block Registry: [Id: {}]", this.condensedID); } @@ -406,7 +405,7 @@ public void toggleVisibility() { if(!isChild) CHILD_VISIBILITY.replace(this.condensedID, !CHILD_VISIBILITY.get(this.condensedID)); } - public void getParentTooltipText(List tooltipData, PlayerEntity player, TooltipContext context) { + public void getParentTooltipText(List tooltipData, Player player, TooltipFlag context) { if(condensedEntryTitleBuilder != null){ condensedEntryTitle = this.condensedEntryTitleBuilder.get(); @@ -420,13 +419,13 @@ public void getParentTooltipText(List tooltipData, PlayerEntity player, To } if(tagKey != null && CondensedCreative.getConfig().tagPreviewForEntries){ - tooltipData.add(Text.of("Tag: #" + tagKey.id().toString()).copy().formatted(Formatting.GRAY)); + tooltipData.add(Component.nullToEmpty("Tag: #" + tagKey.location().toString()).copy().withStyle(ChatFormatting.GRAY)); } if(CondensedCreative.getConfig().debugIdentifiersForEntries) { - tooltipData.add(Text.of("")); + tooltipData.add(Component.nullToEmpty("")); - tooltipData.add(Text.of("EntryID: " + condensedID.toString()).copy().formatted(Formatting.GRAY)); + tooltipData.add(Component.nullToEmpty("EntryID: " + condensedID.toString()).copy().withStyle(ChatFormatting.GRAY)); } } diff --git a/common/src/main/java/io/wispforest/condensed_creative/entry/impl/ItemEntry.java b/common/src/main/java/io/wispforest/condensed_creative/entry/impl/ItemEntry.java index a68b1e5..24a01c5 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/entry/impl/ItemEntry.java +++ b/common/src/main/java/io/wispforest/condensed_creative/entry/impl/ItemEntry.java @@ -2,7 +2,7 @@ import io.wispforest.condensed_creative.entry.Entry; import io.wispforest.condensed_creative.mixins.ItemStackSetAccessor; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; public class ItemEntry implements Entry { diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/CreativeScreenHandlerAccessor.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/CreativeScreenHandlerAccessor.java deleted file mode 100644 index 662741a..0000000 --- a/common/src/main/java/io/wispforest/condensed_creative/mixins/CreativeScreenHandlerAccessor.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.wispforest.condensed_creative.mixins; - -import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(CreativeInventoryScreen.CreativeScreenHandler.class) -public interface CreativeScreenHandlerAccessor { - @Invoker int callGetOverflowRows(); -} diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/ItemGroupAccessor.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/ItemGroupAccessor.java deleted file mode 100644 index 9301bc4..0000000 --- a/common/src/main/java/io/wispforest/condensed_creative/mixins/ItemGroupAccessor.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.wispforest.condensed_creative.mixins; - -import net.minecraft.item.ItemGroup; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(ItemGroup.class) -public interface ItemGroupAccessor { - - @Accessor("entryCollector") ItemGroup.EntryCollector cc$getEntryCollector(); -} diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/ItemStackSetAccessor.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/ItemStackSetAccessor.java index 145fe90..6db23f5 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/mixins/ItemStackSetAccessor.java +++ b/common/src/main/java/io/wispforest/condensed_creative/mixins/ItemStackSetAccessor.java @@ -1,12 +1,12 @@ package io.wispforest.condensed_creative.mixins; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemStackSet; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ItemStackLinkedSet; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; -@Mixin(ItemStackSet.class) +@Mixin(ItemStackLinkedSet.class) public interface ItemStackSetAccessor { - @Invoker("getHashCode") static int cc$getHashCode(@Nullable ItemStack stack) { throw new UnsupportedOperationException(); } + @Invoker("hashStackAndTag") static int cc$getHashCode(@Nullable ItemStack stack) { throw new UnsupportedOperationException(); } } diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/NbtCompoundAccessor.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/NbtCompoundAccessor.java deleted file mode 100644 index 908f498..0000000 --- a/common/src/main/java/io/wispforest/condensed_creative/mixins/NbtCompoundAccessor.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.wispforest.condensed_creative.mixins; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - -@Mixin(NbtCompound.class) -public interface NbtCompoundAccessor { - - @Accessor("entries") Map cc$getEntries(); - -} diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeInventoryScreenMixin.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeInventoryScreenMixin.java index fd5a245..aa6b888 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeInventoryScreenMixin.java +++ b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeInventoryScreenMixin.java @@ -2,45 +2,34 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import com.llamalad7.mixinextras.sugar.Local; import io.wispforest.condensed_creative.CondensedCreative; import io.wispforest.condensed_creative.compat.ItemGroupVariantHandler; import io.wispforest.condensed_creative.ducks.CreativeInventoryScreenHandlerDuck; import io.wispforest.condensed_creative.entry.Entry; import io.wispforest.condensed_creative.entry.impl.CondensedItemEntry; import io.wispforest.condensed_creative.entry.impl.ItemEntry; -import io.wispforest.condensed_creative.mixins.CreativeScreenHandlerAccessor; import io.wispforest.condensed_creative.registry.CondensedEntryRegistry; import io.wispforest.condensed_creative.util.CondensedInventory; import io.wispforest.condensed_creative.util.ItemGroupHelper; import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.client.gui.screen.ButtonTextures; -import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; -import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.ClickableWidget; -import net.minecraft.client.gui.widget.TexturedButtonWidget; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemGroups; -import net.minecraft.item.ItemStack; -import net.minecraft.registry.Registries; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.screen.ScreenTexts; -import net.minecraft.screen.slot.Slot; -import net.minecraft.screen.slot.SlotActionType; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.MathHelper; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.components.WidgetSprites; +import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; +import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen; +import net.minecraft.core.NonNullList; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TooltipFlag; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; @@ -50,69 +39,71 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; import java.util.function.Predicate; -@Mixin(CreativeInventoryScreen.class) -@Debug(export = true) -public abstract class CreativeInventoryScreenMixin extends AbstractInventoryScreen { +@Mixin(CreativeModeInventoryScreen.class) +public abstract class CreativeInventoryScreenMixin extends EffectRenderingInventoryScreen { - @Shadow @Final @Mutable public static SimpleInventory INVENTORY; + @Shadow @Final @Mutable public static SimpleContainer CONTAINER; - @Shadow private static ItemGroup selectedTab; + @Shadow private static CreativeModeTab selectedTab; - @Shadow private float scrollPosition; + @Shadow private float scrollOffs; - @Shadow protected abstract void setSelectedTab(ItemGroup group); + @Shadow protected abstract void selectTab(CreativeModeTab group); //------------- - @Unique private static final Identifier refreshButtonIconUnfocused = CondensedCreative.createID("refresh_button_unfocused"); - @Unique private static final Identifier refreshButtonIconFocused = CondensedCreative.createID("refresh_button_focused"); + @Unique private static final ResourceLocation refreshButtonIconUnfocused = CondensedCreative.createID("refresh_button_unfocused"); + @Unique private static final ResourceLocation refreshButtonIconFocused = CondensedCreative.createID("refresh_button_focused"); @Unique private boolean validItemGroupForCondensedEntries = false; //------------- - public CreativeInventoryScreenMixin(CreativeInventoryScreen.CreativeScreenHandler screenHandler, PlayerInventory playerInventory, Text text) { + public CreativeInventoryScreenMixin(CreativeModeInventoryScreen.ItemPickerMenu screenHandler, Inventory playerInventory, Component text) { super(screenHandler, playerInventory, text); } @Inject(method = "", at = @At("TAIL")) private static void setupInventory(CallbackInfo ci){ - INVENTORY = new CondensedInventory(INVENTORY.size()); + CONTAINER = new CondensedInventory(CONTAINER.getContainerSize()); } - @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/PlayerScreenHandler;addListener(Lnet/minecraft/screen/ScreenHandlerListener;)V", shift = At.Shift.BY, by = 2)) + @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/InventoryMenu;addSlotListener(Lnet/minecraft/world/inventory/ContainerListener;)V", shift = At.Shift.BY, by = 2)) private void addButtonRender(CallbackInfo ci){ if(!CondensedCreative.getConfig().entryRefreshButton) return; - var widget = new TexturedButtonWidget(this.x + 200, this.y + 140, 16, 16, new ButtonTextures(refreshButtonIconUnfocused, refreshButtonIconFocused), + var widget = new ImageButton(this.leftPos + 200, this.topPos + 140, 16, 16, new WidgetSprites(refreshButtonIconUnfocused, refreshButtonIconFocused), button -> { CondensedEntryRegistry.refreshEntrypoints(); - setSelectedTab(this.selectedTab); + selectTab(this.selectedTab); }, - ScreenTexts.EMPTY + CommonComponents.EMPTY ); - widget.setTooltip(Tooltip.of(Text.of("Refresh Condensed Entries"))); + widget.setTooltip(Tooltip.create(Component.nullToEmpty("Refresh Condensed Entries"))); - this.addDrawableChild(widget); + this.addRenderableWidget(widget); } //------------------------------------------------------------------------------------------------------------------------------------------------------// - @Inject(method = "getTooltipFromItem", at = @At("HEAD"), cancellable = true) - private void testToReplaceTooltipText(ItemStack stack, CallbackInfoReturnable> cir){ - var slot = ((HandledScreenAccessor)this).cc$getFocusedSlot(); + @Inject(method = "getTooltipFromContainerItem", at = @At("HEAD"), cancellable = true) + private void testToReplaceTooltipText(ItemStack stack, CallbackInfoReturnable> cir){ + var slot = ((HandledScreenAccessor)this).cc$getHoveredSlot(); - if(slot != null && slot.inventory instanceof CondensedInventory inv - && ItemEntry.areStacksEqual(slot.getStack(), stack) - && inv.getEntryStack(slot.id) instanceof CondensedItemEntry entry && !entry.isChild) { + if(slot != null && slot.container instanceof CondensedInventory inv + && ItemEntry.areStacksEqual(slot.getItem(), stack) + && inv.getEntryStack(slot.index) instanceof CondensedItemEntry entry && !entry.isChild) { - List tooltipData = new ArrayList<>(); + List tooltipData = new ArrayList<>(); - entry.getParentTooltipText(tooltipData, this.client.player, this.client.options.advancedItemTooltips ? TooltipContext.Default.ADVANCED : TooltipContext.Default.BASIC); + entry.getParentTooltipText(tooltipData, this.minecraft.player, this.minecraft.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL); cir.setReturnValue(tooltipData); } @@ -120,54 +111,57 @@ private void testToReplaceTooltipText(ItemStack stack, CallbackInfoReturnable
  • operation){ - operation.call(list, object); + @Redirect(method = "selectTab", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/NonNullList;add(Ljava/lang/Object;)Z")) + private boolean setSelectedTab$addStackToEntryList(NonNullList instance, Object o) { + this.getHandlerDuck().addToDefaultEntryList((ItemStack) o); - return this.getHandlerDuck().addToDefaultEntryList((ItemStack) object); + return true; } - - @WrapOperation(method = "setSelectedTab", at = { - @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;addAll(Ljava/util/Collection;)Z", ordinal = 0), - @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;addAll(Ljava/util/Collection;)Z", ordinal = 1)}) - private boolean setSelectedTab$addStacksToEntryList(DefaultedList list, Collection collection, Operation operation, @Local(argsOnly = true) ItemGroup group){ - operation.call(list, collection); - - if(group != Registries.ITEM_GROUP.get(ItemGroups.HOTBAR)) this.validItemGroupForCondensedEntries = true; - - return getHandlerDuck().addToDefaultEntryList((Collection) collection); +// +// @Inject(method = "setSelectedTab", at = { +// @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;add(Ljava/lang/Object;)Z", ordinal = 0, shift = At.Shift.BY, by = 2), +// @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;add(Ljava/lang/Object;)Z", ordinal = 1, shift = At.Shift.BY, by = 2)}) +// private void setSelectedTab$addStackToEntryList(ItemGroup group, CallbackInfo ci){ +// this.getHandlerDuck().addToDefaultEntryList(this.handler.itemList.get(this.handler.itemList.size() - 1)); +// } + + @Inject(method = "selectTab", at = { + @At(value = "INVOKE", target = "Lnet/minecraft/core/NonNullList;addAll(Ljava/util/Collection;)Z",ordinal = 0, shift = At.Shift.BY, by = 2), + @At(value = "INVOKE", target = "Lnet/minecraft/core/NonNullList;addAll(Ljava/util/Collection;)Z", ordinal = 1, shift = At.Shift.BY, by = 1)}) + private void setSelectedTab$addStacksToEntryList(CreativeModeTab group, CallbackInfo ci){ + this.menu.items.forEach(stack -> getHandlerDuck().addToDefaultEntryList(stack)); + + if(group != BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabsAccessor.HOTBAR())) this.validItemGroupForCondensedEntries = true; } //------------- - @Inject(method = "search", at = @At("HEAD")) + @Inject(method = "refreshSearchResults", at = @At("HEAD")) private void search$clearEntryList(CallbackInfo ci){ this.getHandlerDuck().getDefaultEntryList().clear(); } - @Inject(method = "search", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$CreativeScreenHandler;scrollItems(F)V", shift = At.Shift.BY, by = -2)) + @Inject(method = "refreshSearchResults", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/inventory/CreativeModeInventoryScreen$ItemPickerMenu;scrollTo(F)V", shift = At.Shift.BY, by = -2)) private void search$addStacksToEntryList(CallbackInfo ci){ - this.handler.itemList.forEach(stack -> this.getHandlerDuck().addToDefaultEntryList(stack)); + this.menu.items.forEach(stack -> this.getHandlerDuck().addToDefaultEntryList(stack)); } - @Inject(method = {"setSelectedTab", "search"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$CreativeScreenHandler;scrollItems(F)V")) + @Inject(method = {"selectTab", "refreshSearchResults"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/inventory/CreativeModeInventoryScreen$ItemPickerMenu;scrollTo(F)V")) private void scrollLineCountDefault(CallbackInfo ci){ this.getHandlerDuck().markEntryListDirty(); } //------------------------------------------------------------------------------------------------------------------------------------------------------// - @Inject(method = "setSelectedTab", at = @At(value = "JUMP", opcode = Opcodes.IF_ACMPNE, ordinal = 2)) - private void filterEntriesAndAddCondensedEntries(ItemGroup group, CallbackInfo ci){ + @Inject(method = "selectTab", at = @At(value = "JUMP", opcode = Opcodes.IF_ACMPNE, ordinal = 2)) + private void filterEntriesAndAddCondensedEntries(CreativeModeTab group, CallbackInfo ci){ if (!validItemGroupForCondensedEntries) return; var handler = ItemGroupVariantHandler.getHandler(group); @@ -218,21 +212,21 @@ private void filterEntriesAndAddCondensedEntries(ItemGroup group, CallbackInfo c //---------- - @Inject(method = "onMouseClick", at = @At("HEAD"), cancellable = true) - private void checkIfCondensedEntryWithinSlot(Slot slot, int slotId, int button, SlotActionType actionType, CallbackInfo ci){ - if(slot != null && slot.inventory instanceof CondensedInventory inv && inv.getEntryStack(slotId) instanceof CondensedItemEntry entry && !entry.isChild) { + @Inject(method = "slotClicked", at = @At("HEAD"), cancellable = true) + private void checkIfCondensedEntryWithinSlot(Slot slot, int slotId, int button, ClickType actionType, CallbackInfo ci){ + if(slot != null && slot.container instanceof CondensedInventory inv && inv.getEntryStack(slotId) instanceof CondensedItemEntry entry && !entry.isChild) { entry.toggleVisibility(); this.getHandlerDuck().markEntryListDirty(); - this.handler.scrollItems(this.scrollPosition); + this.menu.scrollTo(this.scrollOffs); - var maxRows = ((CreativeScreenHandlerAccessor) this.handler).callGetOverflowRows(); + var maxRows = ((CreativeScreenHandlerAccessor) this.menu).calculateRowCount(); - if(this.scrollPosition > maxRows) { - this.scrollPosition = maxRows; + if(this.scrollOffs > maxRows) { + this.scrollOffs = maxRows; - this.handler.scrollItems(this.scrollPosition); + this.menu.scrollTo(this.scrollOffs); } ci.cancel(); @@ -241,11 +235,11 @@ private void checkIfCondensedEntryWithinSlot(Slot slot, int slotId, int button, //---------- - @ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V"), index = 2) + @ModifyArg(method = "renderBg", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V"), index = 2) private int changePosForScrollBar(int y){ - int j = this.y + 18; + int j = this.topPos + 18; - float scrollPosition = this.scrollPosition/* * ((CreativeScreenHandlerAccessor) this.handler).callGetOverflowRows()*/; // Float.isFinite() + float scrollPosition = this.scrollOffs/* * ((CreativeScreenHandlerAccessor) this.handler).callGetOverflowRows()*/; // Float.isFinite() if(!Float.isFinite(scrollPosition)) scrollPosition = 0; @@ -256,55 +250,43 @@ private int changePosForScrollBar(int y){ @Unique public CreativeInventoryScreenHandlerDuck getHandlerDuck(){ - return (CreativeInventoryScreenHandlerDuck) this.handler; + return (CreativeInventoryScreenHandlerDuck) this.menu; } //------------------------------------------------------------------------------------------------------------------------------------------------------// - @Mixin(CreativeInventoryScreen.CreativeScreenHandler.class) + @Mixin(CreativeModeInventoryScreen.ItemPickerMenu.class) public static abstract class CreativeInventoryScreenHandlerMixin implements CreativeInventoryScreenHandlerDuck { - @Shadow public abstract boolean shouldShowScrollbar(); + @Shadow public abstract boolean canScroll(); - @Shadow protected abstract int getRow(float scroll); + @Shadow protected abstract int getRowIndexForScroll(float scroll); //---------------------------------------- @Unique private boolean isEntryListDirty = true; - @Unique private DefaultedList defaultEntryList = DefaultedList.of(); - @Unique private DefaultedList filteredEntryList = DefaultedList.of(); + @Unique private NonNullList defaultEntryList = NonNullList.create(); + @Unique private NonNullList filteredEntryList = NonNullList.create(); - @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$CreativeScreenHandler;scrollItems(F)V")) - private void scrollLineCount(CreativeInventoryScreen.CreativeScreenHandler instance, float position, Operation original){ + @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/inventory/CreativeModeInventoryScreen$ItemPickerMenu;scrollTo(F)V")) + private void scrollLineCount(CreativeModeInventoryScreen.ItemPickerMenu instance, float position, Operation original){ this.markEntryListDirty(); original.call(instance, position); } - @Redirect(method = "shouldShowScrollbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;size()I")) - private int redirectListSize(DefaultedList instance){ + @Redirect(method = "canScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/NonNullList;size()I")) + private int redirectListSize(NonNullList instance){ return this.filteredEntryList.size(); } - @Inject(method = "scrollItems", at = @At(value = "HEAD")) - private void setupFilterList(float position, CallbackInfo ci) { - if(this.isEntryListDirty){ - Predicate removeNonVisibleEntries = Entry::isVisible; - - this.filteredEntryList.clear(); - this.filteredEntryList.addAll(this.getDefaultEntryList().stream().filter(removeNonVisibleEntries).toList()); - - this.isEntryListDirty = false; - } - } - /** * @author Blodhgarm * @reason adjusted to use filteredEntryList instead */ @Overwrite - public void scrollItems(float position){ + public void scrollTo(float position){ if(this.isEntryListDirty){ Predicate removeNonVisibleEntries = Entry::isVisible; @@ -314,7 +296,7 @@ public void scrollItems(float position){ this.isEntryListDirty = false; } - int positionOffset = this.getRow(position); + int positionOffset = this.getRowIndexForScroll(position); //--------------------------------------------- @@ -323,9 +305,9 @@ public void scrollItems(float position){ int m = l + ((k + positionOffset) * 9); if (m >= 0 && m < this.filteredEntryList.size()) { - ((CondensedInventory)CreativeInventoryScreen.INVENTORY).setEntryStack(l + k * 9, this.filteredEntryList.get(m)); + ((CondensedInventory) CreativeModeInventoryScreenAccessor.CONTAINER()).setEntryStack(l + k * 9, this.filteredEntryList.get(m)); } else { - ((CondensedInventory)CreativeInventoryScreen.INVENTORY).setStack(l + k * 9, ItemStack.EMPTY); + ((CondensedInventory) CreativeModeInventoryScreenAccessor.CONTAINER()).setItem(l + k * 9, ItemStack.EMPTY); } } } @@ -336,14 +318,14 @@ public void scrollItems(float position){ * @reason adjusted to use filteredEntryList instead and prevent negative values */ @Overwrite - public int getOverflowRows() { - return !this.filteredEntryList.isEmpty() && this.shouldShowScrollbar() ? MathHelper.ceil((this.filteredEntryList.size() / 9F) - 5F) : 0; + public int calculateRowCount() { + return !this.filteredEntryList.isEmpty() && this.canScroll() ? Mth.ceil((this.filteredEntryList.size() / 9F) - 5F) : 0; } //---------- @Override - public DefaultedList getDefaultEntryList() { + public NonNullList getDefaultEntryList() { return this.defaultEntryList; } diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeInventoryScreenAccessor.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeInventoryScreenAccessor.java new file mode 100644 index 0000000..b1e7523 --- /dev/null +++ b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeInventoryScreenAccessor.java @@ -0,0 +1,12 @@ +package io.wispforest.condensed_creative.mixins.client; + +import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; +import net.minecraft.world.SimpleContainer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(CreativeModeInventoryScreen.class) +public interface CreativeModeInventoryScreenAccessor { + @Accessor("CONTAINER") + static SimpleContainer CONTAINER() { throw new UnsupportedOperationException(); } +} diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeTabAccessor.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeTabAccessor.java new file mode 100644 index 0000000..a1aeb69 --- /dev/null +++ b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeTabAccessor.java @@ -0,0 +1,10 @@ +package io.wispforest.condensed_creative.mixins.client; + +import net.minecraft.world.item.CreativeModeTab; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(CreativeModeTab.class) +public interface CreativeModeTabAccessor { + @Accessor("displayItemsGenerator") CreativeModeTab.DisplayItemsGenerator cc$getDisplayItemsGenerator(); +} diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeTabsAccessor.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeTabsAccessor.java new file mode 100644 index 0000000..7814d29 --- /dev/null +++ b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeModeTabsAccessor.java @@ -0,0 +1,15 @@ +package io.wispforest.condensed_creative.mixins.client; + +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.CreativeModeTabs; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(CreativeModeTabs.class) +public interface CreativeModeTabsAccessor { + @Accessor("HOTBAR") + static ResourceKey HOTBAR() { + throw new UnsupportedOperationException(); + } +} diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeScreenHandlerAccessor.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeScreenHandlerAccessor.java new file mode 100644 index 0000000..e3b99ea --- /dev/null +++ b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/CreativeScreenHandlerAccessor.java @@ -0,0 +1,10 @@ +package io.wispforest.condensed_creative.mixins.client; + +import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(CreativeModeInventoryScreen.ItemPickerMenu.class) +public interface CreativeScreenHandlerAccessor { + @Invoker("calculateRowCount") int calculateRowCount(); +} diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/HandledScreenAccessor.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/HandledScreenAccessor.java index ed75ec2..84553ac 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/HandledScreenAccessor.java +++ b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/HandledScreenAccessor.java @@ -1,14 +1,12 @@ package io.wispforest.condensed_creative.mixins.client; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.screen.slot.Slot; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.world.inventory.Slot; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -@Mixin(HandledScreen.class) +@Mixin(AbstractContainerScreen.class) public interface HandledScreenAccessor { - - @Accessor("focusedSlot") - @Nullable Slot cc$getFocusedSlot(); + @Accessor("hoveredSlot") @Nullable Slot cc$getHoveredSlot(); } diff --git a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/HandledScreenMixin.java b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/HandledScreenMixin.java index 4982d4b..d085a8b 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/mixins/client/HandledScreenMixin.java +++ b/common/src/main/java/io/wispforest/condensed_creative/mixins/client/HandledScreenMixin.java @@ -2,25 +2,25 @@ import io.wispforest.condensed_creative.entry.impl.CondensedItemEntry; import io.wispforest.condensed_creative.util.CondensedInventory; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; -@Mixin(HandledScreen.class) -public abstract class HandledScreenMixin { +@Mixin(AbstractContainerScreen.class) +public abstract class HandledScreenMixin { - @ModifyVariable(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;getStack()Lnet/minecraft/item/ItemStack;", ordinal = 0, shift = At.Shift.BY, by = 2)) - private ItemStack changeDisplayedStackIfParent(ItemStack stack, DrawContext matrices, Slot slot){ - if(slot.inventory instanceof CondensedInventory inv && inv.getEntryStack(slot.id) instanceof CondensedItemEntry entry && !entry.isChild){ - if (MinecraftClient.getInstance().world.getTime() - entry.lastTick > 40) { + @ModifyVariable(method = "renderSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/Slot;getItem()Lnet/minecraft/world/item/ItemStack;", ordinal = 0, shift = At.Shift.BY, by = 2)) + private ItemStack changeDisplayedStackIfParent(ItemStack stack, GuiGraphics matrices, Slot slot){ + if(slot.container instanceof CondensedInventory inv && inv.getEntryStack(slot.index) instanceof CondensedItemEntry entry && !entry.isChild){ + if (Minecraft.getInstance().level.getGameTime() - entry.lastTick > 40) { entry.getNextValue(); - entry.lastTick = MinecraftClient.getInstance().world.getTime(); + entry.lastTick = Minecraft.getInstance().level.getGameTime(); } return entry.getDisplayStack(); diff --git a/common/src/main/java/io/wispforest/condensed_creative/registry/CondensedEntryRegistry.java b/common/src/main/java/io/wispforest/condensed_creative/registry/CondensedEntryRegistry.java index 3909b4d..7d5674f 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/registry/CondensedEntryRegistry.java +++ b/common/src/main/java/io/wispforest/condensed_creative/registry/CondensedEntryRegistry.java @@ -4,13 +4,6 @@ import io.wispforest.condensed_creative.LoaderSpecificUtils; import io.wispforest.condensed_creative.entry.impl.CondensedItemEntry; import io.wispforest.condensed_creative.util.ItemGroupHelper; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemConvertible; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.registry.tag.TagKey; -import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; import org.slf4j.Logger; @@ -18,6 +11,13 @@ import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.Block; /** * Main Helper class to create CondensedItemEntries @@ -29,9 +29,9 @@ public final class CondensedEntryRegistry { private static final Logger LOGGER = LogUtils.getLogger(); /** - * Register your A Entry's item group using {@link CondensedItemEntry.Builder#addToItemGroup(ItemGroup)}. + * Register your A Entry's item group using {@link CondensedItemEntry.Builder#addToItemGroup(CreativeModeTab)}. * - *

    For owo ItemGroup with certain tabs use {@link CondensedItemEntry.Builder#addToItemGroup(ItemGroup, int)} to specify a certain tab index.

    + *

    For owo ItemGroup with certain tabs use {@link CondensedItemEntry.Builder#addToItemGroup(CreativeModeTab, int)} to specify a certain tab index.

    */ public static final Map> ENTRYPOINT_LOADED_ENTRIES = new HashMap<>(); @@ -41,23 +41,23 @@ public final class CondensedEntryRegistry { * Method to create A {@link CondensedItemEntry} using a Predicate * * @param identifier The Entries identifier - * @param itemConvertible The {@link ItemConvertible} being used to place the Entry within registered {@link ItemGroup} + * @param itemConvertible The {@link ItemLike} being used to place the Entry within registered {@link CreativeModeTab} * @param predicte The {@link Predicate} used to find all the children items for the created {@link CondensedItemEntry} * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder of(Identifier identifier, ItemConvertible itemConvertible, Predicate predicte){ - return of(identifier, itemConvertible.asItem().getDefaultStack(), predicte); + public static CondensedItemEntry.Builder of(ResourceLocation identifier, ItemLike itemConvertible, Predicate predicte){ + return of(identifier, itemConvertible.asItem().getDefaultInstance(), predicte); } /** * Method to create A {@link CondensedItemEntry} using a Predicate * * @param identifier The Entries identifier - * @param stack The {@link ItemStack} being used to place the Entry within the {@link ItemGroup} + * @param stack The {@link ItemStack} being used to place the Entry within the {@link CreativeModeTab} * @param predicte The predicate used to find all the children items for the created {@link CondensedItemEntry} * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder of(Identifier identifier, ItemStack stack, Predicate predicte){ + public static CondensedItemEntry.Builder of(ResourceLocation identifier, ItemStack stack, Predicate predicte){ return new CondensedItemEntry.Builder(identifier, stack, predicte, null); } @@ -67,57 +67,57 @@ public static CondensedItemEntry.Builder of(Identifier identifier, ItemStack sta * Method to create A {@link CondensedItemEntry} using a Tag * * @param identifier The Entries identifier - * @param itemConvertible The {@link ItemConvertible} being used to place the Entry within registered {@link ItemGroup} + * @param itemConvertible The {@link ItemLike} being used to place the Entry within registered {@link CreativeModeTab} * @param tagKey The {@link TagKey} used to find all the children items for the created {@link CondensedItemEntry} * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder fromTag(Identifier identifier, ItemConvertible itemConvertible, TagKey tagKey){ - return fromTag(identifier, itemConvertible.asItem().getDefaultStack(), tagKey); + public static CondensedItemEntry.Builder fromTag(ResourceLocation identifier, ItemLike itemConvertible, TagKey tagKey){ + return fromTag(identifier, itemConvertible.asItem().getDefaultInstance(), tagKey); } /** * Method to create A {@link CondensedItemEntry} using a Tag * * @param identifier The Entries identifier - * @param stack The {@link ItemStack} being used to place the Entry within the {@link ItemGroup} + * @param stack The {@link ItemStack} being used to place the Entry within the {@link CreativeModeTab} * @param tagKey The {@link TagKey} used to find all the children items for the created {@link CondensedItemEntry} * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder fromTag(Identifier identifier, ItemStack stack, TagKey tagKey){ + public static CondensedItemEntry.Builder fromTag(ResourceLocation identifier, ItemStack stack, TagKey tagKey){ return new CondensedItemEntry.Builder(identifier, stack, null, tagKey); } //---------- /** - * Use {@link #fromTag(Identifier, ItemConvertible, TagKey)}} + * Use {@link #fromTag(ResourceLocation, ItemLike, TagKey)}} */ @Deprecated(forRemoval = true) - public static CondensedItemEntry.Builder fromItemTag(Identifier identifier, ItemConvertible itemConvertible, TagKey itemTagKey){ - return fromItemTag(identifier, itemConvertible.asItem().getDefaultStack(), itemTagKey); + public static CondensedItemEntry.Builder fromItemTag(ResourceLocation identifier, ItemLike itemConvertible, TagKey itemTagKey){ + return fromItemTag(identifier, itemConvertible.asItem().getDefaultInstance(), itemTagKey); } /** - * Use {@link #fromTag(Identifier, ItemConvertible, TagKey)}} + * Use {@link #fromTag(ResourceLocation, ItemLike, TagKey)}} */ @Deprecated(forRemoval = true) - public static CondensedItemEntry.Builder fromItemTag(Identifier identifier, ItemStack stack, TagKey itemTagKey){ + public static CondensedItemEntry.Builder fromItemTag(ResourceLocation identifier, ItemStack stack, TagKey itemTagKey){ return fromTag(identifier, stack, itemTagKey); } /** - * Use {@link #fromTag(Identifier, ItemConvertible, TagKey)}} + * Use {@link #fromTag(ResourceLocation, ItemLike, TagKey)}} */ @Deprecated(forRemoval = true) - public static CondensedItemEntry.Builder fromBlockTag(Identifier identifier, ItemConvertible itemConvertible, TagKey blockTagKey){ - return fromBlockTag(identifier, itemConvertible.asItem().getDefaultStack(), blockTagKey); + public static CondensedItemEntry.Builder fromBlockTag(ResourceLocation identifier, ItemLike itemConvertible, TagKey blockTagKey){ + return fromBlockTag(identifier, itemConvertible.asItem().getDefaultInstance(), blockTagKey); } /** - * Use {@link #fromTag(Identifier, ItemConvertible, TagKey)}} + * Use {@link #fromTag(ResourceLocation, ItemLike, TagKey)}} */ @Deprecated(forRemoval = true) - public static CondensedItemEntry.Builder fromBlockTag(Identifier identifier, ItemStack stack, TagKey blockTagKey){ + public static CondensedItemEntry.Builder fromBlockTag(ResourceLocation identifier, ItemStack stack, TagKey blockTagKey){ return fromTag(identifier, stack, blockTagKey); } @@ -127,26 +127,26 @@ public static CondensedItemEntry.Builder fromBlockTag(Identifier identifier, Ite * Method to create A {@link CondensedItemEntry} using a Collection * * @param identifier The Entries identifier - * @param itemConvertible The {@link ItemConvertible} being used to place the Entry within registered {@link ItemGroup} + * @param itemConvertible The {@link ItemLike} being used to place the Entry within registered {@link CreativeModeTab} * @param collection The collection of {@link Item}'s that will be used to build the children entries for the Entry * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder fromItems(Identifier identifier, ItemConvertible itemConvertible, Collection collection){ - return fromItems(identifier, itemConvertible.asItem().getDefaultStack(), collection); + public static CondensedItemEntry.Builder fromItems(ResourceLocation identifier, ItemLike itemConvertible, Collection collection){ + return fromItems(identifier, itemConvertible.asItem().getDefaultInstance(), collection); } /** * Method to create A {@link CondensedItemEntry} using a Collection * * @param identifier The Entries identifier - * @param stack The {@link ItemStack} being used to place the Entry within the {@link ItemGroup} + * @param stack The {@link ItemStack} being used to place the Entry within the {@link CreativeModeTab} * @param collection The collection of {@link Item}'s that will be used to build the children entries for the Entry * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder fromItems(Identifier identifier, ItemStack stack, Collection collection){ + public static CondensedItemEntry.Builder fromItems(ResourceLocation identifier, ItemStack stack, Collection collection){ return fromItemStacks(identifier, stack, collection.stream() - .map(ItemConvertible::asItem) - .map(Item::getDefaultStack) + .map(ItemLike::asItem) + .map(Item::getDefaultInstance) .collect(Collectors.toList())); } @@ -156,23 +156,23 @@ public static CondensedItemEntry.Builder fromItems(I * Method to create A {@link CondensedItemEntry} using a Collection * * @param identifier The Entries identifier - * @param itemConvertible The {@link ItemConvertible} being used to place the Entry within registered {@link ItemGroup} + * @param itemConvertible The {@link ItemLike} being used to place the Entry within registered {@link CreativeModeTab} * @param collection The collection of {@link ItemStack}'s that will be used to build the children entries for the Entry * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder fromItemStacks(Identifier identifier, ItemConvertible itemConvertible, Collection collection){ - return fromItemStacks(identifier, itemConvertible.asItem().getDefaultStack(), collection); + public static CondensedItemEntry.Builder fromItemStacks(ResourceLocation identifier, ItemLike itemConvertible, Collection collection){ + return fromItemStacks(identifier, itemConvertible.asItem().getDefaultInstance(), collection); } /** * Method to create A {@link CondensedItemEntry} using a Collection * * @param identifier The Entries identifier - * @param stack The {@link ItemStack} being used to place the Entry within the {@link ItemGroup} + * @param stack The {@link ItemStack} being used to place the Entry within the {@link CreativeModeTab} * @param collection The collection of {@link ItemStack}'s that will be used to build the children entries for the Entry * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder fromItemStacks(Identifier identifier, ItemStack stack, Collection collection){ + public static CondensedItemEntry.Builder fromItemStacks(ResourceLocation identifier, ItemStack stack, Collection collection){ return new CondensedItemEntry.Builder(identifier, stack, collection); } @@ -182,23 +182,23 @@ public static CondensedItemEntry.Builder fromItemStacks(Identifier identifier, I * Method to create A {@link CondensedItemEntry} using an ItemStack List Supplier * * @param identifier The Entries identifier - * @param itemConvertible The {@link ItemConvertible} being used to place the Entry within registered {@link ItemGroup} + * @param itemConvertible The {@link ItemLike} being used to place the Entry within registered {@link CreativeModeTab} * @param entryListSupplier A supplier for a collection of ItemStacks within a List * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder ofSupplier(Identifier identifier, ItemConvertible itemConvertible, Supplier> entryListSupplier){ - return ofSupplier(identifier, itemConvertible.asItem().getDefaultStack(), entryListSupplier); + public static CondensedItemEntry.Builder ofSupplier(ResourceLocation identifier, ItemLike itemConvertible, Supplier> entryListSupplier){ + return ofSupplier(identifier, itemConvertible.asItem().getDefaultInstance(), entryListSupplier); } /** * Method to create A {@link CondensedItemEntry} using an ItemStack List Supplier * * @param identifier The Entries identifier - * @param stack The {@link ItemStack} being used to place the Entry within the {@link ItemGroup} + * @param stack The {@link ItemStack} being used to place the Entry within the {@link CreativeModeTab} * @param entryListSupplier A supplier for a collection of ItemStacks within a List * @return The created {@link CondensedItemEntry} */ - public static CondensedItemEntry.Builder ofSupplier(Identifier identifier, ItemStack stack, Supplier> entryListSupplier){ + public static CondensedItemEntry.Builder ofSupplier(ResourceLocation identifier, ItemStack stack, Supplier> entryListSupplier){ return new CondensedItemEntry.Builder(identifier, stack, entryListSupplier); } diff --git a/common/src/main/java/io/wispforest/condensed_creative/util/CondensedInventory.java b/common/src/main/java/io/wispforest/condensed_creative/util/CondensedInventory.java index a55a47e..17fff93 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/util/CondensedInventory.java +++ b/common/src/main/java/io/wispforest/condensed_creative/util/CondensedInventory.java @@ -1,30 +1,29 @@ package io.wispforest.condensed_creative.util; import io.wispforest.condensed_creative.entry.Entry; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.Inventories; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtList; -import net.minecraft.recipe.RecipeMatcher; -import net.minecraft.util.collection.DefaultedList; - import java.util.List; import java.util.stream.Collectors; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.ListTag; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.StackedContents; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; -public class CondensedInventory extends SimpleInventory { +public class CondensedInventory extends SimpleContainer { - private final DefaultedList entryStacks; + private final NonNullList entryStacks; public CondensedInventory(int size) { super(size); - this.entryStacks = DefaultedList.ofSize(size, Entry.EMPTY_ENTRY); + this.entryStacks = NonNullList.withSize(size, Entry.EMPTY_ENTRY); } @Override - public ItemStack getStack(int slot) { + public ItemStack getItem(int slot) { return slot >= 0 && slot < this.entryStacks.size() ? this.entryStacks.get(slot).getEntryStack() : ItemStack.EMPTY; } @@ -36,31 +35,31 @@ public Entry getEntryStack(int slot) { * Clears this util and return all the non-empty stacks in a list. */ @Override - public List clearToList() { + public List removeAllItems() { List list = (List)this.entryStacks.stream().filter(entry -> !entry.isEmpty()).map(Entry::getEntryStack).collect(Collectors.toList()); - this.clear(); + this.clearContent(); return list; } @Override - public ItemStack removeStack(int slot, int amount) { - ItemStack itemStack = Inventories.splitStack(getItemStackList(), slot, amount); + public ItemStack removeItem(int slot, int amount) { + ItemStack itemStack = ContainerHelper.removeItem(getItemStackList(), slot, amount); if (!itemStack.isEmpty()) { - this.markDirty(); + this.setChanged(); } return itemStack; } - public ItemStack removeItem(Item item, int count) { + public ItemStack removeItemType(Item item, int count) { ItemStack itemStack = new ItemStack(item, 0); - for(int i = this.size - 1; i >= 0; --i) { - ItemStack itemStack2 = this.getStack(i); + for(int i = this.getContainerSize() - 1; i >= 0; --i) { + ItemStack itemStack2 = this.getItem(i); if (itemStack2.getItem().equals(item)) { int j = count - itemStack.getCount(); ItemStack itemStack3 = itemStack2.split(j); - itemStack.increment(itemStack3.getCount()); + itemStack.grow(itemStack3.getCount()); if (itemStack.getCount() == count) { break; } @@ -68,18 +67,18 @@ public ItemStack removeItem(Item item, int count) { } if (!itemStack.isEmpty()) { - this.markDirty(); + this.setChanged(); } return itemStack; } @Override - public boolean canInsert(ItemStack stack) { + public boolean canAddItem(ItemStack stack) { boolean bl = false; for(ItemStack itemStack : getItemStackList()) { - if (itemStack.isEmpty() || ItemStack.canCombine(itemStack, stack) && itemStack.getCount() < itemStack.getMaxCount()) { + if (itemStack.isEmpty() || ItemStack.isSameItemSameTags(itemStack, stack) && itemStack.getCount() < itemStack.getMaxStackSize()) { bl = true; break; } @@ -89,8 +88,8 @@ public boolean canInsert(ItemStack stack) { } @Override - public ItemStack removeStack(int slot) { - ItemStack itemStack = getStack(slot); + public ItemStack removeItemNoUpdate(int slot) { + ItemStack itemStack = getItem(slot); if (itemStack.isEmpty()) { return ItemStack.EMPTY; } else { @@ -100,24 +99,24 @@ public ItemStack removeStack(int slot) { } @Override - public void setStack(int slot, ItemStack stack) { + public void setItem(int slot, ItemStack stack) { this.entryStacks.set(slot, Entry.of(stack)); - if (!stack.isEmpty() && stack.getCount() > this.getMaxCountPerStack()) { - stack.setCount(this.getMaxCountPerStack()); + if (!stack.isEmpty() && stack.getCount() > this.getMaxStackSize()) { + stack.setCount(this.getMaxStackSize()); } - this.markDirty(); + this.setChanged(); } public void setEntryStack(int slot, Entry entryStack) { this.entryStacks.set(slot, entryStack); ItemStack stack = entryStack.getEntryStack(); - if (!stack.isEmpty() && stack.getCount() > this.getMaxCountPerStack()) { - stack.setCount(this.getMaxCountPerStack()); + if (!stack.isEmpty() && stack.getCount() > this.getMaxStackSize()) { + stack.setCount(this.getMaxStackSize()); } - this.markDirty(); + this.setChanged(); } @Override @@ -132,26 +131,26 @@ public boolean isEmpty() { } @Override - public void markDirty() { - super.markDirty(); + public void setChanged() { + super.setChanged(); } @Override - public boolean canPlayerUse(PlayerEntity player) { + public boolean stillValid(Player player) { return true; } @Override - public void clear() { + public void clearContent() { this.entryStacks.clear(); - this.clear(); + this.clearContent(); } @Override - public void provideRecipeInputs(RecipeMatcher finder) { + public void fillStackedContents(StackedContents finder) { for(ItemStack itemStack : getItemStackList()) { - finder.addInput(itemStack); + finder.accountStack(itemStack); } } @@ -161,11 +160,11 @@ public String toString() { } //TODO: WHY IS THIS HERE? - public void readNbtList(NbtList nbtList) { + public void fromTag(ListTag nbtList) { for(int i = 0; i < nbtList.size(); ++i) { - ItemStack itemStack = ItemStack.fromNbt(nbtList.getCompound(i)); + ItemStack itemStack = ItemStack.of(nbtList.getCompound(i)); if (!itemStack.isEmpty()) { - this.addStack(itemStack); + this.addItem(itemStack); } } } diff --git a/common/src/main/java/io/wispforest/condensed_creative/util/ItemGroupHelper.java b/common/src/main/java/io/wispforest/condensed_creative/util/ItemGroupHelper.java index 0cc8349..c5accbd 100644 --- a/common/src/main/java/io/wispforest/condensed_creative/util/ItemGroupHelper.java +++ b/common/src/main/java/io/wispforest/condensed_creative/util/ItemGroupHelper.java @@ -1,21 +1,21 @@ package io.wispforest.condensed_creative.util; import io.wispforest.condensed_creative.compat.ItemGroupVariantHandler; -import net.minecraft.item.ItemGroup; -import net.minecraft.registry.Registries; -import net.minecraft.registry.RegistryKey; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; -public record ItemGroupHelper(ItemGroup group, int tab) { +public record ItemGroupHelper(CreativeModeTab group, int tab) { - public static ItemGroupHelper of(RegistryKey groupKey, int tab) { - ItemGroup group = Registries.ITEM_GROUP.get(groupKey); + public static ItemGroupHelper of(ResourceKey groupKey, int tab) { + CreativeModeTab group = BuiltInRegistries.CREATIVE_MODE_TAB.get(groupKey); if(group == null) throw new NullPointerException("A ItemGroup helper was attempted to be created with a RegistryKey that was not found within the ItemGroup Registry! [Key: " + groupKey.toString() + "]"); return of(group, tab); } - public static ItemGroupHelper of(ItemGroup group, int tab) { + public static ItemGroupHelper of(CreativeModeTab group, int tab) { var handler = ItemGroupVariantHandler.getHandler(group); return new ItemGroupHelper(group, handler != null && handler.isVariant(group) ? Math.max(tab, 0) : 0); diff --git a/common/src/main/resources/condensedCreativeCommon.mixins.json b/common/src/main/resources/condensedCreativeCommon.mixins.json index 3be7f60..a042b78 100644 --- a/common/src/main/resources/condensedCreativeCommon.mixins.json +++ b/common/src/main/resources/condensedCreativeCommon.mixins.json @@ -4,12 +4,13 @@ "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "mixins": [ - "CreativeScreenHandlerAccessor", - "ItemGroupAccessor", "ItemStackSetAccessor" ], "client": [ - "NbtCompoundAccessor", + "client.CreativeModeInventoryScreenAccessor", + "client.CreativeModeTabsAccessor", + "client.CreativeScreenHandlerAccessor", + "client.CreativeModeTabAccessor", "client.CreativeInventoryScreenMixin", "client.CreativeInventoryScreenMixin$CreativeInventoryScreenHandlerMixin", "client.HandledScreenAccessor", diff --git a/common/src/main/resources/condensed_creative_common.accesswidener b/common/src/main/resources/condensed_creative_common.accesswidener index ab60094..351ecf9 100644 --- a/common/src/main/resources/condensed_creative_common.accesswidener +++ b/common/src/main/resources/condensed_creative_common.accesswidener @@ -1,24 +1,17 @@ accessWidener v2 named -accessible class net/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$CreativeSlot -accessible class net/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$LockableSlot - -accessible field net/minecraft/client/gui/screen/ingame/CreativeInventoryScreen INVENTORY Lnet/minecraft/inventory/SimpleInventory; - -accessible field net/minecraft/inventory/SimpleInventory size I - -transitive-accessible field net/minecraft/item/ItemGroups BUILDING_BLOCKS Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups COLORED_BLOCKS Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups NATURAL Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups FUNCTIONAL Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups REDSTONE Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups HOTBAR Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups SEARCH Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups TOOLS Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups COMBAT Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups FOOD_AND_DRINK Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups INGREDIENTS Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups SPAWN_EGGS Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups OPERATOR Lnet/minecraft/registry/RegistryKey; -transitive-accessible field net/minecraft/item/ItemGroups INVENTORY Lnet/minecraft/registry/RegistryKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs BUILDING_BLOCKS Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs COLORED_BLOCKS Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs NATURAL_BLOCKS Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs FUNCTIONAL_BLOCKS Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs REDSTONE_BLOCKS Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs HOTBAR Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs SEARCH Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs TOOLS_AND_UTILITIES Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs COMBAT Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs FOOD_AND_DRINKS Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs INGREDIENTS Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs SPAWN_EGGS Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs OP_BLOCKS Lnet/minecraft/resources/ResourceKey; +transitive-accessible field net/minecraft/world/item/CreativeModeTabs INVENTORY Lnet/minecraft/resources/ResourceKey; diff --git a/fabric/src/main/java/io/wispforest/condensed_creative/fabric/CondensedCreativeFabric.java b/fabric/src/main/java/io/wispforest/condensed_creative/fabric/CondensedCreativeFabric.java index 0f89464..5ba2add 100644 --- a/fabric/src/main/java/io/wispforest/condensed_creative/fabric/CondensedCreativeFabric.java +++ b/fabric/src/main/java/io/wispforest/condensed_creative/fabric/CondensedCreativeFabric.java @@ -7,16 +7,15 @@ import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.item.ItemGroup; -import net.minecraft.resource.ResourceType; -import net.minecraft.util.Identifier; - +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.PackType; +import net.minecraft.world.item.CreativeModeTab; import java.util.function.Supplier; public class CondensedCreativeFabric implements ClientModInitializer { - public static ItemGroup testGroup = null; - public static Supplier createOwoItemGroup = () -> null; + public static CreativeModeTab testGroup = null; + public static Supplier createOwoItemGroup = () -> null; @Override public void onInitializeClient() { @@ -28,7 +27,7 @@ public void onInitializeClient() { //-- - ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new IdentifierCondensedEntriesLoader()); + ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new IdentifierCondensedEntriesLoader()); if(FabricLoader.getInstance().isDevelopmentEnvironment()) DebugPackLoading.init(); @@ -37,7 +36,7 @@ public void onInitializeClient() { public static class IdentifierCondensedEntriesLoader extends CondensedEntriesLoader implements IdentifiableResourceReloadListener { @Override - public Identifier getFabricId() { + public ResourceLocation getFabricId() { return CondensedCreative.createID("reload_condensed_entries"); } } diff --git a/fabric/src/main/java/io/wispforest/condensed_creative/fabric/compat/owo/OwoCompat.java b/fabric/src/main/java/io/wispforest/condensed_creative/fabric/compat/owo/OwoCompat.java index 753f97c..c83d546 100644 --- a/fabric/src/main/java/io/wispforest/condensed_creative/fabric/compat/owo/OwoCompat.java +++ b/fabric/src/main/java/io/wispforest/condensed_creative/fabric/compat/owo/OwoCompat.java @@ -3,19 +3,18 @@ import io.wispforest.condensed_creative.CondensedCreative; import io.wispforest.condensed_creative.compat.ItemGroupVariantHandler; import io.wispforest.condensed_creative.fabric.CondensedCreativeFabric; -import io.wispforest.condensed_creative.mixins.ItemGroupAccessor; +import io.wispforest.condensed_creative.mixins.client.CreativeModeTabAccessor; import io.wispforest.owo.itemgroup.Icon; import io.wispforest.owo.itemgroup.OwoItemGroup; import io.wispforest.owo.itemgroup.gui.ItemGroupTab; -import net.minecraft.block.Blocks; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemGroups; -import net.minecraft.item.Items; -import net.minecraft.registry.Registries; -import net.minecraft.registry.RegistryKey; - import java.util.List; import java.util.function.Function; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.CreativeModeTabs; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Blocks; public class OwoCompat { @@ -24,23 +23,23 @@ public static void init(){ if (CondensedCreative.isDeveloperMode()) { CondensedCreativeFabric.createOwoItemGroup = () -> { - OwoItemGroup owoItemGroup = OwoItemGroup.builder(CondensedCreative.createID("test"), () -> Icon.of(Blocks.BEDROCK.asItem().getDefaultStack())) + OwoItemGroup owoItemGroup = OwoItemGroup.builder(CondensedCreative.createID("test"), () -> Icon.of(Blocks.BEDROCK.asItem().getDefaultInstance())) .initializer(group -> { - Function, ItemGroup> func = Registries.ITEM_GROUP::get; + Function, CreativeModeTab> func = BuiltInRegistries.CREATIVE_MODE_TAB::get; addTabToList(group.tabs, group, Icon.of(Blocks.BRICKS), "building_blocks", true, (enabledFeatures, entries) -> { - ((ItemGroupAccessor) func.apply(ItemGroups.BUILDING_BLOCKS)) - .cc$getEntryCollector() + ((CreativeModeTabAccessor) func.apply(CreativeModeTabs.BUILDING_BLOCKS)) + .cc$getDisplayItemsGenerator() .accept(enabledFeatures, entries); }); addTabToList(group.tabs, group, Icon.of(Blocks.PEONY), "colored_blocks", false, (enabledFeatures, entries) -> { - ((ItemGroupAccessor) func.apply(ItemGroups.COLORED_BLOCKS)) - .cc$getEntryCollector() + ((CreativeModeTabAccessor) func.apply(CreativeModeTabs.COLORED_BLOCKS)) + .cc$getDisplayItemsGenerator() .accept(enabledFeatures, entries); }); addTabToList(group.tabs, group, Icon.of(Items.IRON_INGOT), "ingredients", false, (enabledFeatures, entries) -> { - ((ItemGroupAccessor) func.apply(ItemGroups.INGREDIENTS)) - .cc$getEntryCollector() + ((CreativeModeTabAccessor) func.apply(CreativeModeTabs.INGREDIENTS)) + .cc$getDisplayItemsGenerator() .accept(enabledFeatures, entries); }); }).build(); diff --git a/fabric/src/main/java/io/wispforest/condensed_creative/fabric/compat/owo/OwoItemGroupHandler.java b/fabric/src/main/java/io/wispforest/condensed_creative/fabric/compat/owo/OwoItemGroupHandler.java index 0f7fa8e..0eb4412 100644 --- a/fabric/src/main/java/io/wispforest/condensed_creative/fabric/compat/owo/OwoItemGroupHandler.java +++ b/fabric/src/main/java/io/wispforest/condensed_creative/fabric/compat/owo/OwoItemGroupHandler.java @@ -4,10 +4,8 @@ import io.wispforest.condensed_creative.compat.ItemGroupVariantHandler; import io.wispforest.owo.itemgroup.OwoItemGroup; import it.unimi.dsi.fastutil.ints.IntSet; -import net.minecraft.item.ItemGroup; -import net.minecraft.util.Identifier; - import java.util.Collection; +import net.minecraft.world.item.CreativeModeTab; public class OwoItemGroupHandler extends ItemGroupVariantHandler { @@ -16,12 +14,12 @@ public OwoItemGroupHandler() { } @Override - public Collection getSelectedTabs(ItemGroup group) { + public Collection getSelectedTabs(CreativeModeTab group) { return (group instanceof OwoItemGroup owoItemGroup) ? owoItemGroup.selectedTabs() : IntSet.of(-1); } @Override - public int getMaxTabs(ItemGroup group) { + public int getMaxTabs(CreativeModeTab group) { return (group instanceof OwoItemGroup owoItemGroup) ? owoItemGroup.tabs.size() : 1; } } diff --git a/fabric/src/main/java/io/wispforest/condensed_creative/fabric/mixins/client/HandledScreenMixin.java b/fabric/src/main/java/io/wispforest/condensed_creative/fabric/mixins/client/HandledScreenMixin.java index 55f8883..e5760bb 100644 --- a/fabric/src/main/java/io/wispforest/condensed_creative/fabric/mixins/client/HandledScreenMixin.java +++ b/fabric/src/main/java/io/wispforest/condensed_creative/fabric/mixins/client/HandledScreenMixin.java @@ -1,20 +1,20 @@ package io.wispforest.condensed_creative.fabric.mixins.client; import io.wispforest.condensed_creative.client.SlotRenderUtils; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(HandledScreen.class) -public abstract class HandledScreenMixin { +@Mixin(AbstractContainerScreen.class) +public abstract class HandledScreenMixin { - @Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", shift = At.Shift.BY, by = 1)) - private void renderExtraIfEntry(DrawContext context, Slot slot, CallbackInfo ci){ - SlotRenderUtils.renderExtraIfEntry((HandledScreen) (Object) this, context, slot); + @Inject(method = "renderSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;renderItemDecorations(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;IILjava/lang/String;)V", shift = At.Shift.BY, by = 1)) + private void renderExtraIfEntry(GuiGraphics context, Slot slot, CallbackInfo ci){ + SlotRenderUtils.renderExtraIfEntry((AbstractContainerScreen) (Object) this, context, slot); } } diff --git a/neoforge/src/main/java/io/wispforest/condensed_creative/neoforge/mixins/client/CreativeInventoryScreenMixin.java b/neoforge/src/main/java/io/wispforest/condensed_creative/neoforge/mixins/client/CreativeInventoryScreenMixin.java deleted file mode 100644 index 9f15e7b..0000000 --- a/neoforge/src/main/java/io/wispforest/condensed_creative/neoforge/mixins/client/CreativeInventoryScreenMixin.java +++ /dev/null @@ -1,352 +0,0 @@ -package io.wispforest.condensed_creative.neoforge.mixins.client; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import io.wispforest.condensed_creative.CondensedCreative; -import io.wispforest.condensed_creative.compat.ItemGroupVariantHandler; -import io.wispforest.condensed_creative.ducks.CreativeInventoryScreenHandlerDuck; -import io.wispforest.condensed_creative.entry.Entry; -import io.wispforest.condensed_creative.entry.impl.CondensedItemEntry; -import io.wispforest.condensed_creative.entry.impl.ItemEntry; -import io.wispforest.condensed_creative.mixins.CreativeScreenHandlerAccessor; -import io.wispforest.condensed_creative.mixins.client.HandledScreenAccessor; -import io.wispforest.condensed_creative.registry.CondensedEntryRegistry; -import io.wispforest.condensed_creative.util.CondensedInventory; -import io.wispforest.condensed_creative.util.ItemGroupHelper; -import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap; -import net.minecraft.client.gui.screen.ButtonTextures; -import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; -import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; -import net.minecraft.client.gui.tooltip.Tooltip; -import net.minecraft.client.gui.widget.TexturedButtonWidget; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemGroups; -import net.minecraft.item.ItemStack; -import net.minecraft.registry.Registries; -import net.minecraft.screen.ScreenTexts; -import net.minecraft.screen.slot.Slot; -import net.minecraft.screen.slot.SlotActionType; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.MathHelper; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.*; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; - -@Mixin(CreativeInventoryScreen.class) -public abstract class CreativeInventoryScreenMixin extends AbstractInventoryScreen { - - @Shadow @Final @Mutable public static SimpleInventory INVENTORY; - - @Shadow private static ItemGroup selectedTab; - - @Shadow private float scrollPosition; - - @Shadow protected abstract void setSelectedTab(ItemGroup group); - - //------------- - - @Unique private static final Identifier refreshButtonIconUnfocused = CondensedCreative.createID("refresh_button_unfocused"); - @Unique private static final Identifier refreshButtonIconFocused = CondensedCreative.createID("refresh_button_focused"); - - @Unique private boolean validItemGroupForCondensedEntries = false; - - //------------- - - public CreativeInventoryScreenMixin(CreativeInventoryScreen.CreativeScreenHandler screenHandler, PlayerInventory playerInventory, Text text) { - super(screenHandler, playerInventory, text); - } - - @Inject(method = "", at = @At("TAIL")) - private static void setupInventory(CallbackInfo ci){ - INVENTORY = new CondensedInventory(INVENTORY.size()); - } - - @Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/PlayerScreenHandler;addListener(Lnet/minecraft/screen/ScreenHandlerListener;)V", shift = At.Shift.BY, by = 2)) - private void addButtonRender(CallbackInfo ci){ - if(!CondensedCreative.getConfig().entryRefreshButton) return; - - var widget = new TexturedButtonWidget(this.x + 200, this.y + 140, 16, 16, new ButtonTextures(refreshButtonIconUnfocused, refreshButtonIconFocused), - button -> { - CondensedEntryRegistry.refreshEntrypoints(); - setSelectedTab(this.selectedTab); - }, - ScreenTexts.EMPTY - ); - - widget.setTooltip(Tooltip.of(Text.of("Refresh Condensed Entries"))); - - this.addDrawableChild(widget); - } - - //------------------------------------------------------------------------------------------------------------------------------------------------------// - - @Inject(method = "getTooltipFromItem", at = @At("HEAD"), cancellable = true) - private void testToReplaceTooltipText(ItemStack stack, CallbackInfoReturnable> cir){ - var slot = ((HandledScreenAccessor)this).cc$getFocusedSlot(); - - if(slot != null && slot.inventory instanceof CondensedInventory inv - && ItemEntry.areStacksEqual(slot.getStack(), stack) - && inv.getEntryStack(slot.id) instanceof CondensedItemEntry entry && !entry.isChild) { - - List tooltipData = new ArrayList<>(); - - entry.getParentTooltipText(tooltipData, this.client.player, this.client.options.advancedItemTooltips ? TooltipContext.Default.ADVANCED : TooltipContext.Default.BASIC); - - cir.setReturnValue(tooltipData); - } - } - - //------------------------------------------------------------------------------------------------------------------------------------------------------// - - @Inject(method = "setSelectedTab", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;clear()V", ordinal = 0)) - private void setSelectedTab$clearEntryList(ItemGroup group, CallbackInfo ci){ - this.getHandlerDuck().getDefaultEntryList().clear(); - - this.validItemGroupForCondensedEntries = false; - } - - @Redirect(method = "setSelectedTab", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;add(Ljava/lang/Object;)Z")) - private boolean setSelectedTab$addStackToEntryList(DefaultedList instance, Object o) { - this.getHandlerDuck().addToDefaultEntryList((ItemStack) o); - - return true; - } -// -// @Inject(method = "setSelectedTab", at = { -// @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;add(Ljava/lang/Object;)Z", ordinal = 0, shift = At.Shift.BY, by = 2), -// @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;add(Ljava/lang/Object;)Z", ordinal = 1, shift = At.Shift.BY, by = 2)}) -// private void setSelectedTab$addStackToEntryList(ItemGroup group, CallbackInfo ci){ -// this.getHandlerDuck().addToDefaultEntryList(this.handler.itemList.get(this.handler.itemList.size() - 1)); -// } - - @Inject(method = "setSelectedTab", at = { - @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;addAll(Ljava/util/Collection;)Z",ordinal = 0, shift = At.Shift.BY, by = 2), - @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;addAll(Ljava/util/Collection;)Z", ordinal = 1, shift = At.Shift.BY, by = 1)}) - private void setSelectedTab$addStacksToEntryList(ItemGroup group, CallbackInfo ci){ - this.handler.itemList.forEach(stack -> getHandlerDuck().addToDefaultEntryList(stack)); - - if(group != Registries.ITEM_GROUP.get(ItemGroups.HOTBAR)) this.validItemGroupForCondensedEntries = true; - } - - //------------- - - @Inject(method = "search", at = @At("HEAD")) - private void search$clearEntryList(CallbackInfo ci){ - this.getHandlerDuck().getDefaultEntryList().clear(); - } - - @Inject(method = "search", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$CreativeScreenHandler;scrollItems(F)V", shift = At.Shift.BY, by = -2)) - private void search$addStacksToEntryList(CallbackInfo ci){ - this.handler.itemList.forEach(stack -> this.getHandlerDuck().addToDefaultEntryList(stack)); - } - - @Inject(method = {"setSelectedTab", "search"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$CreativeScreenHandler;scrollItems(F)V")) - private void scrollLineCountDefault(CallbackInfo ci){ - this.getHandlerDuck().markEntryListDirty(); - } - - //------------------------------------------------------------------------------------------------------------------------------------------------------// - - @Inject(method = "setSelectedTab", at = @At(value = "JUMP", opcode = Opcodes.IF_ACMPNE, ordinal = 2)) - private void filterEntriesAndAddCondensedEntries(ItemGroup group, CallbackInfo ci){ - if (!validItemGroupForCondensedEntries) return; - - var handler = ItemGroupVariantHandler.getHandler(group); - - var possibleTabs = (handler != null && handler.isVariant(group)) - ? handler.getSelectedTabs(group) - : Set.of(0); - - var helpers = possibleTabs.stream() - .map(tab -> ItemGroupHelper.of(group, tab)) - .toArray(ItemGroupHelper[]::new); - - var defaultList = this.getHandlerDuck().getDefaultEntryList(); - - var indexToEntry = new Int2ObjectAVLTreeMap(Collections.reverseOrder()); - - var parentEntries = CondensedEntryRegistry.getEntryList(helpers); - - for (var condensedItemEntry : parentEntries) { - int i = defaultList.indexOf(Entry.of(condensedItemEntry.getEntryStack())); - - condensedItemEntry.initializeChildren(defaultList); - - if(condensedItemEntry.childrenEntry.isEmpty()) continue; - - if (i >= 0 && i < defaultList.size()) { - defaultList.add(i, condensedItemEntry); - } else { - defaultList.add(condensedItemEntry); - } - } - - for (var condensedItemEntry : parentEntries) { - indexToEntry.put(defaultList.indexOf(condensedItemEntry), condensedItemEntry); - } - - indexToEntry.forEach((i, condensedItemEntry) -> { - var childrenStartIndex = i + 1; - var children = List.copyOf(condensedItemEntry.childrenEntry); - - if (childrenStartIndex >= 0 && childrenStartIndex < defaultList.size()) { - defaultList.addAll(childrenStartIndex, children); - } else { - defaultList.addAll(children); - } - }); - } - - //---------- - - @Inject(method = "onMouseClick", at = @At("HEAD"), cancellable = true) - private void checkIfCondensedEntryWithinSlot(Slot slot, int slotId, int button, SlotActionType actionType, CallbackInfo ci){ - if(slot != null && slot.inventory instanceof CondensedInventory inv && inv.getEntryStack(slotId) instanceof CondensedItemEntry entry && !entry.isChild) { - entry.toggleVisibility(); - - this.getHandlerDuck().markEntryListDirty(); - - this.handler.scrollItems(this.scrollPosition); - - var maxRows = ((CreativeScreenHandlerAccessor) this.handler).callGetOverflowRows(); - - if(this.scrollPosition > maxRows) { - this.scrollPosition = maxRows; - - this.handler.scrollItems(this.scrollPosition); - } - - ci.cancel(); - } - } - - //---------- - - @ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V"), index = 2) - private int changePosForScrollBar(int y){ - int j = this.y + 18; - - float scrollPosition = this.scrollPosition/* * ((CreativeScreenHandlerAccessor) this.handler).callGetOverflowRows()*/; // Float.isFinite() - - if(!Float.isFinite(scrollPosition)) scrollPosition = 0; - - return Math.round(j + (95f * scrollPosition)); - } - - //---------- - - @Unique - public CreativeInventoryScreenHandlerDuck getHandlerDuck(){ - return (CreativeInventoryScreenHandlerDuck) this.handler; - } - - //------------------------------------------------------------------------------------------------------------------------------------------------------// - - @Mixin(CreativeInventoryScreen.CreativeScreenHandler.class) - public static abstract class CreativeInventoryScreenHandlerMixin implements CreativeInventoryScreenHandlerDuck { - - @Shadow public abstract boolean shouldShowScrollbar(); - - @Shadow protected abstract int getRow(float scroll); - - //---------------------------------------- - - @Unique private boolean isEntryListDirty = true; - - @Unique private DefaultedList defaultEntryList = DefaultedList.of(); - @Unique private DefaultedList filteredEntryList = DefaultedList.of(); - - @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/CreativeInventoryScreen$CreativeScreenHandler;scrollItems(F)V")) - private void scrollLineCount(CreativeInventoryScreen.CreativeScreenHandler instance, float position, Operation original){ - this.markEntryListDirty(); - - original.call(instance, position); - } - - @Redirect(method = "shouldShowScrollbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;size()I")) - private int redirectListSize(DefaultedList instance){ - return this.filteredEntryList.size(); - } - - @Inject(method = "scrollItems", at = @At(value = "HEAD")) - private void setupFilterList(float position, CallbackInfo ci) { - if(this.isEntryListDirty){ - Predicate removeNonVisibleEntries = Entry::isVisible; - - this.filteredEntryList.clear(); - this.filteredEntryList.addAll(this.getDefaultEntryList().stream().filter(removeNonVisibleEntries).toList()); - - this.isEntryListDirty = false; - } - } - - /** - * @author Blodhgarm - * @reason adjusted to use filteredEntryList instead - */ - @Overwrite - public void scrollItems(float position){ - if(this.isEntryListDirty){ - Predicate removeNonVisibleEntries = Entry::isVisible; - - this.filteredEntryList.clear(); - this.filteredEntryList.addAll(this.getDefaultEntryList().stream().filter(removeNonVisibleEntries).toList()); - - this.isEntryListDirty = false; - } - - int positionOffset = this.getRow(position); - - //--------------------------------------------- - - for(int k = 0; k < 5; ++k) { - for(int l = 0; l < 9; ++l) { - int m = l + ((k + positionOffset) * 9); - - if (m >= 0 && m < this.filteredEntryList.size()) { - ((CondensedInventory)CreativeInventoryScreen.INVENTORY).setEntryStack(l + k * 9, this.filteredEntryList.get(m)); - } else { - ((CondensedInventory)CreativeInventoryScreen.INVENTORY).setStack(l + k * 9, ItemStack.EMPTY); - } - } - } - } - - /** - * @author Blodhgarm - * @reason adjusted to use filteredEntryList instead and prevent negative values - */ - @Overwrite - public int getOverflowRows() { - return !this.filteredEntryList.isEmpty() && this.shouldShowScrollbar() ? MathHelper.ceil((this.filteredEntryList.size() / 9F) - 5F) : 0; - } - - //---------- - - @Override - public DefaultedList getDefaultEntryList() { - return this.defaultEntryList; - } - - @Override - public void markEntryListDirty() { - this.isEntryListDirty = true; - } - } -} diff --git a/neoforge/src/main/java/io/wispforest/condensed_creative/neoforge/mixins/client/HandledScreenMixin.java b/neoforge/src/main/java/io/wispforest/condensed_creative/neoforge/mixins/client/HandledScreenMixin.java index e1a8ed1..dc74107 100644 --- a/neoforge/src/main/java/io/wispforest/condensed_creative/neoforge/mixins/client/HandledScreenMixin.java +++ b/neoforge/src/main/java/io/wispforest/condensed_creative/neoforge/mixins/client/HandledScreenMixin.java @@ -1,20 +1,20 @@ package io.wispforest.condensed_creative.neoforge.mixins.client; import io.wispforest.condensed_creative.client.SlotRenderUtils; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(HandledScreen.class) -public abstract class HandledScreenMixin { +@Mixin(AbstractContainerScreen.class) +public abstract class HandledScreenMixin { - @Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;renderSlotContents(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/item/ItemStack;Lnet/minecraft/screen/slot/Slot;IILjava/lang/String;)V", shift = At.Shift.BY, by = 1)) - private void renderExtraIfEntry(DrawContext context, Slot slot, CallbackInfo ci){ - SlotRenderUtils.renderExtraIfEntry((HandledScreen) (Object) this, context, slot); + @Inject(method = "renderSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/inventory/AbstractContainerScreen;renderSlotContents(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/inventory/Slot;IILjava/lang/String;)V", shift = At.Shift.BY, by = 1)) + private void renderExtraIfEntry(GuiGraphics context, Slot slot, CallbackInfo ci){ + SlotRenderUtils.renderExtraIfEntry((AbstractContainerScreen) (Object) this, context, slot); } } diff --git a/settings.gradle b/settings.gradle index d139704..8c0162b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,6 +4,7 @@ pluginManagement { maven { url "https://maven.architectury.dev/" } maven { url "https://maven.minecraftforge.net/" } maven { url "https://maven.neoforged.net/releases/" } + maven { url "https://maven.parchmentmc.org" } gradlePluginPortal() }