Jump to content

[1.8] Swapping Items


Jedispencer21

Recommended Posts

What I am trying to do is to have it when you place a button, it swaps your current item with an item with higher damage, the problem I am having is that when I press the button, it takes the weapon from the slot, but it doesn't swap them, it just replaces the current held item with the swapped item, but doesn't take the current item and put it in the other slot.

 

Here is my code for swapping:

 

 

protected static void selectSlot(int slot)

{

if ((slot < 0) || (slot > 8)) return;

 

InventoryPlayer inventory = mc.thePlayer.inventory;

ItemStack stack = inventory.getStackInSlot(slot);

inventory.setInventorySlotContents(inventory.currentItem, stack);

ItemStack stack1 = inventory.getStackInSlot(inventory.currentItem);

inventory.setInventorySlotContents(slot, stack1);

}

 

 

Link to comment
Share on other sites

What I am trying to do is to have it when you place a button, it swaps your current item with an item with higher damage, the problem I am having is that when I press the button, it takes the weapon from the slot, but it doesn't swap them, it just replaces the current held item with the swapped item, but doesn't take the current item and put it in the other slot.

 

Here is my code for swapping:

 

 

protected static void selectSlot(int slot)
{
	if ((slot < 0) || (slot > ) return;

	InventoryPlayer inventory = mc.thePlayer.inventory;
	ItemStack stack = inventory.getStackInSlot(slot);
	inventory.setInventorySlotContents(inventory.currentItem, stack);
	ItemStack stack1 = inventory.getStackInSlot(inventory.currentItem);
	inventory.setInventorySlotContents(slot, stack1);
}

 

 

 

 

You are setting the inventory slot with your item, and then getting the item you just set. You want to do this:

ItemStack slotStack = inventory.getStackInSlot(slot);
ItemStack currentStack = inventory.getStackInSlot(inventory.currentItem);

if (slotStack != null){
    inventory.setInventorySlotContents(inventory.currentItem, slotStack);
} else {
    //return here? if you want to
}

if (currentStack != null){
    inventory.setInventorySlotContents(slot, currentStack);
} else {
    //same as above
}

 

Also, I dont know if you can do these operations on the client side, since you are using Minecraft.getMinecraft().thePlayer (client side player)

Link to comment
Share on other sites

That sort of worked, it swaps the items client side and appears to swap them, but it doesn't actually swap them server side also the other problem I have is that it doesn't select the item with the most damage, it just selects the right most item, this is the selection code:

 

 

public static void swapWeapons()

{

ItemStack currentStack = mc.thePlayer.getHeldItem();

Item currentItem = null;

 

if (currentStack != null) currentItem = currentStack.getItem();

 

int meleeWeaponSlot = getMostDamagingSlot();

 

if ((meleeWeaponSlot < 0))

{

displayNotification("No Weapons Available");

}

else if ((meleeWeaponSlot >= 0))

{

selectSlot(meleeWeaponSlot);

}

}

 

private static int getMostDamagingSlot()

{

ItemStack[] stack = mc.thePlayer.inventory.mainInventory;

double highestDamage = -1.0D;

int highestSlot = -1;

 

for (int i = 0; i < 9; ++i)

{

ItemStack hotbar = stack;

if (hotbar == null || !(hotbar.getItem() instanceof ItemSword) && !(hotbar.getItem() instanceof ItemTool)) continue;

double weaponDamage = getWeaponDamage(hotbar);

if (weaponDamage < highestDamage) continue;

highestDamage = weaponDamage;

highestSlot = i;

}

 

return highestSlot;

}

 

public static double getWeaponDamage(ItemStack stack)

{

Multimap attributeMods = stack.getItem().getAttributeModifiers(stack);

 

if (attributeMods.containsKey(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()))

{

Collection attributes = attributeMods.get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName());

 

if (attributes.size() > 0)

{

Object object = attributes.iterator().next();

 

if ((attributes instanceof AttributeModifier))

{

AttributeModifier weaponMod = (AttributeModifier) object;

return weaponMod.getAmount();

}

}

}

 

return -1.0D;

}

 

 

Link to comment
Share on other sites

Bumping after 40 minutes? Seriously?

 

Anyway, of course it is not swapping server side - you are using Minecraft.getMinecraft().thePlayer, which is CLIENT side only. Use an EntityPlayer from a parameter somewhere, probably in a packet since you are trying to swap with a button press - input interactions are also CLIENT side only.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Slot Bank BRI atau Daftar slot Bank BRI bisa anda lakukan pada situs Museumbola kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di Museumbola adalah anda akan mendapatkan bonus 50% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 10 ribu rupiah saja anda sudah bisa bermain bersama kami di Museumbola. Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.    
    • Museumbola adalah situs judi slot BANK BCA tergacor 2024 dengan minimal deposit  10 ribu rupiah saja anda sudah bisa spin slot gacor di Museumbola. Mulai dari Pragmatic, Pg Soft, Habanero, Playstar, Spadegaming, dan masih banyak lagi. Pilihan slot yang begitu banyak tidak akan membuat anda bosan. Segera daftarkan BANK BCA anda dan jadi member aktif Museumbola. anda akan diberi kesempatan mendapatkan bonus deposit harian setiap hari. Segera Klik DAFTAR sekarang juga sebelum terlambat.  
    • Slot BANK BCA adalah pilihan tergacor untuk memulai bermain slot judi Online dimuka bumi saat ini. Jika anda mempunyai BANK BCA, Anda berkesempatan mendapatkan Akun Pro atau ID pro untuk bermain slot. Tunggu apa lagi? Segera daftarkan diri anda sekarang dan dapatkan kemewahan menang maxwin di Museumbola.
    • SLOT SCATTER HITAM : SLOT MAHJONG SCATTER HITAM - MAHJONG WAYS SCATTER HITAM - SLOT PRAGMATIC SCATTER HITAM KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • SLOT 1000 : SLOT1000 DEPOSIT 1000 VIA DANA - SLOT 1000 VIA QRIS - SLOT DEPOSIT QRIS 1000 - SLOT DEPO 1K - SLOT 1000 BET KECIL KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
  • Topics

×
×
  • Create New...

Important Information

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