Add client commands

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2022-08-12 22:04:30 +09:00
parent 4ed66609b0
commit a2e5359225
8 changed files with 229 additions and 8 deletions

View File

@@ -20,6 +20,7 @@
package dev.architectury.event.forge;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.brigadier.CommandDispatcher;
import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.client.ClientChatEvent;
@@ -324,6 +325,12 @@ public class EventHandlerImplClient {
ClientRawInputEvent.KEY_PRESSED.invoker().keyPressed(Minecraft.getInstance(), event.getKey(), event.getScanCode(), event.getAction(), event.getModifiers());
}
@SubscribeEvent(priority = EventPriority.HIGH)
public static void event(RegisterClientCommandsEvent event) {
ClientCommandRegistrationEvent.EVENT.invoker().register((CommandDispatcher<ClientCommandRegistrationEvent.ClientCommandSourceStack>)
(CommandDispatcher<?>) event.getDispatcher(), event.getBuildContext());
}
@OnlyIn(Dist.CLIENT)
public static class ModBasedEventHandler {
@SubscribeEvent(priority = EventPriority.HIGH)

View File

@@ -0,0 +1,67 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.mixin.forge.client;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.architectury.event.events.client.ClientCommandRegistrationEvent;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(CommandSourceStack.class)
public abstract class MixinCommandSourceStack implements ClientCommandRegistrationEvent.ClientCommandSourceStack {
@Override
public void arch$sendSuccess(Component message, boolean broadcastToAdmins) {
((CommandSourceStack) (Object) this).sendSuccess(message, broadcastToAdmins);
}
@Override
public void arch$sendFailure(Component message) {
((CommandSourceStack) (Object) this).sendFailure(message);
}
@Override
public LocalPlayer arch$getPlayer() {
try {
return (LocalPlayer) ((CommandSourceStack) (Object) this).getEntityOrException();
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
}
@Override
public Vec3 arch$getPosition() {
return ((CommandSourceStack) (Object) this).getPosition();
}
@Override
public Vec2 arch$getRotation() {
return ((CommandSourceStack) (Object) this).getRotation();
}
@Override
public ClientLevel arch$getLevel() {
return (ClientLevel) ((CommandSourceStack) (Object) this).getUnsidedLevel();
}
}

View File

@@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_16",
"minVersion": "0.8",
"client": [
"client.MixinCommandSourceStack",
"MixinClientLevel",
"MixinMinecraft"
],