Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public final class TooltipOverlay {
public static float hoverTicks;
private static ItemStack lastItemStack = ItemStack.EMPTY;
private static boolean liftAboveGoggle;
public static void register(@NotNull RegisterGuiLayersEvent event) {
event.registerAbove(VanillaGuiLayers.HOTBAR, getCCGRes("tooltip_overlay"), TooltipOverlay::renderOverlay);
}
Expand All @@ -49,6 +50,8 @@ public static void renderOverlay(GuiGraphics gui, DeltaTracker deltaTracker) {
}
hoverTicks = Math.min(8, hoverTicks + getRealtimeDeltaTicks());
lastItemStack = itemStack;
// 锁存"是否抬到目镜信息上方",使淡出期间保持在偏移后的位置,而非随护目镜层的 hoverTicks 提前落回原位
liftAboveGoggle = GoggleOverlayRenderer.hoverTicks > 0;
renderItemStack(gui, itemStack);
}
public static @NotNull ItemStack toRenderItemStack() {
Expand Down Expand Up @@ -91,8 +94,8 @@ public static void renderItemStack(@NotNull GuiGraphics gui, @NotNull ItemStack
tooltipWidth = Math.max(tooltipWidth, component.getWidth(mc.font));
tooltipHeight += component.getHeight();
}
var goggleFade = Mth.clamp(GoggleOverlayRenderer.hoverTicks / 24F, 0, 1);
if (goggleFade > 0) y -= (int) ((tooltipHeight + 10) * goggleFade);
// 物品悬浮框淡入淡出全程停留在该偏移位置
if (liftAboveGoggle) y -= tooltipHeight + 10;
x = Mth.clamp(x, 0, width - tooltipWidth);
y = Mth.clamp(y, 16, height - tooltipHeight - 100);
renderTooltip(gui, itemStack, components, x, y, tooltipWidth, tooltipHeight, back.getRGB(), top.getRGB(), bot.getRGB());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static io.github.forgestove.create_cyber_goggles.core.util.CCGUtil.*;
@Mixin(GoggleOverlayRenderer.class)
public abstract class GoggleOverlayRendererMixin {
@Unique private static BlockHitResult ccg$lastBlockHitResult;
@Unique private static HitResult ccg$lastHitResult;
@Inject(method = "renderOverlay", at = @At("HEAD"), cancellable = true)
private static void renderOverlay(CallbackInfo ci) {
if (!CCG.config.goggles.disableInScreenGoggles || isInGame()) return;
Expand Down Expand Up @@ -106,22 +106,25 @@ private static HitResult keepHitDuringFadeOut(HitResult original) {
if (original instanceof BlockHitResult bhr && bhr.getType() == Type.BLOCK && mc.level != null) {
var be = mc.level.getBlockEntity(bhr.getBlockPos());
if (be instanceof IHaveGoggleInformation || be instanceof IHaveHoveringInformation) {
ccg$lastBlockHitResult = bhr;
ccg$lastHitResult = bhr;
return original;
}
// 非渲染方块:淡出时返回缓存的上一个渲染方块
return ccg$isFadingOut() && ccg$lastBlockHitResult != null ? ccg$lastBlockHitResult : original;
} else if (original instanceof EntityHitResult ehr && ehr.getEntity() instanceof IHaveGoggleInformation) {
//放置在地面的实现目镜信息接口的实体
ccg$lastHitResult = ehr;
return original;
}
return ccg$isFadingOut() && ccg$lastBlockHitResult != null ? ccg$lastBlockHitResult : original;
// 非渲染目标:淡出时返回缓存的上一个渲染目标
return ccg$isFadingOut() && ccg$lastHitResult != null ? ccg$lastHitResult : original;
}
@Unique
private static boolean ccg$isFadingOut() {
if (!CCG.config.goggles.enableFadeOut) return false;
var hit = mc.hitResult;
if (hit instanceof BlockHitResult bhr && bhr.getType() == Type.BLOCK && mc.level != null) {
var be = mc.level.getBlockEntity(bhr.getBlockPos());
if (be instanceof IHaveGoggleInformation || be instanceof IHaveHoveringInformation) return false; // 当前方块会渲染 tooltip
}
if (be instanceof IHaveGoggleInformation || be instanceof IHaveHoveringInformation) return false;
} else if (hit instanceof EntityHitResult ehr && ehr.getEntity() instanceof IHaveGoggleInformation) return false;
return GoggleOverlayRenderer.hoverTicks > 0; // 无有效 tooltip 且之前有渲染 → 淡出
}
@ModifyExpressionValue(method = "renderOverlay", at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z", ordinal = 1))
Expand Down
Loading