-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
228 additions
and
7 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...on/src/main/java/dev/architectury/event/events/client/ClientCommandRegistrationEvent.java
This file contains 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,71 @@ | ||
/* | ||
* 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.event.events.client; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import com.mojang.brigadier.builder.RequiredArgumentBuilder; | ||
import dev.architectury.event.Event; | ||
import dev.architectury.event.EventFactory; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.client.player.LocalPlayer; | ||
import net.minecraft.commands.SharedSuggestionProvider; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.Vec2; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
public interface ClientCommandRegistrationEvent { | ||
/** | ||
* @see ClientCommandRegistrationEvent#register(CommandDispatcher) | ||
*/ | ||
Event<ClientCommandRegistrationEvent> EVENT = EventFactory.createLoop(); | ||
|
||
/** | ||
* This event is invoked after the client initializes. | ||
* Equivalent to Forge's {@code RegisterClientCommandsEvent} and Fabric's {@code ClientCommandManager}. | ||
* | ||
* @param dispatcher The command dispatcher to register commands to. | ||
*/ | ||
void register(CommandDispatcher<ClientCommandSourceStack> dispatcher); | ||
|
||
static LiteralArgumentBuilder<ClientCommandSourceStack> literal(String name) { | ||
return LiteralArgumentBuilder.literal(name); | ||
} | ||
|
||
static <T> RequiredArgumentBuilder<ClientCommandSourceStack, T> argument(String name, ArgumentType<T> type) { | ||
return RequiredArgumentBuilder.argument(name, type); | ||
} | ||
|
||
interface ClientCommandSourceStack extends SharedSuggestionProvider { | ||
void arch$sendSuccess(Component message, boolean broadcastToAdmins); | ||
|
||
void arch$sendFailure(Component message); | ||
|
||
LocalPlayer arch$getPlayer(); | ||
|
||
Vec3 arch$getPosition(); | ||
|
||
Vec2 arch$getRotation(); | ||
|
||
ClientLevel arch$getLevel(); | ||
} | ||
} |
This file contains 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
62 changes: 62 additions & 0 deletions
62
...ic/src/main/java/dev/architectury/mixin/fabric/client/MixinFabricClientCommandSource.java
This file contains 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,62 @@ | ||
/* | ||
* 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.fabric.client; | ||
|
||
import dev.architectury.event.events.client.ClientCommandRegistrationEvent; | ||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.client.player.LocalPlayer; | ||
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(FabricClientCommandSource.class) | ||
public interface MixinFabricClientCommandSource extends ClientCommandRegistrationEvent.ClientCommandSourceStack { | ||
@Override | ||
default void arch$sendSuccess(Component message, boolean broadcastToAdmins) { | ||
((FabricClientCommandSource) this).sendFeedback(message); | ||
} | ||
|
||
@Override | ||
default void arch$sendFailure(Component message) { | ||
((FabricClientCommandSource) this).sendError(message); | ||
} | ||
|
||
@Override | ||
default LocalPlayer arch$getPlayer() { | ||
return ((FabricClientCommandSource) this).getPlayer(); | ||
} | ||
|
||
@Override | ||
default Vec3 arch$getPosition() { | ||
return ((FabricClientCommandSource) this).getPosition(); | ||
} | ||
|
||
@Override | ||
default Vec2 arch$getRotation() { | ||
return ((FabricClientCommandSource) this).getRotation(); | ||
} | ||
|
||
@Override | ||
default ClientLevel arch$getLevel() { | ||
return ((FabricClientCommandSource) this).getWorld(); | ||
} | ||
} |
This file contains 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 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
67 changes: 67 additions & 0 deletions
67
forge/src/main/java/dev/architectury/mixin/forge/client/MixinCommandSourceStack.java
This file contains 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,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(); | ||
} | ||
} |
This file contains 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 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