Jump to content

a glitch where I cant give a player a item.


gmod622

Recommended Posts

here code to the GUI:

 

 

 package mod.gmod622.gui;

import java.util.Random;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiIngameMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class GUIenchanter extends GuiScreen
{
private World worldMC;
private EntityPlayer entityP;
private Minecraft mineC;
public static double rand;
private static Random random = new Random();

public GUIenchanter(World world, EntityPlayer entityplayer, Minecraft minecraft)
{
worldMC = world;
entityP = entityplayer;
mineC = minecraft;


}

public void initGui()
{

buttonList.add(new GuiButton(0, width / 2 - 50, height / 2 - 50, 200, 20, "Random Enchanted Book (30 lvls)"));
}
protected void actionPerformed(GuiButton guiButton)
{
if(guiButton.id == 0)
{


if(entityP.experienceLevel >= 30 && entityP.inventory.hasItem(Item.book.itemID)) {
	EnchantedBook(entityP);
       entityP.experienceLevel -= 30;
      
       entityP.inventory.consumeInventoryItem(Item.book.itemID);
}else if(entityP.experienceLevel <= 30)
{
	entityP.addChatMessage("Not enough Levels.");
}else 
{
	entityP.addChatMessage("Book required");
}


}
}

@Override
public boolean doesGuiPauseGame()
{
    return false;
}

public static void EnchantedBook(EntityPlayer par3EntityPlayer)
{
             Enchantment enchantment = Enchantment.enchantmentsBookList[random.nextInt(Enchantment.enchantmentsBookList.length)];
    ItemStack itemstack = new ItemStack(Item.enchantedBook.itemID, 1, 0);
    int l = MathHelper.getRandomIntegerInRange(random, enchantment.getMinLevel(), enchantment.getMaxLevel());
   Item.enchantedBook.getEnchantedItemStack_do(itemstack, new EnchantmentData(enchantment, l));
par3EntityPlayer.inventory.addItemStackToInventory(itemstack);
}

} 

 

Not new to java >> New to modding.

Link to comment
Share on other sites

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.