Skip to content
Open
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
6 changes: 6 additions & 0 deletions gradle/scripts/moddevgradle.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ neoForge {
}
}
}

tasks.configureEach {
if (name in ['runClient', 'runServer', 'runGameTestServer', 'runData']) {
notCompatibleWithConfigurationCache("IntelliJ debugger injects non-cacheable actions into Minecraft run tasks")
}
}
4 changes: 3 additions & 1 deletion src/generated/resources/assets/ageratum/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
"key.category.ageratum.key": "ɯnʇɐɹǝᵷⱯ",
"system.ageratum.share.button": "[NƎԀO O⟘ ꞰƆIꞀƆ]",
"system.ageratum.share.tip": ":noʎ ɥʇᴉʍ ǝpᴉnᵷ ɐ pǝɹɐɥs sɐɥ %s ɹǝʎɐꞁԀ",
"tooltip.ageratum.bind_item_hold": "oɟuᴉ ǝɹoɯ ʇǝᵷ oʇ %s pꞁoH"
"tooltip.ageratum.bind_item_hold": "oɟuᴉ ǝɹoɯ ʇǝᵷ oʇ %s pꞁoH",
"tooltip.ageratum.structure_projection.layer_shortcut": "sɹǝʎɐꞁ uoᴉʇɔǝɾoɹd ʇsnɾpɐ oʇ %s / %s ssǝɹԀ",
"tooltip.ageratum.structure_projection.remove_shortcut": "uoᴉʇɔǝɾoɹd ǝsoꞁɔ oʇ %s ssǝɹԀ"
}
4 changes: 3 additions & 1 deletion src/generated/resources/assets/ageratum/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
"key.category.ageratum.key": "Ageratum",
"system.ageratum.share.button": "[CLICK TO OPEN]",
"system.ageratum.share.tip": "Player %s has shared a guide with you:",
"tooltip.ageratum.bind_item_hold": "Hold %s to get more info"
"tooltip.ageratum.bind_item_hold": "Hold %s to get more info",
"tooltip.ageratum.structure_projection.layer_shortcut": "Press %s / %s to adjust projection layers",
"tooltip.ageratum.structure_projection.remove_shortcut": "Press %s to close projection"
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,46 @@ public static boolean openGuideOnClient(Identifier location, List<Identifier> br
return openGuideOnClient(location, null, breadCrumbs);
}

/**
* 从侧边栏打开文档,保留当前标签栏滚动和折叠状态。
*/
public static boolean openGuideOnClientPreservingLabelState(Identifier location, List<Identifier> breadCrumbs) {
return openGuideOnClientInternal(location, null, breadCrumbs, true);
}

/**
* 客户端本地打开文档,可选指定锚点;若不存在则返回 false。
*
* @param location 文档资源位置
* @param anchor 目标锚点(可为 null)
*/
public static boolean openGuideOnClient(Identifier location, @Nullable String anchor, List<Identifier> breadCrumbs) {
return openGuideOnClientInternal(location, anchor, breadCrumbs, false);
}

