Jump to content

[SOLVED][1.6.4]Helmet that adds Infinity to Items Help


Clawx207

Recommended Posts

As the title says, i am trying to make this item. Here's my current code for it:

 

 

public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack item)

{

        if (player.getCurrentItemOrArmor(4) != null)

        {

            ItemStack helmet = player.getCurrentItemOrArmor(4);

            if (helmet.getItem() == this)

            {

            if(player.getCurrentEquippedItem().getItem() instanceof ItemBow)

            {

                player.getCurrentEquippedItem().addEnchantment(Enchantment.infinity, 1);

            }

            }

        }

}

 

 

It "Kind of works". As it keeps enchanting the bow to the point where it looks like this then crashes:

 

infinity I

infinity I

infinity I

infinity I

infinity I

infinity I

infinity I

 

 

How would i make it so it only enchants the item once?

 

 

 

Link to comment
Share on other sites

if(!player.getCurrentEquippedItem().hasEnchantment(Enchantment.infinity, 1))
{
     player.getCurrentEquippedItem().addEnchantment(Enchantment.infinity, 1);
}

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

You will also need to find a way to remove the enchantment when they're no longer holding it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

if(!player.getCurrentEquippedItem().hasEnchantment(Enchantment.infinity, 1))
{
     player.getCurrentEquippedItem().addEnchantment(Enchantment.infinity, 1);
}

 

.hasEnchantment does not exist...?

 

 

Edit:

 

Ahhh but this works:

 

if(!player.getCurrentEquippedItem().hasEffect(Enchantment.infinity.effectId))

 

 

Link to comment
Share on other sites

Also:

 

You will also need to find a way to remove the enchantment when they're no longer holding it.

 

Tip:

There are multiple ways to get rid of an item so it's no longer your active one.

Tip #2:

One of them involves Item Frames.  An item that goes into a frame ceases to exist with no function calls or events.  So unless your plan is to let the player have infinite* free infinity bows, this is an idea that is doomed to failure.

Tip #3:

The helmet no longer being worn / ceasing to exist will also need to be covered.

 

*Pun not intended, but enjoyed.  And only "inifinite-until-helmet-breaks" of course.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I will work on that next, but right now every time i wear the helmet and hold a bow i get this crash:

 

 

2014-01-20 23:07:43 [iNFO] [sTDOUT] Description: Ticking player

2014-01-20 23:07:43 [iNFO] [sTDOUT]

2014-01-20 23:07:43 [iNFO] [sTDOUT] java.lang.NullPointerException

2014-01-20 23:07:43 [iNFO] [sTDOUT] at MGM.InfBandana.onArmorTickUpdate(InfBandana.java:35)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:367)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:606)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1826)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:342)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:328)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.network.NetServerHandler.handleFlying(NetServerHandler.java:304)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.network.packet.Packet10Flying.processPacket(Packet10Flying.java:51)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)

2014-01-20 23:07:43 [iNFO] [sTDOUT] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)

 

 

This is my updated code:

 

 

public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack item)

{

int i;

        if (player.getCurrentItemOrArmor(4) != null)

        {

            ItemStack helmet = player.getCurrentItemOrArmor(4);

            if (helmet.getItem() == this)

            {

            if(player.getCurrentEquippedItem().getItem() instanceof ItemBow)

            {

            if(!player.getCurrentEquippedItem().hasEffect(Enchantment.infinity.effectId))

            {

                player.getCurrentEquippedItem().addEnchantment(Enchantment.infinity, 1);

            }

            }

            }

        }

}

 

 

"if(player.getCurrentEquippedItem().getItem() instanceof ItemBow)" is the line of code it is having issues with

Link to comment
Share on other sites

Haha! One up to you good sir!

 

Changed some things around here's what i'm going with for right now!

 

 

public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack item)

{

ItemStack itemstack = player.getCurrentEquippedItem();

 

        if (player.getCurrentItemOrArmor(4) != null)

        {

            ItemStack helmet = player.getCurrentItemOrArmor(4);

            if (helmet.getItem() == this)

            {

            if(itemstack != null && itemstack.itemID == Item.bow.itemID)

            {

            if(!itemstack.hasEffect(Enchantment.infinity.effectId))

            {

            itemstack.addEnchantment(Enchantment.infinity, 1);

            }

            }

            }

        }

}

 

 

Thank you guys! Much more responsive than the minecraft forums!

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.