Look-mode has no cursor, so +/- only work when chat is open. Keep the panel visible then. The add command now refuses ids that are not real items.
This commit is contained in:
@@ -17,6 +17,7 @@ import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.client.event.InputEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterClientCommandsEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent;
|
||||
import net.neoforged.neoforge.client.gui.VanillaGuiLayers;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
|
||||
@Mod(value = Satistaskory.MODID, dist = Dist.CLIENT)
|
||||
@@ -28,7 +29,8 @@ public class SatistaskoryClient {
|
||||
}
|
||||
|
||||
private static void registerGuiLayers(RegisterGuiLayersEvent event) {
|
||||
event.registerAboveAll(
|
||||
event.registerAbove(
|
||||
VanillaGuiLayers.CHAT,
|
||||
ResourceLocation.fromNamespaceAndPath(Satistaskory.MODID, "play_overlay"),
|
||||
PlayOverlay::render);
|
||||
}
|
||||
@@ -46,7 +48,7 @@ public class SatistaskoryClient {
|
||||
return;
|
||||
}
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
if (minecraft.screen != null || minecraft.player == null) {
|
||||
if (!PlayOverlay.inWorldHud(minecraft)) {
|
||||
return;
|
||||
}
|
||||
double mouseX = minecraft.mouseHandler.xpos()
|
||||
|
||||
@@ -8,8 +8,10 @@ import com.sufficient.satistaskory.domain.ItemId;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.ResourceLocationArgument;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public final class ClientCommands {
|
||||
private ClientCommands() {}
|
||||
@@ -29,6 +31,13 @@ public final class ClientCommands {
|
||||
|
||||
private static int add(CommandContext<CommandSourceStack> ctx) {
|
||||
ResourceLocation location = ResourceLocationArgument.getId(ctx, "item");
|
||||
if (!BuiltInRegistries.ITEM.containsKey(location)
|
||||
|| (BuiltInRegistries.ITEM.get(location) == Items.AIR
|
||||
&& !location.equals(ResourceLocation.withDefaultNamespace("air")))) {
|
||||
ctx.getSource().sendFailure(Component.literal(
|
||||
"Unknown item: " + location + " (crafting table is minecraft:crafting_table)"));
|
||||
return 0;
|
||||
}
|
||||
ItemId item = ItemId.parse(location.toString());
|
||||
PlannerSession.get().create(item);
|
||||
ctx.getSource().sendSuccess(() -> Component.literal("Added " + item), false);
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.ChatScreen;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
@@ -30,7 +31,7 @@ public final class PlayOverlay {
|
||||
public static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
|
||||
HITS.clear();
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
if (minecraft.player == null || minecraft.options.hideGui) {
|
||||
if (!inWorldHud(minecraft)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,6 +87,17 @@ public final class PlayOverlay {
|
||||
HITS.add(new Hit(clearX, clearY - 2, clearX + clearWidth, clearY + LINE, Kind.CLEAR, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Visible in-world. Chat is allowed so the mouse can hit +/- (look-mode has no cursor).
|
||||
* Pause/inventory still hide it.
|
||||
*/
|
||||
public static boolean inWorldHud(Minecraft minecraft) {
|
||||
if (minecraft.level == null || minecraft.player == null || minecraft.options.hideGui) {
|
||||
return false;
|
||||
}
|
||||
return minecraft.screen == null || minecraft.screen instanceof ChatScreen;
|
||||
}
|
||||
|
||||
public static boolean click(double mouseX, double mouseY) {
|
||||
for (Hit hit : HITS) {
|
||||
if (hit.contains(mouseX, mouseY)) {
|
||||
|
||||
Reference in New Issue
Block a user