private static boolean openGuideOnClientInternal(
Identifier location,
@Nullable String anchor,
List<Identifier> breadCrumbs,
boolean preserveLabelState
) {
if (isPreviewLocation(location)) {
return openPreviewGuideOnClient(location, anchor, breadCrumbs);
return openPreviewGuideOnClient(location, anchor, breadCrumbs, preserveLabelState);
}

Minecraft minecraft = Minecraft.getInstance();
GuideScreen currentGuideScreen = null;
if (minecraft.screen instanceof GuideScreen guideScreen) {
currentGuideScreen = guideScreen;
}
ResourceManager resourceManager = minecraft.getResourceManager();
if (!GuideDocumentLoader.exists(resourceManager, location)) {
return false;
}

int inheritedLabelScrollRows = 0;
double inheritedLabelScrollRemainder = 0.0d;
if (minecraft.screen instanceof GuideScreen currentGuideScreen) {
if (currentGuideScreen != null) {
inheritedLabelScrollRows = currentGuideScreen.getLabelScrollRows();
inheritedLabelScrollRemainder = currentGuideScreen.getLabelScrollRemainder();
}
Expand All @@ -201,6 +221,9 @@ public static boolean openGuideOnClient(Identifier location, @Nullable String an
GuideScreen screen = new GuideScreen(location, cachedDocument.get(), breadCrumbs, false);
screen.setAnchor(anchor);
screen.setLabelScrollState(inheritedLabelScrollRows, inheritedLabelScrollRemainder);
if (preserveLabelState && currentGuideScreen != null) {
screen.setLabelStatePreserved(currentGuideScreen);
}
minecraft.setScreen(screen);
return true;
}
Expand All @@ -213,6 +236,8 @@ public static boolean openGuideOnClient(Identifier location, @Nullable String an
minecraft,
inheritedLabelScrollRows,
inheritedLabelScrollRemainder,
currentGuideScreen,
preserveLabelState,
content,
false
);
Expand All @@ -221,17 +246,22 @@ public static boolean openGuideOnClient(Identifier location, @Nullable String an
private static boolean openPreviewGuideOnClient(
Identifier location,
@Nullable String anchor,
List<Identifier> breadCrumbs
List<Identifier> breadCrumbs,
boolean preserveLabelState
) {
Minecraft minecraft = Minecraft.getInstance();
GuideScreen currentGuideScreen = null;
if (minecraft.screen instanceof GuideScreen guideScreen) {
currentGuideScreen = guideScreen;
}
Path previewFile = resolvePreviewDocumentPath(location);
if (!Files.isRegularFile(previewFile)) {
return false;
}

int inheritedLabelScrollRows = 0;
double inheritedLabelScrollRemainder = 0.0d;
if (minecraft.screen instanceof GuideScreen currentGuideScreen) {
if (currentGuideScreen != null) {
inheritedLabelScrollRows = currentGuideScreen.getLabelScrollRows();
inheritedLabelScrollRemainder = currentGuideScreen.getLabelScrollRemainder();
}
Expand All @@ -251,6 +281,8 @@ private static boolean openPreviewGuideOnClient(
minecraft,
inheritedLabelScrollRows,
inheritedLabelScrollRemainder,
currentGuideScreen,
preserveLabelState,
content,
true
);
Expand All @@ -263,13 +295,18 @@ private static boolean parseDocumentAndSetScreen(
Minecraft minecraft,
int inheritedLabelScrollRows,
double inheritedLabelScrollRemainder,
@Nullable GuideScreen currentGuideScreen,
boolean preserveLabelState,
String content,
boolean preview
) {
MDDocument parsedDocument = new MarkdownParser().parseDocument(location, content);
GuideScreen screen = new GuideScreen(location, parsedDocument, breadCrumbs, preview);
screen.setAnchor(anchor);
screen.setLabelScrollState(inheritedLabelScrollRows, inheritedLabelScrollRemainder);
if (preserveLabelState && currentGuideScreen != null) {
screen.setLabelStatePreserved(currentGuideScreen);
}
minecraft.setScreen(screen);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ public class AgeratumClientConfig {

@Comment("The scaling ratio of the interface")
@BoundedDiscrete(min = 1, max = 4)
public int scale = 1;
public int scale = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static int itemCommand(CommandContext<CommandSourceStack> context) {
Component message = Component.literal(itemId.toString())
.withStyle(style -> style.withColor(0xFF66CCFF)
.withUnderlined(true)
.withClickEvent(new ClickEvent.CopyToClipboard(refString))
.withClickEvent(new ClickEvent.CopyToClipboard(itemId.toString()))
.withHoverEvent(new HoverEvent.ShowText(
Component.translatable("commands.ageratum.item.id_copy_hint")
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.gui.screens.inventory.tooltip.DefaultTooltipPositioner;
import net.minecraft.network.chat.Component;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemStack;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -65,14 +62,26 @@ public MDRenderContext child(int maxX, int maxY, float mouseX, float mouseY, int
}

public void addTooltip(ItemStack stack) {
this.tooltips.add(new Tooltip(Screen.getTooltipFromItem(Minecraft.getInstance(), stack), stack.getTooltipImage()));
this.tooltips.add(new Tooltip(
Screen.getTooltipFromItem(Minecraft.getInstance(), stack),
stack.getTooltipImage(),
stack
));
}

public void addTooltip(Component text) {
this.tooltips.add(new Tooltip(List.of(text), Optional.empty()));
this.addTooltip(List.of(text));
}

public record Tooltip(List<Component> tooltipLines, Optional<TooltipComponent> visualTooltipComponent) {
public void addTooltip(List<Component> lines) {
this.tooltips.add(new Tooltip(lines, Optional.empty(), ItemStack.EMPTY));
}

public record Tooltip(
List<Component> tooltipLines,
Optional<TooltipComponent> visualTooltipComponent,
ItemStack stack
) {
}

public void enableScissor(int minX, int minY, int maxX, int maxY) {
Expand All @@ -89,17 +98,29 @@ public void onEnd(BiConsumer<GuideScreen, MDRenderContext> consumer) {

public void extractTooltipRenderState() {
for (MDRenderContext.Tooltip tooltip : this.tooltips()) {
List<ClientTooltipComponent> list = new ArrayList<>();
tooltip.tooltipLines().forEach(component -> list.add(ClientTooltipComponent.create(component.getVisualOrderText())));
tooltip.visualTooltipComponent().ifPresent(component -> list.add(ClientTooltipComponent.create(component)));
this.graphics().tooltip(
this.minecraft().font,
list,
Math.round(this.mouseX()),
Math.round(this.mouseY()),
DefaultTooltipPositioner.INSTANCE,
null
);
ItemStack stack = tooltip.stack();
int mouseX = Math.round(this.mouseX());
int mouseY = Math.round(this.mouseY());
if (stack.isEmpty()) {
this.graphics()
.setTooltipForNextFrame(
this.minecraft().font,
tooltip.tooltipLines(),
tooltip.visualTooltipComponent(),
mouseX,
mouseY
);
} else {
this.graphics()
.setTooltipForNextFrame(
this.minecraft().font,
tooltip.tooltipLines(),
tooltip.visualTooltipComponent(),
stack,
mouseX,
mouseY
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.anvilcraft.resource.ageratum.client.feat.markdown.component.extend;

import dev.anvilcraft.lib.v2.font.AnvilLibFont;
import dev.anvilcraft.resource.ageratum.client.AgeratumClient;
import dev.anvilcraft.resource.ageratum.client.feat.markdown.GuideDocumentCache;
import dev.anvilcraft.resource.ageratum.client.feat.markdown.MDExtensionContext;
import dev.anvilcraft.resource.ageratum.client.feat.markdown.MDRenderContext;
import dev.anvilcraft.resource.ageratum.client.feat.markdown.component.MDComponent;
Expand All @@ -26,6 +28,7 @@
import net.minecraft.world.level.block.state.properties.Property;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
Expand All @@ -43,6 +46,7 @@ public class MDBlockComponent extends MDImageComponent {
private final boolean showText;
private final ViewportCameraRig cameraRig = new ViewportCameraRig();
private @Nullable BlockState blockState;
private @Nullable Identifier hoveredDocLink;
private @Nullable SandboxRenderLevel sandboxRenderLevel;

public MDBlockComponent(Identifier blockLoc, Map<String, String> stateProps, boolean showText) {
Expand Down Expand Up @@ -94,7 +98,7 @@ private void extractBlockRenderState(MDRenderContext context, float mouseX, floa

ItemStack tooltipStack = state.getBlock().asItem().getDefaultInstance();
if (!tooltipStack.isEmpty()) {
this.extractTooltipRenderState(context, tooltipStack, 8, 8, mouseX, mouseY);
this.renderBlockItem(context, tooltipStack, 8, 8, mouseX, mouseY);
}

if (this.showText) {
Expand All @@ -104,6 +108,42 @@ private void extractBlockRenderState(MDRenderContext context, float mouseX, floa
}
}

/**
* 渲染方块物品 tooltip,并检查文档绑定;W 键提示由 tooltip 事件统一注入。
*/
private void renderBlockItem(MDRenderContext context, ItemStack stack, int startX, int startY, float mouseX, float mouseY) {
if (this.isHoverItem(startX, startY, mouseX, mouseY)) {
context.addTooltip(stack);
// W 键提示由 BoundItemGuideNavigator 通过 RenderTooltipEvent 注入,这里只记录跳转目标。
GuideDocumentCache.getFirstDocumentByItemStack(
stack,
AgeratumClient.getClientLanguageCode(context.minecraft())
).ifPresentOrElse(
doc -> this.hoveredDocLink = doc,
() -> this.hoveredDocLink = null
);
}
}

@Override
public boolean keyPressed(
Minecraft minecraft,
double mouseX,
double mouseY,
int keyCode,
int scanCode,
int modifiers,
int maxX
) {
if (this.hoveredDocLink != null
&& keyCode == dev.anvilcraft.resource.ageratum.client.AgeratumKeyMappings.W_KEY_MAPPING.getKey().getValue()) {
AgeratumClient.openGuideOnClient(this.hoveredDocLink, List.of());
return true;
}
return false;
}


protected @Nullable BlockState getBlockState() {
if (this.blockState != null) return this.blockState;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dev.anvilcraft.resource.ageratum.client.feat.markdown.component.extend;
import net.minecraft.network.chat.Component;

import com.mojang.brigadier.StringReader;
import dev.anvilcraft.lib.v2.font.AnvilLibFont;
Expand Down Expand Up @@ -163,6 +164,19 @@ private void renderButton(MDRenderContext context) {
AgeratumConstants.GuideScreenUI.Positions.STRUCTURE_BUTTON_WIDTH,
32
);
if (isHover) {
context.addTooltip(List.of(
Component.translatable(
"tooltip.ageratum.structure_projection.layer_shortcut",
Component.keybind("key.ageratum.structure_projection.layer_up"),
Component.keybind("key.ageratum.structure_projection.layer_down")
),
Component.translatable(
"tooltip.ageratum.structure_projection.remove_shortcut",
Component.keybind("key.ageratum.structure_projection.remove")
)
));
}
}

@Override
Expand Down
Loading