Skip to content

Commit

Permalink
Remove all distmarkers from the client module
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed Oct 28, 2023
1 parent 7ec9240 commit 08dcf17
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AttributeSlot, AttributeDisplayType> displayTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -82,7 +80,7 @@ public static void receiveAttributes(Map<String, AttributeIconEntry> 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;
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -154,7 +151,7 @@ else if (slot.hasCanonicalSlot() && allAreSame && !slotAttributes.equals(baseChe
}
}

public static Multimap<Attribute, AttributeModifier> getModifiersOnEquipped(Player player, ItemStack stack, Multimap<Attribute, AttributeModifier> attributes, AttributeSlot slot) {
private static Multimap<Attribute, AttributeModifier> getModifiersOnEquipped(Player player, ItemStack stack, Multimap<Attribute, AttributeModifier> attributes, AttributeSlot slot) {
if (ImprovedTooltipsModule.showUpgradeStatus && slot.hasCanonicalSlot()) {
ItemStack equipped = player.getItemBySlot(slot.getCanonicalSlot());
if (!equipped.equals(stack) && !equipped.isEmpty()) {
Expand All @@ -166,7 +163,7 @@ public static Multimap<Attribute, AttributeModifier> getModifiersOnEquipped(Play
return ImmutableMultimap.of();
}

public static Multimap<Attribute, AttributeModifier> getModifiers(ItemStack stack, AttributeSlot slot) {
private static Multimap<Attribute, AttributeModifier> getModifiers(ItemStack stack, AttributeSlot slot) {
var capturedModifiers = ((PseudoAccessorItemStack) (Object) stack).quark$getCapturedAttributes();

if (capturedModifiers.containsKey(slot)) {
Expand All @@ -186,7 +183,7 @@ public static Multimap<Attribute, AttributeModifier> getModifiers(ItemStack stac
return ImmutableMultimap.of();
}

public static boolean extractAttributeValues(ItemStack stack, Map<AttributeSlot, MutableComponent> attributeTooltips, boolean onlyInvalid, AttributeSlot slot, Multimap<Attribute, AttributeModifier> slotAttributes) {
private static boolean extractAttributeValues(ItemStack stack, Map<AttributeSlot, MutableComponent> attributeTooltips, boolean onlyInvalid, AttributeSlot slot, Multimap<Attribute, AttributeModifier> slotAttributes) {
boolean anyInvalid = false;
for(Attribute attr : slotAttributes.keySet()) {
AttributeIconEntry entry = getIconForAttribute(attr);
Expand All @@ -209,7 +206,6 @@ public static boolean extractAttributeValues(ItemStack stack, Map<AttributeSlot,
return onlyInvalid;
}

@OnlyIn(Dist.CLIENT)
private static int renderAttribute(PoseStack matrix, Attribute attribute, AttributeSlot slot, int x, int y, ItemStack stack, Multimap<Attribute, AttributeModifier> slotAttributes, Minecraft mc, boolean forceRenderIfZero, Multimap<Attribute, AttributeModifier> equippedSlotAttributes, @Nullable Set<Attribute> equippedAttrsToRender) {
AttributeIconEntry entry = getIconForAttribute(attribute);
if (entry != null) {
Expand Down Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -87,7 +83,7 @@ public static void makeTooltip(ZGatherTooltipComponents event) {

private static ItemStack BOOK;

public static List<ItemStack> getItemsForEnchantment(Enchantment e, boolean onlyForTable) {
private static List<ItemStack> getItemsForEnchantment(Enchantment e, boolean onlyForTable) {
List<ItemStack> list = new ArrayList<>();

for(ItemStack stack : getTestItems()) {
Expand All @@ -114,7 +110,7 @@ public static List<ItemStack> getItemsForEnchantment(Enchantment e, boolean only
return list;
}

public static List<EnchantmentInstance> getEnchantedBookEnchantments(ItemStack stack) {
private static List<EnchantmentInstance> getEnchantedBookEnchantments(ItemStack stack) {
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);

List<EnchantmentInstance> retList = new ArrayList<>(enchantments.size());
Expand Down Expand Up @@ -142,13 +138,12 @@ public static List<ItemStack> 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() {
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()) {
Expand Down Expand Up @@ -90,8 +86,6 @@ else if (saturation >= 2)
}
}


@OnlyIn(Dist.CLIENT)
public record FoodComponent(ItemStack stack, int width,
int height) implements ClientTooltipComponent, TooltipComponent {

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@
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;

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) {
Expand All @@ -46,7 +43,6 @@ else if(ImprovedTooltipsModule.mapRequireShift && !Screen.hasShiftDown())
}
}

@OnlyIn(Dist.CLIENT)
public record MapComponent(ItemStack stack) implements ClientTooltipComponent, TooltipComponent {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down Expand Up @@ -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[][]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vazkii/quark/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Attribute, AttributeModifier> overrideAttributeTooltips(Multimap<Attribute, AttributeModifier> attributes, @Local EquipmentSlot slot) {
if (AttributeTooltips.shouldHideAttributes()) {
if (ImprovedTooltipsModule.shouldHideAttributes()) {
capturedAttributes.put(AttributeSlot.fromCanonicalSlot(slot), LinkedHashMultimap.create(attributes));
return ImmutableMultimap.of();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/vazkii/quark/mixin/PotionUtilsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Pair<Attribute, AttributeModifier>> overrideAttributeTooltips(List<Pair<Attribute, AttributeModifier>> attributes, ItemStack stack) {
if (AttributeTooltips.shouldHideAttributes()) {
if (ImprovedTooltipsModule.shouldHideAttributes()) {
((PseudoAccessorItemStack) (Object) stack).quark$capturePotionAttributes(attributes);
return Collections.emptyList();
}
Expand Down
Loading

0 comments on commit 08dcf17

Please sign in to comment.