-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: smarter item mod name tooltip (currently not working) (close: …
- Loading branch information
Showing
4 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/snownee/jade/mixin/CreativeModeInventoryScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package snownee.jade.mixin; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
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.CallbackInfoReturnable; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.llamalad7.mixinextras.sugar.Share; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalRef; | ||
|
||
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.item.ItemStack; | ||
import snownee.jade.Jade; | ||
import snownee.jade.api.config.IWailaConfig; | ||
import snownee.jade.api.theme.IThemeHelper; | ||
import snownee.jade.util.ModIdentification; | ||
|
||
@Mixin(CreativeModeInventoryScreen.class) | ||
public class CreativeModeInventoryScreenMixin { | ||
@WrapOperation(method = "getTooltipFromContainerItem", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V")) | ||
private void jade$collectTabName( | ||
List<Component> instance, | ||
int i, | ||
Object e, | ||
Operation<Void> original, | ||
@Share("index") LocalIntRef index, | ||
@Share("names") LocalRef<List<String>> tabNames) { | ||
original.call(instance, i, e); | ||
if (!IWailaConfig.get().general().showItemModNameTooltip()) { | ||
return; | ||
} | ||
index.set(i); | ||
String tabName = ((Component) e).getString().toLowerCase(Locale.ENGLISH); | ||
if (tabNames.get() == null) { | ||
Jade.LOGGER.info("set tabName: {}", tabName); | ||
tabNames.set(Lists.newArrayList(tabName)); | ||
} else { | ||
tabNames.get().add(tabName); | ||
} | ||
} | ||
|
||
@Inject(method = "getTooltipFromContainerItem", at = @At(value = "RETURN", ordinal = 1)) | ||
private void jade$addModName( | ||
ItemStack itemStack, | ||
CallbackInfoReturnable<List<Component>> cir, | ||
@Local List<Component> tooltip, | ||
@Share("index") LocalIntRef index, | ||
@Share("names") LocalRef<List<String>> tabNames) { | ||
Jade.LOGGER.info("tabName: {}", tabNames.get()); | ||
if (!IWailaConfig.get().general().showItemModNameTooltip() || tabNames.get() == null) { | ||
return; | ||
} | ||
String modName = ModIdentification.getModName(itemStack); | ||
String modNameLower = modName.toLowerCase(Locale.ENGLISH); | ||
for (String tabName : tabNames.get()) { | ||
if (tabName.startsWith(modNameLower)) { | ||
return; | ||
} | ||
} | ||
tooltip.add(index.get(), IThemeHelper.get().modName(modName)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters