-
Notifications
You must be signed in to change notification settings - Fork 3
fan 界面和渲染的若干问题 #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
luqin2007
wants to merge
13
commits into
SinoCraftProject:main
Choose a base branch
from
luqin2007:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fan 界面和渲染的若干问题 #73
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9e06ea3
feat: 事件:HUD 渲染前
luqin2007 c003be5
fix: 光标移动
luqin2007 0d9dd66
clean codes
luqin2007 7705f0f
feat: 增加了一堆 todo
luqin2007 c999316
fix: 修复几个 server 端类加载问题
luqin2007 6abcd6d
feat: move GUI render event to RenderEventImpl
luqin2007 3bc76aa
fix: Fabric 端 AfterBake 事件无效
luqin2007 1769552
feat: key
luqin2007 d04a5b7
feat: 手中渲染扇子文本
luqin2007 48a8318
feat: 扇子 HUD 显示开关
luqin2007 dc30be9
fix: client init 时间
luqin2007 271b541
fix: 为啥 rebase 会丢文件
luqin2007 d79987b
remove: fan hud
luqin2007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
...obrush-fabric/src/main/java/games/moegirl/sinocraft/sinobrush/fabric/SinoBrushFabric.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,17 @@ | ||
| package games.moegirl.sinocraft.sinobrush.fabric; | ||
|
|
||
| import games.moegirl.sinocraft.sinobrush.SinoBrush; | ||
| import games.moegirl.sinocraft.sinobrush.client.SinoBrushClient; | ||
| import net.fabricmc.api.EnvType; | ||
| import net.fabricmc.api.ModInitializer; | ||
| import net.fabricmc.loader.api.FabricLoader; | ||
|
|
||
| public class SinoBrushFabric implements ModInitializer { | ||
| @Override | ||
| public void onInitialize() { | ||
| SinoBrush.init(); | ||
| if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { | ||
| SinoBrushClient.initClient(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
sinobrush/src/generated/resources/.cache/0ef3df785a7f94cfbffdf71a30a0892f6d385df3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| // 1.21.1 2025-02-09T20:04:55.8755727 Languages: zh_cn for mod: sinobrush | ||
| // 1.21.1 2025-03-31T20:36:40.5956544 Languages: zh_cn for mod: sinobrush | ||
| 6703a6ffc6e71681f6d65c55cb784e22cb94850f assets/sinobrush/lang/zh_cn.json |
2 changes: 1 addition & 1 deletion
2
sinobrush/src/generated/resources/.cache/a8fcf7feab4b002651f8845bb8733436a9644e8d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| // 1.21.1 2025-02-09T20:04:55.8755727 Languages: zh_hk for mod: sinobrush | ||
| // 1.21.1 2025-03-31T20:36:40.5966567 Languages: zh_hk for mod: sinobrush | ||
| f3ff30daf5943879fc1a4304e7e4b7ac07684e89 assets/sinobrush/lang/zh_hk.json |
2 changes: 1 addition & 1 deletion
2
sinobrush/src/generated/resources/.cache/c9e6904cd53920642cfd601a942b3aed84069064
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| // 1.21.1 2025-02-09T20:04:55.8755727 Languages: en_us for mod: sinobrush | ||
| // 1.21.1 2025-03-31T20:36:40.5976555 Languages: en_us for mod: sinobrush | ||
| 65cd216d17e9e5917d0fafad74b16723c52b622a assets/sinobrush/lang/en_us.json |
2 changes: 1 addition & 1 deletion
2
sinobrush/src/generated/resources/.cache/ed04c204adf5a1b37ba6904801511276adad4ec4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| // 1.21.1 2025-02-09T20:04:55.8710529 Languages: zh_tw for mod: sinobrush | ||
| // 1.21.1 2025-03-31T20:36:40.5946554 Languages: zh_tw for mod: sinobrush | ||
| 3b79d66cd21b4c4e859c0b2bbdf380ff563ce216 assets/sinobrush/lang/zh_tw.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
sinobrush/src/main/java/games/moegirl/sinocraft/sinobrush/client/FanRenderer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| package games.moegirl.sinocraft.sinobrush.client; | ||
|
|
||
| import com.mojang.blaze3d.vertex.PoseStack; | ||
| import games.moegirl.sinocraft.sinobrush.SinoBrush; | ||
| import games.moegirl.sinocraft.sinobrush.item.FanItem; | ||
| import games.moegirl.sinocraft.sinobrush.item.SBRItems; | ||
| import games.moegirl.sinocraft.sinocore.gui.widgets.WidgetLoader; | ||
| import games.moegirl.sinocraft.sinocore.gui.widgets.Widgets; | ||
| import games.moegirl.sinocraft.sinocore.gui.widgets.entry.TextureEntry; | ||
| import net.minecraft.Util; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.gui.Font; | ||
| import net.minecraft.client.gui.GuiGraphics; | ||
| import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; | ||
| import net.minecraft.client.renderer.MultiBufferSource; | ||
| import net.minecraft.client.renderer.block.model.ItemTransform; | ||
| import net.minecraft.client.renderer.entity.ItemRenderer; | ||
| import net.minecraft.client.resources.model.BakedModel; | ||
| import net.minecraft.client.resources.model.ModelResourceLocation; | ||
| import net.minecraft.network.chat.Component; | ||
| import net.minecraft.resources.ResourceLocation; | ||
| import net.minecraft.world.item.ItemDisplayContext; | ||
| import net.minecraft.world.item.ItemStack; | ||
| import org.apache.logging.log4j.util.Lazy; | ||
| import org.joml.Matrix4f; | ||
|
|
||
| import java.util.EnumSet; | ||
| import java.util.List; | ||
|
|
||
| public class FanRenderer extends BlockEntityWithoutLevelRenderer { | ||
|
|
||
| public static final int MAX_DISPLAY_LINES = 21; | ||
| public static final ModelResourceLocation MODEL_FAN = ModelResourceLocation.inventory(SBRItems.FAN.getId()); | ||
| public static BakedModel DEFAULT_FAN_MODEL; | ||
|
|
||
| private static final EnumSet<ItemDisplayContext> TEXT_TO_RENDER = EnumSet.of( | ||
| ItemDisplayContext.FIRST_PERSON_LEFT_HAND, | ||
| ItemDisplayContext.FIRST_PERSON_RIGHT_HAND, | ||
| ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, | ||
| ItemDisplayContext.THIRD_PERSON_LEFT_HAND); | ||
|
|
||
| public static final Lazy<Widgets> TEXTURE = Lazy.lazy(() -> WidgetLoader.loadWidgets(ResourceLocation.fromNamespaceAndPath(SinoBrush.MODID, "textures/gui/fan"))); | ||
| public static final double[] LINE_X_IN_HAND = {0.440, 0.400, 0.350, 0.310, 0.270, 0.220, 0.170, 0.110, 0.050, -0.010, -0.080, -0.150, -0.220, -0.280, -0.330, -0.380, -0.420, -0.450, -0.470, -0.510, -0.540}; | ||
| public static final double[] LINE_Y_IN_HAND = {0.060, 0.080, 0.090, 0.110, 0.140, 0.160, 0.180, 0.200, 0.220, 0.220, 0.210, 0.200, 0.170, 0.150, 0.130, 0.120, 0.080, 0.060, 0.030, 0.010, -0.030}; | ||
| public static final double[] LINE_R_IN_HAND = {45, 41, 38, 36, 33, 30, 28, 22, 17, 14, 7, 1, -7, -13, -17, -21, -25, -26, -30, -34, -42}; | ||
| private static final float[] LINE_X_IN_GUI = {231, 223, 213, 203, 191, 181, 165, 152, 138, 117, 102, 89, 77, 67, 56, 46, 37, 28, 20, 14, 9,}; | ||
| private static final float[] LINE_Y_IN_GUI = {64, 54, 43, 35, 27, 22, 17, 13, 10, 11, 13, 18, 22, 28, 34, 43, 52, 62, 72, 83, 95,}; | ||
| private static final float[] LINE_R_IN_GUI = {45, 41, 35, 30, 25, 22, 14, 9, 4, -6, -13, -19, -23, -26, -30, -35, -39, -45, -50, -55, -58,}; | ||
|
|
||
| public FanRenderer() { | ||
| super(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels()); | ||
| } | ||
|
|
||
| @Override | ||
| public void renderByItem(ItemStack stack, ItemDisplayContext displayContext, PoseStack poseStack, MultiBufferSource buffer, int packedLight, int packedOverlay) { | ||
| if (stack.isEmpty() || DEFAULT_FAN_MODEL == null) return; | ||
|
|
||
| poseStack.popPose(); | ||
|
|
||
| // 绘制模型 | ||
| boolean leftHand = displayContext == ItemDisplayContext.FIRST_PERSON_LEFT_HAND | ||
| || displayContext == ItemDisplayContext.THIRD_PERSON_LEFT_HAND; | ||
| ItemRenderer renderer = Minecraft.getInstance().getItemRenderer(); | ||
| renderer.render(stack, displayContext, leftHand, poseStack, buffer, packedLight, packedOverlay, DEFAULT_FAN_MODEL); | ||
|
|
||
| // 绘制文字 | ||
| List<Component> lines = FanItem.getLines(stack); | ||
| if (TEXT_TO_RENDER.contains(displayContext) && !lines.isEmpty()) { | ||
| Font font = Minecraft.getInstance().font; | ||
| ItemTransform transform = DEFAULT_FAN_MODEL.getTransforms().getTransform(displayContext); | ||
| transform.apply(leftHand, poseStack); | ||
| poseStack.mulPose(new Matrix4f().rotate((float) Math.toRadians(-45), 0, 0, 1)); | ||
| for (int i = 0; i < Math.min(lines.size(), MAX_DISPLAY_LINES); i++) { | ||
| float r = (float) Math.toRadians(LINE_R_IN_HAND[i]); | ||
| poseStack.pushPose(); | ||
| poseStack.translate(LINE_X_IN_HAND[i], LINE_Y_IN_HAND[i], 0.05); | ||
| poseStack.scale(0.003f, -0.003f, 1); | ||
| poseStack.mulPose(new Matrix4f().rotate(r, 0, 0, 1)); | ||
| drawCharactersInHand(lines.get(i), font, poseStack, buffer, packedLight); | ||
| poseStack.popPose(); | ||
| } | ||
| } | ||
|
|
||
| poseStack.pushPose(); | ||
| } | ||
|
|
||
| private void drawCharactersInHand(Component text, Font font, PoseStack poseStack, MultiBufferSource buffer, int packedLight) { | ||
| String line = text.getString(); | ||
| int y = 0; | ||
| for (char c : line.toCharArray()) { | ||
| String s = String.valueOf(c); | ||
| int w = font.width(s); | ||
| int h = font.wordWrapHeight(s, w); | ||
| font.drawInBatch(s, 0, y, 0x414141, false, poseStack.last().pose(), buffer, | ||
| Font.DisplayMode.NORMAL, 0, packedLight, font.isBidirectional()); | ||
| y += h; | ||
| } | ||
| } | ||
|
|
||
| public static void renderInGui(GuiGraphics guiGraphics, Font font, int x, int y, | ||
| List<Component> lines, int currentLine, long focusedTime) { | ||
| TextureEntry background = (TextureEntry) TEXTURE.get().getWidget("background"); | ||
| guiGraphics.blit(TEXTURE.get().getTexture(), x, y, | ||
| background.getWidth(), background.getHeight(), | ||
| background.getTextureX(), background.getTextureY(), | ||
| background.getTextureWidth(), background.getTextureHeight(), | ||
| TEXTURE.get().getWidth(), TEXTURE.get().getHeight()); | ||
| PoseStack pose = guiGraphics.pose(); | ||
| for (int i = 0; i < MAX_DISPLAY_LINES; i++) { | ||
| if (i >= lines.size() && currentLine != i) | ||
| continue; | ||
|
|
||
| float offX = x + LINE_X_IN_GUI[i]; | ||
| float offY = y + LINE_Y_IN_GUI[i]; | ||
| float r = (float) Math.toRadians(LINE_R_IN_GUI[i]); | ||
| pose.pushPose(); | ||
| pose.translate(offX, offY, 0); | ||
| pose.scale(0.6f, 0.6f, 1); | ||
| pose.mulPose(new Matrix4f().rotate(r, 0, 0, 1)); | ||
| int ny = 0; | ||
| // 文本内容 | ||
| if (i < lines.size()) { | ||
| ny = drawCharactersInGui(guiGraphics, font, lines.get(i).getString()); | ||
| } | ||
| // 编辑标记 | ||
| if (currentLine == i && (Util.getMillis() - focusedTime) / 300L % 2L == 0L) { | ||
| guiGraphics.drawString(font, "_", 0, ny, 0x414141); | ||
| } | ||
| pose.popPose(); | ||
| } | ||
| } | ||
|
|
||
| private static int drawCharactersInGui(GuiGraphics guiGraphics, Font font, String line) { | ||
| int y = 0; | ||
| for (char c : line.toCharArray()) { | ||
| String s = String.valueOf(c); | ||
| int w = font.width(s); | ||
| int h = font.wordWrapHeight(s, w); | ||
| guiGraphics.drawString(font, s, 0, y, 0x414141, false); | ||
| y += h; | ||
| } | ||
| return y; | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
sinobrush/src/main/java/games/moegirl/sinocraft/sinobrush/client/SinoBrushClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里对initClient应该放在ClientModInitializer里