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

Heyho,

 

iam trying to code a small PvP Mod and i need to copy the damage value from one Bow to another Bow.....

 

ive absolutely no idea how to do this.

 

it needs to work with this:D

 

if(player.getCurrentEquippedItem() != null)

if(hand.getItem() == MyMod.testBow)

{

if(player.inventory.hasItem(Items.arrow)){

player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);

player.inventory.addItemStackToInventory(new ItemStack(Items.bow));

 

  • Author

... i got it myself :D

 

int itemDamage = hand.getItemDamage();

if(player.getCurrentEquippedItem() != null)

if(hand.getItem() == MYMod.testBow)

{

if(player.inventory.hasItem(Items.arrow)){

player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);

 

player.inventory.addItemStackToInventory(new ItemStack(Items.bow, 1, (int) itemDamage));

  • Author

hmm now ive a new problem^^

 

i need to copy the enchantments the same way......

 

this time i dont think i will get this to work:-(

 

can some one help me pls?!

  • Author

i think that will not work for my code since i use 2 diferent bows...

 

    public static class Handler implements IMessageHandler<KeyMessage, IMessage>

    {

     

        @Override

        public IMessage onMessage(KeyMessage message, MessageContext ctx)

        {

        //String string = message.text;

 

       

       

EntityPlayer player = ctx.getServerHandler().playerEntity;

ItemStack hand = player.getCurrentEquippedItem();

int itemDamage = hand.getItemDamage();

 

if(player.getCurrentEquippedItem() != null)

if(hand.getItem() == SkyPvP.testBow)

{

if(player.inventory.hasItem(Items.arrow)){

player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);

 

player.inventory.addItemStackToInventory(new ItemStack(Items.bow, 1, (int) itemDamage));

System.out.println("Normal Bow");

}

 

}

else if(hand.getItem() == Items.bow)

{

if(player.inventory.hasItem(SkyPvP.fireArrow1)){

player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);

player.inventory.addItemStackToInventory(new ItemStack(SkyPvP.testBow, 1, (int) itemDamage));

System.out.println("Test Bow");

}

 

 

}

return null;

        }

    }

}

 

 

hmmmm

I think you could just get the nbt of one bow and transfer it to the other, since enchants are stored in nbt. that is if you're not using nbt for anything...

The proud(ish) developer of Ancients

  • Author

yea ive tryed that but i just dont  how i add the "NBTTagList enchantment"

 

NBTTagList enchantment = hand.getEnchantmentTagList();  <----thats what ive tryed

 

 

but i dont know what i need to add here:

 

 

player.inventory.addItemStackToInventory(new ItemStack(Items.bow, 1, (int) itemDamage));

 

 

 

sry that i ask so easy things... 

 

i just dont get it right...

  • Author

sry but i think i dont get it....

 

EntityPlayer player = ctx.getServerHandler().playerEntity;

ItemStack hand = player.getCurrentEquippedItem();

 

??? --> ItemStack oldBow = player.getCurrentEquippedItem();

??? --> ItemStack newBow = oldBow.copy();

 

int itemDamage = hand.getItemDamage();

if(player.getCurrentEquippedItem() != null)

if(hand.getItem() == SkyPvP.testBow)

{

if(player.inventory.hasItem(Items.arrow)){

player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);

 

player.inventory.addItemStackToInventory(new ItemStack(Items.bow, 1, (int) itemDamage));

System.out.println("Normal Bow");

}

 

}

else if(hand.getItem() == Items.bow)

{

if(player.inventory.hasItem(SkyPvP.fireArrow1)){

player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);

player.inventory.addItemStackToInventory(new ItemStack(SkyPvP.testBow, 1, (int) itemDamage));

System.out.println("Test Bow");

}

 

 

}

return null;

        }

    }

 

 

newBow.func_150996_a(theOtherBowItem); // setItem

 

ive no idea what to do with this...

 

 

  • Author

ok I have now understood the concept

 

but how do I bring it in my code......

 

my code:

 

press button->packethandler:

 

switch the current bow to another bow if my inv has its specific arrow in it.

 

(ich sitze seit heut mittag an dem problem und werd noch wahnsinnig:-()

  • Author

Also:

 

deine 3 sachen müssen die hier rein? und wenn ja wo bzw ich brauch ein beispiel da ich noch nicht alles in java/forge verstehe:

 

oder muss ich die sachen in die main modfile packen?

 

    public static class Handler implements IMessageHandler<KeyMessage, IMessage>

    {

     

        @Override

        public IMessage onMessage(KeyMessage message, MessageContext ctx)

        {

        //String string = message.text;

 

       

       

EntityPlayer player = ctx.getServerHandler().playerEntity;

ItemStack hand = player.getCurrentEquippedItem();

int itemDamage = hand.getItemDamage();

if(player.getCurrentEquippedItem() != null)

if(hand.getItem() == SkyPvP.testBow)

{

if(player.inventory.hasItem(Items.arrow)){

player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);

 

player.inventory.addItemStackToInventory(new ItemStack(Items.bow, 1, (int) itemDamage));

System.out.println("Normal Bow");

}

 

}

else if(hand.getItem() == Items.bow)

{

if(player.inventory.hasItem(SkyPvP.fireArrow1)){

player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);

player.inventory.addItemStackToInventory(new ItemStack(SkyPvP.testBow, 1, (int) itemDamage));

System.out.println("Test Bow");

}

 

 

}

return null;

        }

    }

}

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.