Search in sources :

Example 1 with FabricClientCommandSource

use of net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource in project fabric-name-history-lookup by Woolyenough.

the class ClientCommands method names.

private static int names(CommandContext<FabricClientCommandSource> context) {
    CompletableFuture.runAsync(() -> {
        String name = context.getInput().split(" ")[1];
        String[] playerNameAndUUID = get_player_name_and_uuid(name);
        String username = playerNameAndUUID[0];
        String uuid = playerNameAndUUID[1];
        if (Objects.equals(username, "None")) {
            context.getSource().sendError(new LiteralText("No account exists by that name .-."));
        } else {
            context.getSource().sendFeedback(new LiteralText("§7[Hover] §eView name history of " + username).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://namemc.com/profile/" + username)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, get_player_name_history(username, uuid).append(new LiteralText("\n\n§7§oClick to open in NameMC!"))))));
        }
    });
    return 0;
}
Also used : ClientModInitializer(net.fabricmc.api.ClientModInitializer) LiteralText(net.minecraft.text.LiteralText) java.util(java.util) CommandContext(com.mojang.brigadier.context.CommandContext) FabricClientCommandSource(net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource) Environment(net.fabricmc.api.Environment) CompletableFuture(java.util.concurrent.CompletableFuture) EntityArgumentType(net.minecraft.command.argument.EntityArgumentType) HoverEvent(net.minecraft.text.HoverEvent) ClientCommandManager(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager) ClickEvent(net.minecraft.text.ClickEvent) EnvType(net.fabricmc.api.EnvType) MojangAPI(net.woolyenough.namelookup.modules.MojangAPI) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Example 2 with FabricClientCommandSource

use of net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource in project isometric-renders by gliscowo.

the class IsoRenderCommand method register.

public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
    dispatcher.register(literal("isorender").then(literal("block").executes(context -> executeBlockTarget(context.getSource())).then(argument("block", BlockStateArgumentType.blockState()).executes(context -> {
        final BlockStateArgument blockStateArgument = context.getArgument("block", BlockStateArgument.class);
        final BlockState blockState = blockStateArgument.getBlockState();
        return executeBlockState(context.getSource(), blockState, ((BlockStateArgumentAccessor) blockStateArgument).getData());
    }))).then(literal("item").executes(context -> {
        return executeItem(context.getSource(), context.getSource().getPlayer().getMainHandStack().copy());
    }).then(argument("item", ItemStackArgumentType.itemStack()).executes(context -> {
        final ItemStack stack = ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false);
        return executeItem(context.getSource(), stack);
    }))).then(literal("entity").then(argument("entity", EntitySummonArgumentType.entitySummon()).suggests(CLIENT_SUMMONABLE_ENTITIES).executes(context -> {
        Identifier id = context.getArgument("entity", Identifier.class);
        return executeEntity(context.getSource(), EntitySummonArgumentTypeAccessor.invokeValidate(id), new CompoundTag());
    }).then(argument("nbt", NbtCompoundTagArgumentType.nbtCompound()).executes(context -> {
        Identifier id = context.getArgument("entity", Identifier.class);
        return executeEntity(context.getSource(), EntitySummonArgumentTypeAccessor.invokeValidate(id), context.getArgument("nbt", CompoundTag.class));
    })))).then(literal("insanity").executes(context -> {
        RuntimeConfig.allowInsaneResolutions = !RuntimeConfig.allowInsaneResolutions;
        if (RuntimeConfig.allowInsaneResolutions) {
            context.getSource().sendFeedback(prefix("Insane resolutions §cunlocked§7. I will not be your place to cry if this blows up your computer."));
        } else {
            context.getSource().sendFeedback(prefix("Insane resolutions §alocked§7. You're safe again"));
        }
        return 0;
    })).then(literal("area").then(argument("start", BlockPosArgumentType.blockPos()).then(argument("end", BlockPosArgumentType.blockPos()).executes(context -> {
        DefaultPosArgument startArg = context.getArgument("start", DefaultPosArgument.class);
        DefaultPosArgument endArg = context.getArgument("end", DefaultPosArgument.class);
        BlockPos pos1 = IsometricRenderHelper.getPosFromArgument(startArg, context.getSource());
        BlockPos pos2 = IsometricRenderHelper.getPosFromArgument(endArg, context.getSource());
        BlockPos start = new BlockPos(Math.min(pos1.getX(), pos2.getX()), Math.min(pos1.getY(), pos2.getY()), Math.min(pos1.getZ(), pos2.getZ()));
        BlockPos end = new BlockPos(Math.max(pos1.getX(), pos2.getX()), Math.max(pos1.getY(), pos2.getY()), Math.max(pos1.getZ(), pos2.getZ()));
        AreaIsometricRenderScreen screen = new AreaIsometricRenderScreen();
        IsometricRenderPresets.setupAreaRender(screen, start, end);
        IsometricRenderHelper.scheduleScreen(screen);
        return 0;
    })))).then(literal("creative_tab").then(argument("itemgroup", ItemGroupArgumentType.itemGroup()).suggests(ITEM_GROUPS).then(literal("batch").then(literal("blocks").executes(context -> {
        ItemGroup group = context.getArgument("itemgroup", ItemGroup.class);
        IsometricRenderHelper.batchRenderItemGroupBlocks(group);
        return 0;
    })).then(literal("items").executes(context -> {
        ItemGroup group = context.getArgument("itemgroup", ItemGroup.class);
        IsometricRenderHelper.batchRenderItemGroupItems(group);
        return 0;
    }))).then(literal("atlas").executes(context -> {
        ItemGroup group = context.getArgument("itemgroup", ItemGroup.class);
        IsometricRenderHelper.renderItemGroupAtlas(group);
        return 0;
    })))));
}
Also used : BlockEntityAccessor(com.glisco.isometricrenders.mixin.BlockEntityAccessor) net.minecraft.command.argument(net.minecraft.command.argument) EntityType(net.minecraft.entity.EntityType) ClientCommandManager.argument(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.argument) Arrays(java.util.Arrays) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) BlockEntity(net.minecraft.block.entity.BlockEntity) Util(net.minecraft.util.Util) EntitySummonArgumentTypeAccessor(com.glisco.isometricrenders.mixin.EntitySummonArgumentTypeAccessor) TranslatableText(net.minecraft.text.TranslatableText) MobEntity(net.minecraft.entity.mob.MobEntity) Function(java.util.function.Function) Direction(net.minecraft.util.math.Direction) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) IsometricRendersClient.prefix(com.glisco.isometricrenders.client.IsometricRendersClient.prefix) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) BlockState(net.minecraft.block.BlockState) IsometricRenderPresets(com.glisco.isometricrenders.client.gui.IsometricRenderPresets) Entity(net.minecraft.entity.Entity) IsometricRenderScreen(com.glisco.isometricrenders.client.gui.IsometricRenderScreen) FabricClientCommandSource(net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource) World(net.minecraft.world.World) BlockWithEntity(net.minecraft.block.BlockWithEntity) BlockHitResult(net.minecraft.util.hit.BlockHitResult) BlockPos(net.minecraft.util.math.BlockPos) Registry(net.minecraft.util.registry.Registry) CommandSource(net.minecraft.command.CommandSource) HitResult(net.minecraft.util.hit.HitResult) AreaIsometricRenderScreen(com.glisco.isometricrenders.client.gui.AreaIsometricRenderScreen) CompoundTag(net.minecraft.nbt.CompoundTag) ItemGroup(net.minecraft.item.ItemGroup) Identifier(net.minecraft.util.Identifier) BlockStateArgumentAccessor(com.glisco.isometricrenders.mixin.BlockStateArgumentAccessor) MinecraftClient(net.minecraft.client.MinecraftClient) Text(net.minecraft.text.Text) ClientCommandManager.literal(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal) IsometricRenderHelper(com.glisco.isometricrenders.client.gui.IsometricRenderHelper) AreaIsometricRenderScreen(com.glisco.isometricrenders.client.gui.AreaIsometricRenderScreen) BlockState(net.minecraft.block.BlockState) Identifier(net.minecraft.util.Identifier) ItemGroup(net.minecraft.item.ItemGroup) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 3 with FabricClientCommandSource

