Jump to content

Recommended Posts

Posted

I have been looking into making a command to let you add a spell to your wand before i start making my infuser block to do it but i don't know how to make i started doing it like this

 

 

package net.SpellsApi;

 

import java.util.List;

 

import net.minecraft.command.CommandBase;

import net.minecraft.command.ICommandSender;

import net.minecraft.command.NumberInvalidException;

import net.minecraft.command.WrongUsageException;

import net.minecraft.enchantment.Enchantment;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.server.MinecraftServer;

 

public class CommandSpell extends CommandBase

{

    public String getCommandName()

    {

        return "Spell";

    }

 

    /**

    * Return the required permission level for this command.

    */

    public int getRequiredPermissionLevel()

    {

        return 2;

    }

 

    public String getCommandUsage(ICommandSender par1ICommandSender)

    {

        return par1ICommandSender.translateString("commands.Spell.usage", new Object[0]);

    }

 

    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)

    {

        if (par2ArrayOfStr.length < 2)

        {

            throw new WrongUsageException("commands.spell.usage", new Object[0]);

        }

        else

        {

            EntityPlayerMP var3 = func_82359_c(par1ICommandSender, par2ArrayOfStr[0]);

            int var4 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[1], 0, SpellBase.spellsList.length - 1);

            int var5 = 1;

            ItemStack var6 = var3.getCurrentEquippedItem();

 

            if (var6 == null)

            {

                notifyAdmins(par1ICommandSender, "commands.Spell.noItem", new Object[0]);

            }

            else

            {

                SpellBase var7 = SpellBase.spellsList[var4];

 

                if (var7 == null)

                {

                    throw new NumberInvalidException("commands.Spell.notFound", new Object[] {Integer.valueOf(var4)});

                }

                else if (!var7.func_92037_a(var6))

                {

                    notifyAdmins(par1ICommandSender, "commands.Spell.cantEnchant", new Object[0]);

                }

                else

                {

                    if (par2ArrayOfStr.length >= 3)

                    {

                        var5 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[2], var7.getMinLevel(), var7.getMaxLevel());

                    }

 

                    if (var6.hasTagCompound())

                    {

                        NBTTagList var8 = var6.getEnchantmentTagList();

 

                        if (var8 != null)

                        {

                            for (int var9 = 0; var9 < var8.tagCount(); ++var9)

                            {

                                short var10 = ((NBTTagCompound)var8.tagAt(var9)).getShort("id");

 

                                if (SpellBase.spellsList[var10] != null)

                                {

                                    SpellBase var11 = SpellBase.spellsList[var10];

 

                                    if (!var11.canApplyTogether(var7))

                                    {

                                        notifyAdmins(par1ICommandSender, "commands.spells.cantCombine", new Object[] {var7.getTranslatedName(var5), var11.getTranslatedName(((NBTTagCompound)var8.tagAt(var9)).getShort("lvl"))});

                                        return;

                                    }

                                }

                            }

                        }

                    }

 

                    var6.addSpell(var7, var5);

                    notifyAdmins(par1ICommandSender, "commands.Spell.success", new Object[0]);

                }

            }

        }

    }

 

    /**

    * Adds the strings available in this command to the given list of tab completion options.

    */

    public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)

    {

        return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.getListOfPlayers()) : null;

    }

 

    protected String[] getListOfPlayers()

    {

        return MinecraftServer.getServer().getAllUsernames();

    }

 

    /**

    * Return whether the specified command parameter index is a username parameter.

    */

    public boolean isUsernameIndex(int par1)

    {

        return par1 == 0;

    }

}

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.