Skip to content

Commit

Permalink
Update dependencies & compat latest wthit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrix-Shen committed Jul 14, 2022
1 parent c546dd7 commit 59992f8
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 69 deletions.
13 changes: 13 additions & 0 deletions src/main/java/top/hendrixshen/tweakmyclient/TweakMyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import top.hendrixshen.magiclib.dependency.annotation.Dependencies;
import top.hendrixshen.magiclib.dependency.annotation.Dependency;
import top.hendrixshen.tweakmyclient.config.ConfigHandler;
import top.hendrixshen.tweakmyclient.config.Configs;
import top.hendrixshen.tweakmyclient.event.RenderHandler;
Expand All @@ -23,6 +25,17 @@ public static Logger getLogger() {
return logger;
}

@Dependencies(
//#if MC >= 11900
and = @Dependency(value = "wthit", versionPredicate = ">=5.6.1", optional = true)
//#elseif MC >= 11800
//$$ and = @Dependency(value = "wthit", versionPredicate = ">=4.11.0", optional = true)
//#elseif MC >= 11700
//$$ and = @Dependency(value = "wthit", versionPredicate = ">=3.11.3", optional = true)
//#elseif MC >= 11600
//$$ and = @Dependency(value = "wthit", versionPredicate = ">=2.10.15", optional = true)
//#endif
)
@Override
public void onInitializeClient() {
ConfigHandler configHandler = TweakMyClientReference.getConfigHandler();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package top.hendrixshen.tweakmyclient.mixin.patch.litematicaSchematicWAILACompat;

//#if MC >= 11700
import mcp.mobius.waila.hud.ClientTickHandler;
//#if MC >= 11900
import mcp.mobius.waila.gui.hud.TooltipHandler;
//#elseif MC >= 11700
//$$ import mcp.mobius.waila.hud.ClientTickHandler;
//#else
//$$ import net.minecraft.client.Minecraft;
//#endif
Expand All @@ -16,7 +18,11 @@
import top.hendrixshen.tweakmyclient.util.WthitUtil;

@Dependencies(and = @Dependency(value = "wthit"))
@Mixin(value = ClientTickHandler.class, remap = false)
//#endif
//#if MC >= 11900
@Mixin(value = TooltipHandler.class, remap = false)
//#elseif MC >= 11700
//$$ @Mixin(value = ClientTickHandler.class, remap = false)
//#else
//$$ @Mixin(Minecraft.class)
//#endif
Expand Down
180 changes: 122 additions & 58 deletions src/main/java/top/hendrixshen/tweakmyclient/util/WthitUtil.java
Original file line number Diff line number Diff line change
@@ -1,71 +1,72 @@
package top.hendrixshen.tweakmyclient.util;

//#if MC >= 11600
import fi.dy.masa.litematica.util.RayTraceUtils;
import fi.dy.masa.litematica.world.SchematicWorldHandler;
import mcp.mobius.waila.Waila;
//#if MC >= 11800
//#if MC >= 11900
import mcp.mobius.waila.access.DataAccessor;
//#endif
//#if MC >= 11700
import mcp.mobius.waila.api.IBlacklistConfig;
import mcp.mobius.waila.api.IBlockComponentProvider;
//#endif
import mcp.mobius.waila.api.TooltipPosition;
import mcp.mobius.waila.api.WailaConstants;
//#if MC >= 11700
import mcp.mobius.waila.config.PluginConfig;
import mcp.mobius.waila.config.WailaConfig;
//#else
import mcp.mobius.waila.gui.hud.ComponentHandler;
import mcp.mobius.waila.gui.hud.Line;
import mcp.mobius.waila.gui.hud.Tooltip;
import mcp.mobius.waila.gui.hud.TooltipRenderer;
import net.minecraft.world.level.block.entity.BlockEntity;
//#elseif MC >= 11800
//$$ import mcp.mobius.waila.access.DataAccessor;
//$$ import mcp.mobius.waila.api.IBlacklistConfig;
//$$ import mcp.mobius.waila.api.IBlockComponentProvider;
//$$ import mcp.mobius.waila.config.PluginConfig;
//$$ import mcp.mobius.waila.config.WailaConfig;
//$$ import mcp.mobius.waila.hud.ComponentHandler;
//$$ import mcp.mobius.waila.hud.Line;
//$$ import mcp.mobius.waila.hud.Tooltip;
//$$ import mcp.mobius.waila.hud.TooltipHandler;
//$$ import net.minecraft.world.level.block.entity.BlockEntity;
//#elseif MC >= 11700
//$$ import mcp.mobius.waila.data.DataAccessor;
//$$ import mcp.mobius.waila.api.IBlacklistConfig;
//$$ import mcp.mobius.waila.api.IBlockComponentProvider;
//$$ import mcp.mobius.waila.config.PluginConfig;
//$$ import mcp.mobius.waila.config.WailaConfig;
//$$ import mcp.mobius.waila.hud.ComponentHandler;
//$$ import mcp.mobius.waila.hud.Tooltip;
//$$ import mcp.mobius.waila.hud.TooltipHandler;
//$$ import net.minecraft.network.chat.Component;
//$$ import net.minecraft.world.level.block.entity.BlockEntity;
//#elseif MC >= 11600
//$$ import mcp.mobius.waila.api.impl.config.PluginConfig;
//$$ import mcp.mobius.waila.api.impl.config.WailaConfig;
//#endif
//#if MC < 11800
//#if MC >= 11700
//$$ import mcp.mobius.waila.data.DataAccessor;
//#endif
//#endif
//#if MC >= 11700
import mcp.mobius.waila.hud.ComponentHandler;
//#endif
//#if MC >= 11800
import mcp.mobius.waila.hud.Line;
//#endif
//#if MC >= 11700
import mcp.mobius.waila.hud.Tooltip;
import mcp.mobius.waila.hud.TooltipHandler;
//#else
//$$ import mcp.mobius.waila.overlay.ComponentProvider;
//$$ import mcp.mobius.waila.overlay.DataAccessor;
//$$ import mcp.mobius.waila.overlay.Tooltip;
//$$ import mcp.mobius.waila.utils.TaggableList;
//$$ import mcp.mobius.waila.utils.TaggedText;
//$$ import net.minecraft.world.item.ItemStack;
//$$ import net.minecraft.network.chat.Component;
//$$ import java.util.List;
//#endif
import fi.dy.masa.litematica.util.RayTraceUtils;
import fi.dy.masa.litematica.world.SchematicWorldHandler;
import mcp.mobius.waila.Waila;
import mcp.mobius.waila.api.TooltipPosition;
import mcp.mobius.waila.api.WailaConstants;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
//#if MC < 11800
//$$ import net.minecraft.network.chat.Component;
//#endif
//#if MC < 11700
//$$ import net.minecraft.world.item.ItemStack;
//#endif
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import top.hendrixshen.magiclib.compat.minecraft.network.chat.ComponentCompatApi;
import top.hendrixshen.magiclib.language.I18n;
import top.hendrixshen.tweakmyclient.TweakMyClient;

import java.lang.reflect.Field;
//#if MC < 11700
//$$ import java.util.List;
//#endif
import java.util.Objects;
//#endif

public class WthitUtil {
//#if MC >= 11600
//#if MC >= 11700
Expand All @@ -79,36 +80,69 @@ public class WthitUtil {
//$$ private static final Component SNEAK_DETAIL = ComponentCompatApi.literal(I18n.get("tooltip.waila.sneak_for_details")).withStyle(ChatFormatting.ITALIC);
//#endif
private static final Minecraft minecraft = TweakMyClient.getMinecraftClient();
private static Field shouldRender;
//#if MC >= 11900
private static Field STATE;
//#else
//$$ private static Field shouldRender;
//#endif

private static boolean disableWthitRender = false;

static {
try {
//#if MC >= 11700
shouldRender = Class.forName("mcp.mobius.waila.hud.TooltipHandler").getDeclaredField("shouldRender");
//#if MC >= 11900
STATE = Class.forName("mcp.mobius.waila.gui.hud.TooltipHandler").getDeclaredField("STATE");
STATE.setAccessible(true);
//#elseif MC >= 11700
//$$ shouldRender = Class.forName("mcp.mobius.waila.hud.TooltipHandler").getDeclaredField("shouldRender");
//$$ shouldRender.setAccessible(true);
//#else
//$$ shouldRender = Class.forName("mcp.mobius.waila.overlay.Tooltip").getDeclaredField("shouldRender");
//$$ shouldRender.setAccessible(true);
//#endif
shouldRender.setAccessible(true);

} catch (NoSuchFieldException | ClassNotFoundException ignore) {
}
}

private static void setShouldRender(boolean shouldRender) {
//#if MC >= 11900
private static TooltipRenderer.State getState() {
try {
WthitUtil.shouldRender.set(null, shouldRender);
return (TooltipRenderer.State) WthitUtil.STATE.get(null);
} catch (IllegalAccessException ignore) {
return null;
}
}

private static void setStateRender(boolean bl) {
try {
Class<?> clz = Class.forName("mcp.mobius.waila.gui.hud.TooltipHandler$ConfigTooltipRendererState");
Field render = clz.getDeclaredField("render");
render.setAccessible(true);
render.set(WthitUtil.getState(), bl);
} catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException ignore) {
}
}
//#else
//$$ private static void setShouldRender(boolean shouldRender) {
//$$ try {
//$$ WthitUtil.shouldRender.set(null, shouldRender);
//$$ } catch (IllegalAccessException ignore) {
//$$ }
//$$ }
//#endif

public static boolean shouldDisableWthitRender() {
return WthitUtil.disableWthitRender;
}

public static void tick() {
// Check reflect.
if (shouldRender != null) {
//#if MC >= 11900
if (WthitUtil.STATE != null) {
//#else
//$$ if (shouldRender != null) {
//#endif
if (minecraft.level != null && minecraft.cameraEntity != null) {
RayTraceUtils.RayTraceWrapper traceWrapper = RayTraceUtils.getGenericTrace(minecraft.level, minecraft.cameraEntity, 10.0, true, true, true);
Level worldSchematic = SchematicWorldHandler.getSchematicWorld();
Expand All @@ -125,8 +159,10 @@ public static void tick() {
//$$ WailaConfig config = Waila.CONFIG.get();
//#endif
accessor.set(minecraft.level, localPlayer, traceWrapper.getBlockHitResult(), minecraft.cameraEntity, minecraft.getFrameTime());
//#if MC >= 11700
TooltipHandler.beginBuild();
//#if MC >= 11900
TooltipRenderer.beginBuild(WthitUtil.getState());
//#elseif MC >= 11700
//$$ TooltipHandler.beginBuild();
//#else
//$$ Tooltip.start();
//#endif
Expand Down Expand Up @@ -176,7 +212,11 @@ public static void tick() {
WthitUtil.TOOLTIP.clear();
//#if MC >= 11700
ComponentHandler.gatherBlock(accessor, WthitUtil.TOOLTIP, TooltipPosition.HEAD);
TooltipHandler.add(WthitUtil.TOOLTIP);
//#if MC >= 11900
TooltipRenderer.add(WthitUtil.TOOLTIP);
//#else
//$$ TooltipHandler.add(WthitUtil.TOOLTIP);
//#endif
//#else
//$$ ComponentProvider.gatherBlock(accessor, WthitUtil.TOOLTIP, TooltipPosition.HEAD);
//$$ Tooltip.addLines(WthitUtil.TOOLTIP);
Expand All @@ -194,14 +234,18 @@ public static void tick() {
//#else
//$$ if (Waila.CONFIG.get().getGeneral().shouldShiftForDetails() && !TOOLTIP.isEmpty() && !minecraft.player.isShiftKeyDown()) {
//#endif
//#if MC >= 11700
TooltipHandler.add(WthitUtil.SNEAK_DETAIL);
//#if MC >= 11900
TooltipRenderer.add(WthitUtil.SNEAK_DETAIL);
//#elseif MC >= 11700
//$$ TooltipHandler.add(WthitUtil.SNEAK_DETAIL);
//#else
//$$ Tooltip.addLine(WthitUtil.SNEAK_DETAIL);
//#endif
} else {
//#if MC >= 11700
TooltipHandler.add(WthitUtil.TOOLTIP);
//#if MC >= 11900
TooltipRenderer.add(WthitUtil.TOOLTIP);
//#elseif MC >= 11700
//$$ TooltipHandler.add(WthitUtil.TOOLTIP);
//#else
//$$ Tooltip.addLines(WthitUtil.TOOLTIP);
//#endif
Expand All @@ -210,17 +254,29 @@ public static void tick() {
WthitUtil.TOOLTIP.clear();
//#if MC >= 11700
ComponentHandler.gatherBlock(accessor, WthitUtil.TOOLTIP, TooltipPosition.TAIL);
TooltipHandler.add(WthitUtil.TOOLTIP);
//#if MC >= 11900
TooltipRenderer.add(WthitUtil.TOOLTIP);
//#else
//$$ TooltipHandler.add(WthitUtil.TOOLTIP);
//#endif
//#else
//$$ ComponentProvider.gatherBlock(accessor, WthitUtil.TOOLTIP, TooltipPosition.TAIL);
//$$ Tooltip.addLines(WthitUtil.TOOLTIP);
//#endif

WthitUtil.setShouldRender(true);
//#if MC >= 11900
WthitUtil.setStateRender(true);
//#else
//$$ WthitUtil.setShouldRender(true);
//#endif

//#if MC >= 11800
if (PluginConfig.INSTANCE.getBoolean(WailaConstants.CONFIG_SHOW_ICON)) {
TooltipHandler.setIcon(ComponentHandler.getIcon(Objects.requireNonNull(traceWrapper.getBlockHitResult())));
//#if MC >= 11900
TooltipRenderer.setIcon(ComponentHandler.getIcon(Objects.requireNonNull(traceWrapper.getBlockHitResult())));
//#else
//$$ TooltipHandler.setIcon(ComponentHandler.getIcon(Objects.requireNonNull(traceWrapper.getBlockHitResult())));
//#endif
//#elseif MC >= 11700
//$$ if (PluginConfig.INSTANCE.getBoolean(WailaConstants.CONFIG_SHOW_ITEM)) {
//$$ TooltipHandler.setStack(ComponentHandler.getDisplayItem(Objects.requireNonNull(traceWrapper.getBlockHitResult())));
Expand All @@ -229,16 +285,24 @@ public static void tick() {
//$$ Tooltip.setStack(new ItemStack(state.getBlock()));
//#endif
}
//#if MC >= 11700
TooltipHandler.endBuild();
//#if MC >= 11900
WthitUtil.setStateRender(true);
TooltipRenderer.endBuild();
//#elseif MC >= 11700
//$$ WthitUtil.setShouldRender(true);
//$$ TooltipHandler.endBuild();
//#else
//$$ WthitUtil.setShouldRender(true);
//$$ Tooltip.finish();
//#endif
WthitUtil.setShouldRender(true);
}
} else {
WthitUtil.disableWthitRender = false;
WthitUtil.setShouldRender(false);
//#if MC >= 11900
WthitUtil.setStateRender(false);
//#else
//$$ WthitUtil.setShouldRender(false);
//#endif
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions versions/1.16.5/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ minecraft_dependency=1.16.x
# Compatible Libraries
# Litematica - 0.0.0-dev.20210917.192300
litematica_version = 3542567
# Wthit - 2.10.14
wthit_version = 3791287
# Wthit - 2.10.15
wthit_version = 3831594
4 changes: 2 additions & 2 deletions versions/1.17.1/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ minecraft_dependency=1.17.x
# Compatible Libraries
# Litematica - 0.9.0
litematica_version = 3580241
# Wthit - 4.10.3
wthit_version = 3522154
# Wthit - 3.11.3
wthit_version = 3831607
4 changes: 2 additions & 2 deletions versions/1.18.2/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ minecraft_dependency=1.18.x
badpackets_version = 3773641
# Litematica - 0.11.2
litematica_version = 3751645
# Wthit - 4.10.3
wthit_version = 3791303
# Wthit - 4.11.0
wthit_version = 3834227
4 changes: 2 additions & 2 deletions versions/1.19/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ fabric_version = 0.55.2+1.19
badpackets_version = 3773641
# Litematica - 0.11.2
litematica_version = 3751645
# Wthit - 5.1.3
wthit_version = 3822179
# Wthit - 5.6.1
wthit_version = 3873747

0 comments on commit 59992f8

Please sign in to comment.