-
-
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.
Merge remote-tracking branch 'origin/1.19.2' into 1.20
Signed-off-by: shedaniel <[email protected]> # Conflicts: # fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java # forge/src/main/java/dev/architectury/event/forge/EventHandlerImplClient.java # gradle.properties
- Loading branch information
Showing
9 changed files
with
236 additions
and
8 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...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,74 @@ | ||
/* | ||
* 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.CommandBuildContext; | ||
import net.minecraft.commands.SharedSuggestionProvider; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.phys.Vec2; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public interface ClientCommandRegistrationEvent { | ||
/** | ||
* @see ClientCommandRegistrationEvent#register(CommandDispatcher, CommandBuildContext) | ||
*/ | ||
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. | ||
* @param context The command build context. | ||
*/ | ||
void register(CommandDispatcher<ClientCommandSourceStack> dispatcher, CommandBuildContext context); | ||
|
||
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(Supplier<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
64 changes: 64 additions & 0 deletions
64
...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,64 @@ | ||
/* | ||
* 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.v2.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; | ||
|
||
import java.util.function.Supplier; | ||
|
||
@Mixin(FabricClientCommandSource.class) | ||
public interface MixinFabricClientCommandSource extends ClientCommandRegistrationEvent.ClientCommandSourceStack { | ||
@Override | ||
default void arch$sendSuccess(Supplier<Component> message, boolean broadcastToAdmins) { | ||
((FabricClientCommandSource) this).sendFeedback(message.get()); | ||
} | ||
|
||
@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
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.function.Supplier; | ||
|
||
@Mixin(CommandSourceStack.class) | ||
public abstract class MixinCommandSourceStack implements ClientCommandRegistrationEvent.ClientCommandSourceStack { | ||
@Override | ||
public void arch$sendSuccess(Supplier<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
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