diff --git a/src/main/java/vazkii/quark/content/client/module/ImprovedTooltipsModule.java b/src/main/java/vazkii/quark/content/client/module/ImprovedTooltipsModule.java index cfdac96175..9f6aa1284d 100644 --- a/src/main/java/vazkii/quark/content/client/module/ImprovedTooltipsModule.java +++ b/src/main/java/vazkii/quark/content/client/module/ImprovedTooltipsModule.java @@ -5,6 +5,7 @@ import com.google.common.collect.Lists; import net.minecraft.world.item.ItemStack; +import vazkii.quark.base.Quark; import vazkii.zeta.client.event.ZGatherTooltipComponents; import vazkii.zeta.event.ZConfigChanged; import vazkii.zeta.event.bus.LoadEvent; @@ -73,6 +74,11 @@ public class ImprovedTooltipsModule extends ZetaModule { public static boolean staticEnabled; + //put out here for itemstack mixin haxx required for this to work + public static boolean shouldHideAttributes() { + return staticEnabled && attributeTooltips && !Quark.proxy.isClientPlayerHoldingShift(); + } + @ZetaLoadModule(clientReplacement = true) public static class Client extends ImprovedTooltipsModule { diff --git a/src/main/java/vazkii/quark/content/client/resources/AttributeIconEntry.java b/src/main/java/vazkii/quark/content/client/resources/AttributeIconEntry.java index d88431395d..39ba15cc32 100644 --- a/src/main/java/vazkii/quark/content/client/resources/AttributeIconEntry.java +++ b/src/main/java/vazkii/quark/content/client/resources/AttributeIconEntry.java @@ -18,7 +18,6 @@ import net.minecraft.ChatFormatting; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.GsonHelper; -import vazkii.quark.content.client.resources.AttributeIconEntry.CompareType; public record AttributeIconEntry( Map displayTypes, diff --git a/src/main/java/vazkii/quark/content/client/tooltip/AttributeTooltips.java b/src/main/java/vazkii/quark/content/client/tooltip/AttributeTooltips.java index 1c889ad6df..003ad6257f 100644 --- a/src/main/java/vazkii/quark/content/client/tooltip/AttributeTooltips.java +++ b/src/main/java/vazkii/quark/content/client/tooltip/AttributeTooltips.java @@ -25,6 +25,7 @@ import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.core.Registry; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.network.chat.MutableComponent; @@ -47,9 +48,6 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.registries.ForgeRegistries; import vazkii.quark.base.Quark; import vazkii.quark.base.QuarkClient; import vazkii.quark.base.handler.MiscUtil; @@ -82,7 +80,7 @@ public static void receiveAttributes(Map map) { @Nullable private static AttributeIconEntry getIconForAttribute(Attribute attribute) { - ResourceLocation loc = ForgeRegistries.ATTRIBUTES.getKey(attribute); + ResourceLocation loc = Registry.ATTRIBUTE.getKey(attribute); if (loc != null) return attributes.get(loc); return null; } @@ -110,7 +108,6 @@ private static MutableComponent format(Attribute attribute, double value, Attrib } } - @OnlyIn(Dist.CLIENT) public static void makeTooltip(ZGatherTooltipComponents event) { ItemStack stack = event.getItemStack(); @@ -154,7 +151,7 @@ else if (slot.hasCanonicalSlot() && allAreSame && !slotAttributes.equals(baseChe } } - public static Multimap getModifiersOnEquipped(Player player, ItemStack stack, Multimap attributes, AttributeSlot slot) { + private static Multimap getModifiersOnEquipped(Player player, ItemStack stack, Multimap attributes, AttributeSlot slot) { if (ImprovedTooltipsModule.showUpgradeStatus && slot.hasCanonicalSlot()) { ItemStack equipped = player.getItemBySlot(slot.getCanonicalSlot()); if (!equipped.equals(stack) && !equipped.isEmpty()) { @@ -166,7 +163,7 @@ public static Multimap getModifiersOnEquipped(Play return ImmutableMultimap.of(); } - public static Multimap getModifiers(ItemStack stack, AttributeSlot slot) { + private static Multimap getModifiers(ItemStack stack, AttributeSlot slot) { var capturedModifiers = ((PseudoAccessorItemStack) (Object) stack).quark$getCapturedAttributes(); if (capturedModifiers.containsKey(slot)) { @@ -186,7 +183,7 @@ public static Multimap getModifiers(ItemStack stac return ImmutableMultimap.of(); } - public static boolean extractAttributeValues(ItemStack stack, Map attributeTooltips, boolean onlyInvalid, AttributeSlot slot, Multimap slotAttributes) { + private static boolean extractAttributeValues(ItemStack stack, Map attributeTooltips, boolean onlyInvalid, AttributeSlot slot, Multimap slotAttributes) { boolean anyInvalid = false; for(Attribute attr : slotAttributes.keySet()) { AttributeIconEntry entry = getIconForAttribute(attr); @@ -209,7 +206,6 @@ public static boolean extractAttributeValues(ItemStack stack, Map slotAttributes, Minecraft mc, boolean forceRenderIfZero, Multimap equippedSlotAttributes, @Nullable Set equippedAttrsToRender) { AttributeIconEntry entry = getIconForAttribute(attribute); if (entry != null) { @@ -337,12 +333,6 @@ private static double getAttribute(Player player, AttributeSlot slot, ItemStack return value; } - public static boolean shouldHideAttributes() { - return ImprovedTooltipsModule.staticEnabled && ImprovedTooltipsModule.attributeTooltips && !Quark.proxy.isClientPlayerHoldingShift(); - } - - - @OnlyIn(Dist.CLIENT) public record AttributeComponent(ItemStack stack, AttributeSlot slot) implements ClientTooltipComponent, TooltipComponent { diff --git a/src/main/java/vazkii/quark/content/client/tooltip/EnchantedBookTooltips.java b/src/main/java/vazkii/quark/content/client/tooltip/EnchantedBookTooltips.java index c418b5d935..139f5cf708 100755 --- a/src/main/java/vazkii/quark/content/client/tooltip/EnchantedBookTooltips.java +++ b/src/main/java/vazkii/quark/content/client/tooltip/EnchantedBookTooltips.java @@ -7,7 +7,6 @@ import javax.annotation.Nonnull; import com.google.common.collect.HashMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; @@ -16,6 +15,7 @@ import net.minecraft.client.gui.Font; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.core.Registry; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.resources.ResourceLocation; @@ -26,9 +26,6 @@ import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.EnchantmentInstance; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.registries.ForgeRegistries; import vazkii.quark.base.item.QuarkItem; import vazkii.quark.content.client.module.ImprovedTooltipsModule; import vazkii.quark.content.tools.item.AncientTomeItem; @@ -48,7 +45,6 @@ public static void reloaded() { testItems = null; } - @OnlyIn(Dist.CLIENT) public static void makeTooltip(ZGatherTooltipComponents event) { Minecraft mc = Minecraft.getInstance(); if(mc.player == null) @@ -87,7 +83,7 @@ public static void makeTooltip(ZGatherTooltipComponents event) { private static ItemStack BOOK; - public static List getItemsForEnchantment(Enchantment e, boolean onlyForTable) { + private static List getItemsForEnchantment(Enchantment e, boolean onlyForTable) { List list = new ArrayList<>(); for(ItemStack stack : getTestItems()) { @@ -114,7 +110,7 @@ public static List getItemsForEnchantment(Enchantment e, boolean only return list; } - public static List getEnchantedBookEnchantments(ItemStack stack) { + private static List getEnchantedBookEnchantments(ItemStack stack) { Map enchantments = EnchantmentHelper.getEnchantments(stack); List retList = new ArrayList<>(enchantments.size()); @@ -142,13 +138,12 @@ public static List getTestItems() { } private static void computeTestItems() { - testItems = Lists.newArrayList(); - - for (String loc : ImprovedTooltipsModule.enchantingStacks) { - Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(loc)); - if (item != null) - testItems.add(new ItemStack(item)); - } + testItems = ImprovedTooltipsModule.enchantingStacks.stream() + .map(ResourceLocation::new) + .map(Registry.ITEM::get) + .filter(i -> i != Items.AIR) + .map(ItemStack::new) + .toList(); } private static void computeAdditionalStacks() { @@ -162,20 +157,16 @@ private static void computeAdditionalStacks() { String left = tokens[0]; String right = tokens[1]; - Enchantment ench = ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(left)); - if(ench != null) { - tokens = right.split(","); - - for(String itemId : tokens) { - Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemId)); - if (item != null) - additionalStacks.put(ench, new ItemStack(item)); - } - } + Registry.ENCHANTMENT.getOptional(new ResourceLocation(left)) + .ifPresent(ench -> { + for(String itemId : right.split(",")) { + Registry.ITEM.getOptional(new ResourceLocation(itemId)).ifPresent(item -> + additionalStacks.put(ench, new ItemStack(item))); + } + }); } } - @OnlyIn(Dist.CLIENT) public record EnchantedBookComponent(int width, int height, Enchantment enchantment, boolean tableOnly) implements ClientTooltipComponent, TooltipComponent { diff --git a/src/main/java/vazkii/quark/content/client/tooltip/FoodTooltips.java b/src/main/java/vazkii/quark/content/client/tooltip/FoodTooltips.java index 0f47069892..79ffffa4c4 100755 --- a/src/main/java/vazkii/quark/content/client/tooltip/FoodTooltips.java +++ b/src/main/java/vazkii/quark/content/client/tooltip/FoodTooltips.java @@ -22,9 +22,6 @@ import net.minecraft.world.food.FoodProperties; import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.gui.overlay.ForgeGui; import vazkii.quark.content.client.module.ImprovedTooltipsModule; import vazkii.zeta.client.event.ZGatherTooltipComponents; @@ -39,7 +36,6 @@ private static boolean isPoison(FoodProperties food) { return false; } - @OnlyIn(Dist.CLIENT) public static void makeTooltip(ZGatherTooltipComponents event, boolean showFood, boolean showSaturation) { ItemStack stack = event.getItemStack(); if(stack.isEdible()) { @@ -90,8 +86,6 @@ else if (saturation >= 2) } } - - @OnlyIn(Dist.CLIENT) public record FoodComponent(ItemStack stack, int width, int height) implements ClientTooltipComponent, TooltipComponent { @@ -126,7 +120,7 @@ public void renderImage(@Nonnull Font font, int tooltipX, int tooltipY, @Nonnull pose.translate(0, 0, 500); RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.setShaderTexture(0, ForgeGui.GUI_ICONS_LOCATION); + RenderSystem.setShaderTexture(0, GuiComponent.GUI_ICONS_LOCATION); for (int i = 0; i < renderCount; i++) { int x = tooltipX + i * 9 - 1; diff --git a/src/main/java/vazkii/quark/content/client/tooltip/FuelTooltips.java b/src/main/java/vazkii/quark/content/client/tooltip/FuelTooltips.java index 4f59d34680..1cfb69507b 100644 --- a/src/main/java/vazkii/quark/content/client/tooltip/FuelTooltips.java +++ b/src/main/java/vazkii/quark/content/client/tooltip/FuelTooltips.java @@ -16,22 +16,19 @@ import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.ForgeHooks; +import vazkii.quark.base.Quark; import vazkii.quark.base.handler.MiscUtil; import vazkii.quark.content.client.module.ImprovedTooltipsModule; import vazkii.zeta.client.event.ZGatherTooltipComponents; public class FuelTooltips { - @OnlyIn(Dist.CLIENT) public static void makeTooltip(ZGatherTooltipComponents event) { ItemStack stack = event.getItemStack(); if(!stack.isEmpty()) { Screen screen = Minecraft.getInstance().screen; if(screen != null && screen instanceof AbstractFurnaceScreen) { - int count = ForgeHooks.getBurnTime(stack, RecipeType.SMELTING); + int count = Quark.ZETA.getBurnTime(stack, RecipeType.SMELTING); if(count > 0) { Font font = Minecraft.getInstance().font; @@ -47,9 +44,7 @@ private static String getDisplayString(int count) { String time = String.format(((items - (int) items) == 0) ? "x%.0f" : "x%.1f", items); return time; } - - - @OnlyIn(Dist.CLIENT) + public record FuelComponent(ItemStack stack, int width, int count) implements ClientTooltipComponent, TooltipComponent { @Override diff --git a/src/main/java/vazkii/quark/content/client/tooltip/MapTooltips.java b/src/main/java/vazkii/quark/content/client/tooltip/MapTooltips.java index 5c5744ec83..f28bf2d57b 100755 --- a/src/main/java/vazkii/quark/content/client/tooltip/MapTooltips.java +++ b/src/main/java/vazkii/quark/content/client/tooltip/MapTooltips.java @@ -24,8 +24,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.MapItem; import net.minecraft.world.level.saveddata.maps.MapItemSavedData; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import vazkii.quark.content.client.module.ImprovedTooltipsModule; import vazkii.zeta.client.event.ZGatherTooltipComponents; @@ -33,7 +31,6 @@ public class MapTooltips { private static final ResourceLocation RES_MAP_BACKGROUND = new ResourceLocation("textures/map/map_background.png"); - @OnlyIn(Dist.CLIENT) public static void makeTooltip(ZGatherTooltipComponents event) { ItemStack stack = event.getItemStack(); if(!stack.isEmpty() && stack.getItem() instanceof MapItem) { @@ -46,7 +43,6 @@ else if(ImprovedTooltipsModule.mapRequireShift && !Screen.hasShiftDown()) } } - @OnlyIn(Dist.CLIENT) public record MapComponent(ItemStack stack) implements ClientTooltipComponent, TooltipComponent { @Override diff --git a/src/main/java/vazkii/quark/content/client/tooltip/ShulkerBoxTooltips.java b/src/main/java/vazkii/quark/content/client/tooltip/ShulkerBoxTooltips.java index fc7128326d..7f15c52b13 100755 --- a/src/main/java/vazkii/quark/content/client/tooltip/ShulkerBoxTooltips.java +++ b/src/main/java/vazkii/quark/content/client/tooltip/ShulkerBoxTooltips.java @@ -28,8 +28,6 @@ import net.minecraft.world.level.block.ShulkerBoxBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.IItemHandler; @@ -44,7 +42,6 @@ public class ShulkerBoxTooltips { public static final ResourceLocation WIDGET_RESOURCE = new ResourceLocation("quark", "textures/misc/shulker_widget.png"); - @OnlyIn(Dist.CLIENT) public static void makeTooltip(ZGatherTooltipComponents event) { ItemStack stack = event.getItemStack(); if(SimilarBlockTypeHandler.isShulkerBox(stack)) { @@ -78,7 +75,6 @@ public static void makeTooltip(ZGatherTooltipComponents event) { } } - @OnlyIn(Dist.CLIENT) public record ShulkerComponent(ItemStack stack) implements ClientTooltipComponent, TooltipComponent { private static final int[][] TARGET_RATIOS = new int[][]{ diff --git a/src/main/java/vazkii/quark/content/tools/module/AbacusModule.java b/src/main/java/vazkii/quark/content/tools/module/AbacusModule.java index 57751c3b5f..c60f8c999e 100644 --- a/src/main/java/vazkii/quark/content/tools/module/AbacusModule.java +++ b/src/main/java/vazkii/quark/content/tools/module/AbacusModule.java @@ -41,6 +41,8 @@ public class AbacusModule extends ZetaModule { @Hint public Item abacus; + @Config RGBAColorConfig highlightColor = RGBAColorConfig.forColor(0, 0, 0, 0.4); + @LoadEvent public void register(ZRegister event) { abacus = new AbacusItem(this); @@ -49,8 +51,6 @@ public void register(ZRegister event) { @ZetaLoadModule(clientReplacement = true) public static class Client extends AbacusModule { - @Config RGBAColorConfig highlightColor = RGBAColorConfig.forColor(0, 0, 0, 0.4); - @LoadEvent public void clientSetup(ZClientSetup e) { e.enqueueWork(() -> ItemProperties.register(abacus, new ResourceLocation("count"), AbacusItem.Client::count)); diff --git a/src/main/java/vazkii/quark/mixin/ItemStackMixin.java b/src/main/java/vazkii/quark/mixin/ItemStackMixin.java index 247c2836c6..3bc3c1bfcd 100644 --- a/src/main/java/vazkii/quark/mixin/ItemStackMixin.java +++ b/src/main/java/vazkii/quark/mixin/ItemStackMixin.java @@ -28,6 +28,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import vazkii.quark.content.client.hax.PseudoAccessorItemStack; +import vazkii.quark.content.client.module.ImprovedTooltipsModule; import vazkii.quark.content.client.resources.AttributeSlot; import vazkii.quark.content.client.tooltip.AttributeTooltips; import vazkii.quark.content.management.module.ItemSharingModule; @@ -107,7 +108,7 @@ private void clearCapturedTooltip(Player player, TooltipFlag flag, CallbackInfoR @ModifyReceiver(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/Multimap;isEmpty()Z", remap = false)) private Multimap overrideAttributeTooltips(Multimap attributes, @Local EquipmentSlot slot) { - if (AttributeTooltips.shouldHideAttributes()) { + if (ImprovedTooltipsModule.shouldHideAttributes()) { capturedAttributes.put(AttributeSlot.fromCanonicalSlot(slot), LinkedHashMultimap.create(attributes)); return ImmutableMultimap.of(); } diff --git a/src/main/java/vazkii/quark/mixin/PotionUtilsMixin.java b/src/main/java/vazkii/quark/mixin/PotionUtilsMixin.java index d6601f0c5f..1c09359862 100644 --- a/src/main/java/vazkii/quark/mixin/PotionUtilsMixin.java +++ b/src/main/java/vazkii/quark/mixin/PotionUtilsMixin.java @@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import vazkii.quark.content.client.tooltip.AttributeTooltips; +import vazkii.quark.content.client.module.ImprovedTooltipsModule; import vazkii.quark.content.client.hax.PseudoAccessorItemStack; import java.util.Collections; @@ -19,7 +19,7 @@ public class PotionUtilsMixin { @ModifyVariable(method = "addPotionTooltip", at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z", ordinal = 1, shift = At.Shift.BEFORE), ordinal = 2) private static List> overrideAttributeTooltips(List> attributes, ItemStack stack) { - if (AttributeTooltips.shouldHideAttributes()) { + if (ImprovedTooltipsModule.shouldHideAttributes()) { ((PseudoAccessorItemStack) (Object) stack).quark$capturePotionAttributes(attributes); return Collections.emptyList(); } diff --git a/src/main/java/vazkii/zeta/Zeta.java b/src/main/java/vazkii/zeta/Zeta.java index ae89bae4e6..8281400ec2 100644 --- a/src/main/java/vazkii/zeta/Zeta.java +++ b/src/main/java/vazkii/zeta/Zeta.java @@ -6,6 +6,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ElytraItem; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.phys.BlockHitResult; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -107,6 +108,7 @@ public boolean canElytraFly(ItemStack stack, LivingEntity entity) { //forge has a funky little extension for this return stack.getItem() instanceof ElytraItem && ElytraItem.isFlyEnabled(stack); } + public abstract int getBurnTime(ItemStack stack, @Nullable RecipeType recipeType); // Let's Jump public abstract void start(); diff --git a/src/main/java/vazkii/zetaimplforge/ForgeZeta.java b/src/main/java/vazkii/zetaimplforge/ForgeZeta.java index ea617d3c21..3ffb46fef6 100644 --- a/src/main/java/vazkii/zetaimplforge/ForgeZeta.java +++ b/src/main/java/vazkii/zetaimplforge/ForgeZeta.java @@ -5,8 +5,10 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.phys.BlockHitResult; import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.LootTableLoadEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; @@ -111,6 +113,11 @@ public boolean fireRightClickBlock(Player player, InteractionHand hand, BlockPos return MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickBlock(player, hand, pos, bhr)); } + @Override + public int getBurnTime(ItemStack stack, @Nullable RecipeType recipeType) { + return ForgeHooks.getBurnTime(stack, recipeType); + } + @Override public boolean canElytraFly(ItemStack stack, LivingEntity entity) { return stack.canElytraFly(entity);