diff options
| author | Arslaan Pathan <[email protected]> | 2026-09-26 17:05:36 +1200 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-09-26 17:05:36 +1200 |
| commit | 14c68eb5ba16774f581d95a39e64a7b303954ffc (patch) | |
| tree | 2888ef11f47c6a639d440300ef580c247ad1bcb1 /src/main/java/com/arslaancodes/arslaansmagichax/commands/HackGive.java | |
| parent | 766ba1c1d977442332cadaaeca93d795baa559df (diff) | |
| download | arslaansmagichax-14c68eb5ba16774f581d95a39e64a7b303954ffc.tar.xz arslaansmagichax-14c68eb5ba16774f581d95a39e64a7b303954ffc.zip | |
migration to 26.2 - run migrateMappings with old loom then bring it back to new
Diffstat (limited to 'src/main/java/com/arslaancodes/arslaansmagichax/commands/HackGive.java')
| -rw-r--r-- | src/main/java/com/arslaancodes/arslaansmagichax/commands/HackGive.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main/java/com/arslaancodes/arslaansmagichax/commands/HackGive.java b/src/main/java/com/arslaancodes/arslaansmagichax/commands/HackGive.java new file mode 100644 index 0000000..db36136 --- /dev/null +++ b/src/main/java/com/arslaancodes/arslaansmagichax/commands/HackGive.java @@ -0,0 +1,45 @@ +package com.arslaancodes.arslaansmagichax.commands; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.minecraft.client.Minecraft; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +public class HackGive { + public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandBuildContext access) { + dispatcher.register(ClientCommandManager.literal("hackgive") + .then(ClientCommandManager.argument("item", StringArgumentType.string()) + .then(ClientCommandManager.argument("amount", IntegerArgumentType.integer(1)) + .executes(HackGive::run) + ) + ) + ); + } + + private static int run(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException { + Minecraft client = Minecraft.getInstance(); + if (client.level == null || client.player == null) return 0; + + String itemId = StringArgumentType.getString(context, "item"); + int amount = IntegerArgumentType.getInteger(context, "amount"); + Item item = BuiltInRegistries.ITEM.getValue(ResourceLocation.parse(itemId)); + if (item == null) { + context.getSource().sendError(Component.literal("Unknown item: " + itemId)); + return 0; + } + + ItemStack stack = new ItemStack(item, amount); + client.player.getInventory().add(stack); + return 1; + } +} |