use of net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource in project fabric-name-history-lookup by Woolyenough.

the class ClientCommands method namemc.

private static int namemc(CommandContext<FabricClientCommandSource> context) {
    CompletableFuture.runAsync(() -> {
        String name = context.getInput().split(" ")[1];
        String[] playerNameAndUUID = get_player_name_and_uuid(name);
        String username = playerNameAndUUID[0];
        if (Objects.equals(username, "None")) {
            context.getSource().sendFeedback(new LiteralText("§7[Click] §eSearch " + name + " on NameMC §c§o(account does not exist)").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://namemc.com/profile/" + name)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(name + "\n\n§7§oClick to open NameMC")))));
        } else {
            context.getSource().sendFeedback(new LiteralText("§7[Click] §eLook at " + username + "'s NameMC page").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://namemc.com/profile/" + username)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(username + "\n\n§7§oClick to open NameMC")))));
        }
    });
    return 0;
}
Also used : ClientModInitializer(net.fabricmc.api.ClientModInitializer) LiteralText(net.minecraft.text.LiteralText) java.util(java.util) CommandContext(com.mojang.brigadier.context.CommandContext) FabricClientCommandSource(net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource) Environment(net.fabricmc.api.Environment) CompletableFuture(java.util.concurrent.CompletableFuture) EntityArgumentType(net.minecraft.command.argument.EntityArgumentType) HoverEvent(net.minecraft.text.HoverEvent) ClientCommandManager(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager) ClickEvent(net.minecraft.text.ClickEvent) EnvType(net.fabricmc.api.EnvType) MojangAPI(net.woolyenough.namelookup.modules.MojangAPI) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Aggregations

FabricClientCommandSource (net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource)3 CommandContext (com.mojang.brigadier.context.CommandContext)2 java.util (java.util)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ClientModInitializer (net.fabricmc.api.ClientModInitializer)2 EnvType (net.fabricmc.api.EnvType)2 Environment (net.fabricmc.api.Environment)2 ClientCommandManager (net.fabricmc.fabric.api.client.command.v1.ClientCommandManager)2 EntityArgumentType (net.minecraft.command.argument.EntityArgumentType)2 ClickEvent (net.minecraft.text.ClickEvent)2 HoverEvent (net.minecraft.text.HoverEvent)2 LiteralText (net.minecraft.text.LiteralText)2 IsometricRendersClient.prefix (com.glisco.isometricrenders.client.IsometricRendersClient.prefix)1 AreaIsometricRenderScreen (com.glisco.isometricrenders.client.gui.AreaIsometricRenderScreen)1 IsometricRenderHelper (com.glisco.isometricrenders.client.gui.IsometricRenderHelper)1 IsometricRenderPresets (com.glisco.isometricrenders.client.gui.IsometricRenderPresets)1 IsometricRenderScreen (com.glisco.isometricrenders.client.gui.IsometricRenderScreen)1 BlockEntityAccessor (com.glisco.isometricrenders.mixin.BlockEntityAccessor)1 BlockStateArgumentAccessor (com.glisco.isometricrenders.mixin.BlockStateArgumentAccessor)1 EntitySummonArgumentTypeAccessor (com.glisco.isometricrenders.mixin.EntitySummonArgumentTypeAccessor)1