Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello! Ive made a portable book enchater but when im in mutiplayer I get a weird glitch the video will show you what i mean.

 

 

 

Please help

Not new to java >> New to modding.

  • Author

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.

You have to use packets to send the changes induced by actionPerformed(args) to the server.

There are tutorials for PacketHandler and such on the wiki.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.