Proxy demo:TitleScreen 与工作台 CraftingScreen
package demo;
import link.botwmcs.fizzy.Fizzy;
import link.botwmcs.fizzy.proxy.api.KernelAttachSpec;
import link.botwmcs.fizzy.proxy.api.KernelUiSpec;
import link.botwmcs.fizzy.proxy.api.TooltipPolicy;
import link.botwmcs.fizzy.proxy.rule.ProxyBuildContext;
import link.botwmcs.fizzy.proxy.rule.ProxyRule;
import link.botwmcs.fizzy.proxy.runtime.ScreenProxyRuntime;
import link.botwmcs.fizzy.ui.background.BgType;
import link.botwmcs.fizzy.ui.element.background.FizzyBackgroundElement;
import link.botwmcs.fizzy.ui.element.button.VanillaLikeButtonElement;
import link.botwmcs.fizzy.ui.pad.PixelPadSpec;
import link.botwmcs.fizzy.ui.pad.SlotPadSpec;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import java.util.List;
public final class DemoProxyRules {
private DemoProxyRules() {}
public static void registerAll() {
var registry = ScreenProxyRuntime.instance().ruleRegistry();
registry.register(new TitleScreenRule());
registry.register(new CraftingScreenRule());
}
private static final class TitleScreenRule implements ProxyRule {
private static final ResourceLocation ID =
ResourceLocation.fromNamespaceAndPath(Fizzy.MODID, "demo/title_buttons");
@Override
public ResourceLocation id() {
return ID;
}
@Override
public int priority() {
return 100;
}
@Override
public boolean matches(ProxyBuildContext context) {
return context.screen() instanceof TitleScreen;
}
@Override
public KernelAttachSpec build(ProxyBuildContext context) {
int w = context.geometry().rootWidth();
int x = Math.max(8, w - 140);
var docsBtn = VanillaLikeButtonElement.builder(btn -> {
}).text(Component.literal("Docs")).build();
var newsBtn = VanillaLikeButtonElement.builder(btn -> {
}).text(Component.literal("News")).build();
KernelUiSpec uiSpec = KernelUiSpec.builder()
.addPad(new PixelPadSpec(x, 40, 120, 20, List.of(docsBtn)))
.addPad(new PixelPadSpec(x, 66, 120, 20, List.of(newsBtn)))
.build();
return new KernelAttachSpec(uiSpec, null, TooltipPolicy.BOTH, null);
}
}
private static final class CraftingScreenRule implements ProxyRule {
private static final ResourceLocation ID =
ResourceLocation.fromNamespaceAndPath(Fizzy.MODID, "demo/crafting_overlay");
@Override
public ResourceLocation id() {
return ID;
}
@Override
public int priority() {
return 200;
}
@Override
public boolean matches(ProxyBuildContext context) {
if (!(context.screen() instanceof AbstractContainerScreen<?> screen)) {
return false;
}
// 工作台界面(原版类名通常是 CraftingScreen)
return screen.getClass().getName().endsWith(".CraftingScreen");
}
@Override
public KernelAttachSpec build(ProxyBuildContext context) {
int rootW = context.geometry().rootWidth();
var helpButton = VanillaLikeButtonElement.builder(btn -> {
})
.text(Component.literal("Recipe+"))
.build();
KernelUiSpec uiSpec = KernelUiSpec.builder()
.addPad(new PixelPadSpec(Math.max(4, rootW - 86), 6, 80, 16, List.of(helpButton)))
// 用 slot 坐标高亮第一行区域
.addPad(new SlotPadSpec(1, 1, 1, 3, true, List.of(new FizzyBackgroundElement(BgType.PURE_GRAY))))
.build();
return new KernelAttachSpec(uiSpec, null, null, null);
}
}
}客户端初始化时注册:
DemoProxyRules.registerAll();Last updated on