From bc671d435e53ab7f1f5de72d5f449d1ba7fb8a5f Mon Sep 17 00:00:00 2001 From: deirn Date: Sun, 13 Oct 2024 00:19:38 +0700 Subject: [PATCH] pass 2 --- .../waila/api/component/BarComponent.java | 4 +- .../api/component/ProgressArrowComponent.java | 4 +- .../api/component/SpriteBarComponent.java | 4 +- .../mobius/waila/command/ServerCommand.java | 67 +++++++++++-------- .../mobius/waila/gui/hud/TooltipRenderer.java | 4 +- .../mcp/mobius/waila/util/DisplayUtil.java | 4 +- .../plugin/core/theme/GradientTheme.java | 4 +- .../plugin/core/theme/NinePatchTheme.java | 4 +- .../waila/plugin/harvest/tool/ToolTier.java | 17 +++-- .../provider/data/JukeboxDataProvider.java | 14 ++-- 10 files changed, 72 insertions(+), 54 deletions(-) diff --git a/src/api/java/mcp/mobius/waila/api/component/BarComponent.java b/src/api/java/mcp/mobius/waila/api/component/BarComponent.java index e1e971f5..54781148 100644 --- a/src/api/java/mcp/mobius/waila/api/component/BarComponent.java +++ b/src/api/java/mcp/mobius/waila/api/component/BarComponent.java @@ -13,6 +13,7 @@ import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; @@ -90,8 +91,7 @@ static void renderBar( RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - // TODO -// RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); RenderSystem.setShaderTexture(0, WailaConstants.COMPONENT_TEXTURE); var a = WailaHelper.getAlpha(tint); diff --git a/src/api/java/mcp/mobius/waila/api/component/ProgressArrowComponent.java b/src/api/java/mcp/mobius/waila/api/component/ProgressArrowComponent.java index b48a5df2..a15efa8e 100644 --- a/src/api/java/mcp/mobius/waila/api/component/ProgressArrowComponent.java +++ b/src/api/java/mcp/mobius/waila/api/component/ProgressArrowComponent.java @@ -36,11 +36,11 @@ public int getHeight() { @Override public void render(GuiGraphics ctx, int x, int y, DeltaTracker delta) { // Draws the "empty" background arrow - ctx.blitSprite(RenderType::guiTextured, WailaConstants.COMPONENT_TEXTURE, 255, 255, 0, 16, x, y, 22, 16); + ctx.blit(RenderType::guiTextured, WailaConstants.COMPONENT_TEXTURE, x, y, 0, 16, 22, 16, 256, 256); if (progress > 0) { // Draws the "full" foreground arrow based on the progress - ctx.blitSprite(RenderType::guiTextured, WailaConstants.COMPONENT_TEXTURE, 255, 255, 0, 0, x, y, (int) (progress * 22) + 1, 16); + ctx.blit(RenderType::guiTextured, WailaConstants.COMPONENT_TEXTURE, x, y, 0, 0, (int) (progress * 22) + 1, 16, 256, 256); } } diff --git a/src/api/java/mcp/mobius/waila/api/component/SpriteBarComponent.java b/src/api/java/mcp/mobius/waila/api/component/SpriteBarComponent.java index 1470a3ba..8e1fa5c4 100644 --- a/src/api/java/mcp/mobius/waila/api/component/SpriteBarComponent.java +++ b/src/api/java/mcp/mobius/waila/api/component/SpriteBarComponent.java @@ -11,6 +11,7 @@ import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -64,8 +65,7 @@ public void render(GuiGraphics ctx, int x, int y, DeltaTracker delta) { matrices.pushPose(); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - // TODO -// RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); RenderSystem.setShaderTexture(0, texture); var mx = (int) (x + BarComponent.WIDTH * ratio); diff --git a/src/main/java/mcp/mobius/waila/command/ServerCommand.java b/src/main/java/mcp/mobius/waila/command/ServerCommand.java index 4691cab3..6563010e 100644 --- a/src/main/java/mcp/mobius/waila/command/ServerCommand.java +++ b/src/main/java/mcp/mobius/waila/command/ServerCommand.java @@ -10,16 +10,22 @@ import mcp.mobius.waila.api.WailaConstants; import mcp.mobius.waila.buildconst.Tl; import mcp.mobius.waila.debug.DumpGenerator; +import mcp.mobius.waila.mixin.BaseContainerBlockEntityAccess; import mcp.mobius.waila.network.play.s2c.GenerateClientDumpPlayS2CPacket; import mcp.mobius.waila.plugin.PluginLoader; +import net.minecraft.advancements.critereon.ItemPredicate; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; +import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.LockCode; public class ServerCommand extends CommonCommand { @@ -98,33 +104,40 @@ protected void register(ArgumentBuilderBuilder command) { }) .pop("target", "getEntityInfo") - // TODO -// .then(Commands.literal("lockContainer")) -// .then(Commands.argument("pos", BlockPosArgument.blockPos())) -// .then(Commands.argument("lock", StringArgumentType.string())) -// .executes(context -> { -// var source = context.getSource(); -// var world = source.getLevel(); -// var player = source.getPlayer(); -// var pos = BlockPosArgument.getLoadedBlockPos(context, "pos"); -// var lock = StringArgumentType.getString(context, "lock"); -// -// if (player == null) { -// source.sendFailure(Component.literal("Needs a player")); -// } else if (world.getBlockEntity(pos) instanceof BaseContainerBlockEntityAccess container) { -// container.wthit_lockKey(new LockCode(new ItemPredicate())); -// var key = new ItemStack(Items.NAME_TAG); -// key.set(DataComponents.CUSTOM_NAME, Component.literal(lock)); -// player.setItemInHand(InteractionHand.MAIN_HAND, key); -// source.sendSuccess(() -> Component.literal("Locked container " + pos.toShortString() + " with lock \"" + lock + "\""), false); -// return 1; -// } else { -// source.sendFailure(Component.literal("Couldn't lock container " + pos.toShortString())); -// } -// -// return 0; -// }) -// .pop("lock", "pos", "lockContainer") + // TODO + .then(Commands.literal("lockContainer")) + .then(Commands.argument("pos", BlockPosArgument.blockPos())) + .executes(context -> { + var source = context.getSource(); + var world = source.getLevel(); + var player = source.getPlayer(); + var pos = BlockPosArgument.getLoadedBlockPos(context, "pos"); + + if (player == null) { + source.sendFailure(Component.literal("Needs a player")); + return 0; + } + + var stack = player.getItemInHand(InteractionHand.MAIN_HAND); + if (stack.isEmpty()) { + source.sendFailure(Component.literal("Needs a held stack")); + return 0; + } + + if (world.getBlockEntity(pos) instanceof BaseContainerBlockEntityAccess container) { + container.wthit_lockKey(new LockCode(ItemPredicate.Builder.item() + .of(world.registryAccess().lookupOrThrow(Registries.ITEM), stack.getItem()) + .hasComponents(DataComponentPredicate.allOf(stack.getComponents())) + .build())); + + source.sendSuccess(() -> Component.literal("Locked container " + pos.toShortString()), false); + return 1; + } else { + source.sendFailure(Component.literal("Couldn't lock container " + pos.toShortString())); + return 0; + } + }) + .pop("pos", "lockContainer") .pop("debug"); } diff --git a/src/main/java/mcp/mobius/waila/gui/hud/TooltipRenderer.java b/src/main/java/mcp/mobius/waila/gui/hud/TooltipRenderer.java index 62e833da..07179e6c 100644 --- a/src/main/java/mcp/mobius/waila/gui/hud/TooltipRenderer.java +++ b/src/main/java/mcp/mobius/waila/gui/hud/TooltipRenderer.java @@ -31,6 +31,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.ChatScreen; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.util.Mth; import net.minecraft.util.profiling.Profiler; import org.jetbrains.annotations.Nullable; @@ -233,8 +234,7 @@ public static void render(GuiGraphics ctx, DeltaTracker delta) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - // TODO -// RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); RenderSystem.setShaderTexture(0, framebuffer.getColorTextureId()); var w = client.getWindow().getGuiScaledWidth(); diff --git a/src/main/java/mcp/mobius/waila/util/DisplayUtil.java b/src/main/java/mcp/mobius/waila/util/DisplayUtil.java index ef6c3a19..37f33b8a 100644 --- a/src/main/java/mcp/mobius/waila/util/DisplayUtil.java +++ b/src/main/java/mcp/mobius/waila/util/DisplayUtil.java @@ -17,6 +17,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import org.joml.Matrix4f; @@ -58,8 +59,7 @@ public static void renderComponent(GuiGraphics ctx, ITooltipComponent component, var scale = (float) Minecraft.getInstance().getWindow().getGuiScale(); ctx.pose().scale(1 / scale, 1 / scale, 1); - // TODO -// RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); var buf = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); var bx = Mth.floor(x * scale + 0.5); diff --git a/src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/GradientTheme.java b/src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/GradientTheme.java index 88f140ff..d2f3ccba 100644 --- a/src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/GradientTheme.java +++ b/src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/GradientTheme.java @@ -12,6 +12,7 @@ import mcp.mobius.waila.api.__internal__.IApiService; import net.minecraft.client.DeltaTracker; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.util.Mth; import org.jetbrains.annotations.Range; @@ -59,8 +60,7 @@ public void setPadding(Padding padding) { public void renderTooltipBackground(GuiGraphics ctx, int x, int y, int width, int height, @Range(from = 0x00, to = 0xFF) int alpha, DeltaTracker delta) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - // TODO -// RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); var tesselator = Tesselator.getInstance(); var buf = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); diff --git a/src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/NinePatchTheme.java b/src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/NinePatchTheme.java index 9f1654c4..9a775fa7 100644 --- a/src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/NinePatchTheme.java +++ b/src/pluginCore/java/mcp/mobius/waila/plugin/core/theme/NinePatchTheme.java @@ -16,6 +16,7 @@ import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.CoreShaders; import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.resources.ResourceLocation; @@ -97,8 +98,7 @@ public void setPadding(Padding padding) { public void renderTooltipBackground(GuiGraphics ctx, int x, int y, int width, int height, @Range(from = 0x00, to = 0xFF) int alpha, DeltaTracker delta) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - // TODO -// RenderSystem.setShader(GameRenderer::getPositionTexColorShader); + RenderSystem.setShader(CoreShaders.POSITION_TEX_COLOR); RenderSystem.setShaderTexture(0, textureId); var buf = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); diff --git a/src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/tool/ToolTier.java b/src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/tool/ToolTier.java index 885710ad..e797a3af 100644 --- a/src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/tool/ToolTier.java +++ b/src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/tool/ToolTier.java @@ -1,7 +1,6 @@ package mcp.mobius.waila.plugin.harvest.tool; import java.util.Collection; -import java.util.HashMap; import java.util.Map; import java.util.function.Supplier; @@ -23,14 +22,14 @@ public final class ToolTier { public static final ToolTier NONE = Internals.unsafeAlloc(ToolTier.class); - private static final Supplier> VANILLA_TIER_TL_KEYS = Suppliers.memoize(() -> { - var map = new HashMap(); - // TODO -// for (var tier : Tiers.values()) { -// map.put(tier.getIncorrectBlocksForDrops().location(), tier.name().toLowerCase(Locale.ROOT)); -// } - return map; - }); + private static final Supplier> VANILLA_TIER_TL_KEYS = Suppliers.memoize(() -> Map.of( + ToolMaterial.WOOD.incorrectBlocksForDrops().location(), "wood", + ToolMaterial.STONE.incorrectBlocksForDrops().location(), "stone", + ToolMaterial.IRON.incorrectBlocksForDrops().location(), "iron", + ToolMaterial.DIAMOND.incorrectBlocksForDrops().location(), "diamond", + ToolMaterial.GOLD.incorrectBlocksForDrops().location(), "gold", + ToolMaterial.NETHERITE.incorrectBlocksForDrops().location(), "netherite" + )); private static Supplier> tiers; diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/JukeboxDataProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/JukeboxDataProvider.java index ad04cfa8..d25d0608 100644 --- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/JukeboxDataProvider.java +++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/data/JukeboxDataProvider.java @@ -6,6 +6,7 @@ import mcp.mobius.waila.api.IServerAccessor; import mcp.mobius.waila.plugin.vanilla.config.Options; import net.minecraft.core.component.DataComponents; +import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.world.level.block.entity.JukeboxBlockEntity; @@ -18,10 +19,15 @@ public void appendData(IDataWriter data, IServerAccessor acc if (config.getBoolean(Options.JUKEBOX_RECORD)) { var stack = accessor.getTarget().getTheItem(); if (!stack.isEmpty()) { - // TODO - var text = stack.get(DataComponents.JUKEBOX_PLAYABLE) != null - ? Component.translatable(stack.getDisplayName() + ".desc") - : stack.getDisplayName(); + var playable = stack.get(DataComponents.JUKEBOX_PLAYABLE); + Component text = null; + + if (playable != null) { + var song = playable.song().unwrap(accessor.getPlayer().registryAccess().lookupOrThrow(Registries.JUKEBOX_SONG)); + if (song.isPresent()) text = song.get().description(); + } + + if (text == null) text = stack.getDisplayName(); data.raw().putString("record", Component.Serializer.toJson(text, accessor.getWorld().registryAccess())); } }