|
| 1 | +/* |
| 2 | + * This file is part of architectury. |
| 3 | + * Copyright (C) 2020, 2021, 2022 architectury |
| 4 | + * |
| 5 | + * This program is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation; either |
| 8 | + * version 3 of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public License |
| 16 | + * along with this program; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | + */ |
| 19 | + |
| 20 | +package dev.architectury.event.events.client; |
| 21 | + |
| 22 | +import com.mojang.brigadier.CommandDispatcher; |
| 23 | +import com.mojang.brigadier.arguments.ArgumentType; |
| 24 | +import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
| 25 | +import com.mojang.brigadier.builder.RequiredArgumentBuilder; |
| 26 | +import dev.architectury.event.Event; |
| 27 | +import dev.architectury.event.EventFactory; |
| 28 | +import net.minecraft.client.multiplayer.ClientLevel; |
| 29 | +import net.minecraft.client.player.LocalPlayer; |
| 30 | +import net.minecraft.commands.CommandBuildContext; |
| 31 | +import net.minecraft.commands.SharedSuggestionProvider; |
| 32 | +import net.minecraft.network.chat.Component; |
| 33 | +import net.minecraft.world.phys.Vec2; |
| 34 | +import net.minecraft.world.phys.Vec3; |
| 35 | + |
| 36 | +import java.util.function.Supplier; |
| 37 | + |
| 38 | +public interface ClientCommandRegistrationEvent { |
| 39 | + /** |
| 40 | + * @see ClientCommandRegistrationEvent#register(CommandDispatcher, CommandBuildContext) |
| 41 | + */ |
| 42 | + Event<ClientCommandRegistrationEvent> EVENT = EventFactory.createLoop(); |
| 43 | + |
| 44 | + /** |
| 45 | + * This event is invoked after the client initializes. |
| 46 | + * Equivalent to Forge's {@code RegisterClientCommandsEvent} and Fabric's {@code ClientCommandManager}. |
| 47 | + * |
| 48 | + * @param dispatcher The command dispatcher to register commands to. |
| 49 | + * @param context The command build context. |
| 50 | + */ |
| 51 | + void register(CommandDispatcher<ClientCommandSourceStack> dispatcher, CommandBuildContext context); |
| 52 | + |
| 53 | + static LiteralArgumentBuilder<ClientCommandSourceStack> literal(String name) { |
| 54 | + return LiteralArgumentBuilder.literal(name); |
| 55 | + } |
| 56 | + |
| 57 | + static <T> RequiredArgumentBuilder<ClientCommandSourceStack, T> argument(String name, ArgumentType<T> type) { |
| 58 | + return RequiredArgumentBuilder.argument(name, type); |
| 59 | + } |
| 60 | + |
| 61 | + interface ClientCommandSourceStack extends SharedSuggestionProvider { |
| 62 | + void arch$sendSuccess(Supplier<Component> message, boolean broadcastToAdmins); |
| 63 | + |
| 64 | + void arch$sendFailure(Component message); |
| 65 | + |
| 66 | + LocalPlayer arch$getPlayer(); |
| 67 | + |
| 68 | + Vec3 arch$getPosition(); |
| 69 | + |
| 70 | + Vec2 arch$getRotation(); |
| 71 | + |
| 72 | + ClientLevel arch$getLevel(); |
| 73 | + } |
| 74 | +} |
0 commit comments