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

Commit

Permalink
fix: item analysis not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Commander07 committed Oct 9, 2023
1 parent eae8097 commit 61c56c2
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public class NBTPrinterMixin {
protected Slot focusedSlot;
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawForeground(Lnet/minecraft/client/gui/DrawContext;II)V"))
public void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
/*if (focusedSlot != null && focusedSlot.hasStack()){
*//*ItemStack item = focusedSlot.getStack();
List<Text> tooltip = item.getTooltip(MinecraftClient.getInstance().player, TooltipContext.Default.NORMAL);
for (Text text : tooltip) {
System.out.println(text.getString());
}*//*
}*/
// if (focusedSlot != null && focusedSlot.hasStack()){
// ItemStack item = focusedSlot.getStack();
// List<Text> tooltip = item.getTooltip(MinecraftClient.getInstance().player, TooltipContext.Default.BASIC);
// for (Text text : tooltip) {
// System.out.println(text.getString());
// }
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import io.github.nbcss.wynnlib.Settings;
import io.github.nbcss.wynnlib.function.AnalyzeMode;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.item.TooltipData;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -18,19 +22,24 @@
import java.util.List;
import java.util.Optional;

@Mixin(DrawContext.class)
@Mixin(HandledScreen.class)
public abstract class InventoryAnalysisMixin {
@Inject(method = "drawItemTooltip", at = @At("HEAD"), cancellable = true)
public void drawTooltip(TextRenderer textRenderer, ItemStack stack, int x, int y, CallbackInfo ci){
if(stack != null && Settings.INSTANCE.getOption(Settings.SettingOption.ANALYZE_MODE)){
List<Text> tooltip = AnalyzeMode.INSTANCE.getAnalyzeResult(stack);
if (tooltip != null) {
drawTooltip(textRenderer, tooltip, stack.getTooltipData(), x, y);
ci.cancel();

@Shadow @Nullable protected Slot focusedSlot;
@Shadow @Final protected ScreenHandler handler;

@Inject(method = "drawMouseoverTooltip", at = @At("HEAD"), cancellable = true)
public void drawTooltip(DrawContext context, int x, int y, CallbackInfo ci){
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
if (this.handler.getCursorStack().isEmpty() && this.focusedSlot != null && this.focusedSlot.hasStack()) {
ItemStack stack = this.focusedSlot.getStack();
if(stack != null && Settings.INSTANCE.getOption(Settings.SettingOption.ANALYZE_MODE)){
List<Text> tooltip = AnalyzeMode.INSTANCE.getAnalyzeResult(stack);
if (tooltip != null) {
context.drawTooltip(textRenderer, tooltip, stack.getTooltipData(), x, y);
ci.cancel();
}
}
}
}

@Shadow
public abstract void drawTooltip(TextRenderer textRenderer, List<Text> lines, Optional<TooltipData> data, int x, int y);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ItemStack onModifyItem(ItemStack stack) {
return stack;
ItemLoadEvent event = new ItemLoadEvent(stack);
ItemLoadEvent.Companion.handleEvent(event);
String name = stack.getName().toString();
String name = stack.getName().getString();
Matcher matcher = SPELL_PATTERN.matcher(name);
if (matcher.find()) {
Collection<Ability> abilities = AbilityRegistry.INSTANCE.fromDisplayName(matcher.group(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ class PriceProperty: AnalysisProperty {
override fun set(tooltip: List<Text>, line: Int): Int {
if (priceTooltip != null)
return 0
if (tooltip[line].toString().isNotEmpty() || tooltip[line].siblings.isEmpty())
if (tooltip[line].string.isNotEmpty() || tooltip[line].siblings.isEmpty())
return 0
val siblings = tooltip[line].siblings
if (siblings[0].toString() == "Price:" && siblings[0].style.color.toString() == "gold") {
if (siblings[0].string == "Price:" && siblings[0].style.color?.name == "gold") {
var i = 1
val priceTooltip: MutableList<Text> = mutableListOf()
priceTooltip.add(tooltip[line])
while (line + i < tooltip.size) {
val text1 = tooltip[line + i]
if (text1.toString().isNotEmpty() || text1.siblings.isEmpty())
if (text1.string.isNotEmpty() || text1.siblings.isEmpty())
break
val text2 = text1.siblings[0]
if (text2.toString().isNotEmpty() || text2.siblings.isEmpty())
if (text2.string.isNotEmpty() || text2.siblings.isEmpty())
break
val text3 = text2.siblings[0]
if (text3.toString() == " - " && text3.style.color.toString() == "gold") {
if (text3.string == " - " && text3.style.color?.name == "gold") {
priceTooltip.add(text1)
}else{
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ class IdentificationProperty: AnalysisProperty {
return 0
val base = tooltip[line].siblings[0]
//stop further read stats if it from set bonus
if (base.toString() == "Set Bonus:")
if (base.string == "Set Bonus:")
terminated = true
if (base.toString() != "" || base.siblings.size < 2)
if (base.string == "" || base.siblings.size < 2)
return 0
val matcher = ID_VALUE_PATTERN.matcher(base.siblings[0].toString().trim())
val matcher = ID_VALUE_PATTERN.matcher(base.siblings[0].string.trim())
if (matcher.find()) {
val value = matcher.group(1).toInt()
val suffix = matcher.group(2)
val idName = base.siblings.last().toString()
val idName = base.siblings.last().string
Identification.fromSuffixName(suffix, idName)?.let { id ->
idMap[id] = value
if (base.siblings.size > 2){
val stars = base.siblings[1].toString().chars().filter { it.toChar() == '*' }.count()
val stars = base.siblings[1].string.chars().filter { it.toChar() == '*' }.count()
starMap[id] = stars.toInt()
}
return 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class MajorIdProperty: AnalysisProperty {
if (base.siblings.isEmpty())
return 0
if (base.siblings[0].style.color == TextColor.fromFormatting(Formatting.AQUA)) {
val matcher = MAJOR_ID_PATTERN.matcher(base.siblings[0].toString())
val matcher = MAJOR_ID_PATTERN.matcher(base.siblings[0].string)
if (matcher.find()) {
MajorId.fromDisplayName(matcher.group(1))?.let {
majorIds.add(it)
val majorIdTooltip = mutableListOf(tooltip[line])
for(i in (line + 1 until tooltip.size)) {
if (tooltip[i].toString() == ""
if (tooltip[i].string == ""
&& tooltip[i].siblings.isNotEmpty()
&& tooltip[i].siblings[0].style.color == TextColor.fromFormatting(Formatting.DARK_AQUA)){
majorIdTooltip.add(tooltip[i])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ class PowderProperty: AnalysisProperty {
if (tooltip[line].siblings.isEmpty())
return 0
val base = tooltip[line].siblings[0]
val baseString = base.toString()
val baseString = base.string
val matcher = if (baseString != "") {
POWDER_PATTERN.matcher(baseString)
}else if(base.siblings.isNotEmpty()){
POWDER_PATTERN.matcher(base.siblings[0].toString())
POWDER_PATTERN.matcher(base.siblings[0].string)
}else{
return 0
}
if(matcher.find()) {
powderSlots = matcher.group(1).toInt()
powders.clear()
for (i in (1 until base.siblings.size - 1)){
Element.fromIcon(base.siblings[i].toString().trim())?.let {
Element.fromIcon(base.siblings[i].string.trim())?.let {
powders.add(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PowderSpecialProperty: AnalysisProperty {
val base = text.siblings[0]
if (base.siblings.size < 2)
return null
return base.siblings[1].toString()
return base.siblings[1].string
}

private fun readValue(text: Text, pattern: Pattern): Double {
Expand All @@ -60,7 +60,7 @@ class PowderSpecialProperty: AnalysisProperty {
if (tooltip[line].siblings.isEmpty())
return 0
val base = tooltip[line].siblings[0]
val matcher = SPEC_NAME_PATTERN.matcher(base.toString())
val matcher = SPEC_NAME_PATTERN.matcher(base.string)
if(matcher.find()){
FACTORY_MAP[matcher.group(1)]?.let { factory ->
val result = factory.read(tooltip, line + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class RequirementProperty: AnalysisProperty {
if (tooltip[line].siblings.isEmpty())
return 0
val base = tooltip[line].siblings[0]
if (base.toString() != "" || base.siblings.size != 2)
if (base.siblings.size != 2)
return 0
val text = base.siblings[1].toString()
val flag = base.siblings[0].toString() == Symbol.TICK.icon
val text = base.siblings[1].string
val flag = base.siblings[0].string == Symbol.TICK.icon
run {
val matcher = LEVEL_PATTERN.matcher(text)
if (matcher.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RestrictionProperty: AnalysisProperty {
return 0
val base = tooltip[line].siblings[0]
if (base.style.color == TextColor.fromFormatting(Formatting.RED)) {
Restriction.fromDisplayName(base.toString())?.let {
Restriction.fromDisplayName(base.string)?.let {
restriction = it
return 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class SuffixProperty: AnalysisProperty {
if (tier != null || tooltip[line].siblings.isEmpty())
return 0
val base = tooltip[line].siblings[0]
if(base.toString() == "")
if(base.string == "")
return 0
val matcher = PATTERN.matcher(base.toString())
val matcher = PATTERN.matcher(base.string)
if (matcher.find()){
Tier.fromId(matcher.group(1))?.let {
tier = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class WeaponProperty(private val equipment: RolledEquipment):
return 0
val base = tooltip[line].siblings[0]
if (attackSpeed == null && base.siblings.isEmpty()) {
AttackSpeed.fromDisplayName(base.toString())?.let {
AttackSpeed.fromDisplayName(base.string)?.let {
attackSpeed = it
return 1
}
}
run {
val matcher = DAMAGE_PATTERN.matcher(base.toString())
val matcher = DAMAGE_PATTERN.matcher(base.string)
if (matcher.find()) {
val lower = matcher.group(1).toInt()
val upper = matcher.group(2).toInt()
Expand All @@ -91,8 +91,8 @@ class WeaponProperty(private val equipment: RolledEquipment):
}
if (base.siblings.size == 2){
//matches elem damage
Element.fromDisplayName(base.siblings[0].toString())?.let { elem ->
val matcher = ELEM_DAMAGE_PATTERN.matcher(base.siblings[1].toString())
Element.fromDisplayName(base.siblings[0].string)?.let { elem ->
val matcher = ELEM_DAMAGE_PATTERN.matcher(base.siblings[1].string)
if (matcher.find()) {
val lower = matcher.group(1).toInt()
val upper = matcher.group(2).toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ class WearableProperty(private val equipment: RolledEquipment):
}

override fun set(tooltip: List<Text>, line: Int): Int {
if (tooltip[line].toString() != "" || tooltip[line].siblings.isEmpty())
if (tooltip[line].string == "" || tooltip[line].siblings.isEmpty())
return 0
val base = tooltip[line].siblings[0]
val baseString = base.toString()
val baseString = base.string
if (baseString != ""){
val matcher = HEALTH_PATTERN.matcher(baseString)
if(matcher.find()){
health = matcher.group(1).toInt()
return 1
}
}else if(base.siblings.size == 2){
Element.fromDisplayName(base.siblings[0].toString())?.let {
val matcher = DEFENCE_PATTERN.matcher(base.siblings[1].toString())
if (matcher.find()){
elemDefence[it] = matcher.group(1).toInt()
} else if(base.siblings.size == 2){
Element.fromDisplayName(base.siblings[0].string)?.let {
val matcher = DEFENCE_PATTERN.matcher(base.siblings[1].string)
if (matcher.find()){
elemDefence[it] = matcher.group(1).toInt()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ object EmeraldPouchBarRender: EventHandler<RenderItemOverrideEvent> {
}
}
}
println("$capacity, $emeralds")
if (capacity > 0) {
val bar = MathHelper.clamp(emeralds / capacity.toDouble(), 0.0, 1.0)
ItemModifier.putDouble(event.item, key, bar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object EquipmentItemMatcher: ItemMatcher {
if (tooltip.asSequence()
.filter { it.siblings.isNotEmpty() }
.map { it.siblings[0] }
.any { it.toString().contains(eq.getTier().displayName) }) return eq
.any { it.string.contains(eq.getTier().displayName) }) return eq
}
}
tooltip.asSequence()
Expand All @@ -32,7 +32,7 @@ object EquipmentItemMatcher: ItemMatcher {
innerIt = it.siblings[0]
}
val tier = tierMap[innerIt.style.color] ?: return@next
if ("${tier.name.lowercase()} " in innerIt.toString().lowercase()){
if ("${tier.name.lowercase()} " in innerIt.string.lowercase()){
return UnknownItem(tier)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface ItemMatcher {
}
val tooltip = item.getTooltip(MinecraftClient.getInstance().player, TooltipContext.Default.BASIC)
//market item
var name = item.name.toString()
var name = item.name.string
var inMarket = false
if (name.endsWith("\u00C0")) {
name = name.substring(0, name.length - 1)
Expand Down

0 comments on commit 61c56c2

Please sign in to comment.