Skip to content

Commit

Permalink
pass 2
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Oct 12, 2024
1 parent ed989f4 commit bc671d4
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/api/java/mcp/mobius/waila/api/component/BarComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
67 changes: 40 additions & 27 deletions src/main/java/mcp/mobius/waila/command/ServerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandSourceStack, MinecraftServer> {

Expand Down Expand Up @@ -98,33 +104,40 @@ protected void register(ArgumentBuilderBuilder<CommandSourceStack> 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");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mcp/mobius/waila/gui/hud/TooltipRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mcp/mobius/waila/util/DisplayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,14 +22,14 @@ public final class ToolTier {

public static final ToolTier NONE = Internals.unsafeAlloc(ToolTier.class);

private static final Supplier<Map<ResourceLocation, String>> VANILLA_TIER_TL_KEYS = Suppliers.memoize(() -> {
var map = new HashMap<ResourceLocation, String>();
// TODO
// for (var tier : Tiers.values()) {
// map.put(tier.getIncorrectBlocksForDrops().location(), tier.name().toLowerCase(Locale.ROOT));
// }
return map;
});
private static final Supplier<Map<ResourceLocation, String>> 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<Map<ResourceLocation, ToolTier>> tiers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,10 +19,15 @@ public void appendData(IDataWriter data, IServerAccessor<JukeboxBlockEntity> 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()));
}
}
Expand Down

0 comments on commit bc671d4

Please sign in to comment.