Jump to content

Recommended Posts

Posted

good nights 

this time this post is not an accident

actually i think i found a bug

 

the trouble is i can't replace  the selected itemStack for another using the methods from the item class like

onItemUseFinish()  or onPlayerStoppedUsing() as i do in 1.8

 

this is the post with original question i made in the forums

http://www.minecraftforge.net/forum/index.php/topic,37521.msg197729.html#msg197729

 

lets say i have this ItemStackIn  is in the slot 1 from the hotbar if in the item code i do something like

 

@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
if (!worldIn.isRemote){
if (entityLiving instanceof EntityPlayer) {
EntityPlayer playerIn = (EntityPlayer) entityLiving;
playerIn.inventory.setInventorySlotContents( 1, replaceItemStack);
}
}

 

the change is not happening and i remain with ItemStackIn in the slot 1

 

but if i set the item in any other slot

playerIn.inventory.setInventorySlotContents( 2, replaceItemStack);

i end having ItemStackIn in the slot 1  and replaceItemStack in slot 2

 

the only slot i couldn't replace is the one containing the item on use 

 

could you fix this

Thank for reading

 

 

 

 

[/code]

Posted

Nup

 

but i test the creative surviver and mode 2 still fail in all

 

im using

	
// ############################################################################################3
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {

	if (!worldIn.isRemote) {

		if (entityLiving instanceof EntityPlayer) {

			ItemStack replaceItemStack = new ItemStack(MMMateriales.materialesSuspensionderedstoneActivada, 1, 0);
			Item comparationItem = MMMateriales.materialesSuspensionderedstone;

			EntityPlayer playerIn = (EntityPlayer) entityLiving;
			EnumHand ManoActiva = playerIn.getActiveHand();

			ItemStack leftHand = playerIn.getHeldItem(EnumHand.OFF_HAND);
			ItemStack rightHand = playerIn.getHeldItem(EnumHand.MAIN_HAND);

			int hand = playerIn.inventory.currentItem;
			ItemStack itemstack = null;

			itemstack = playerIn.inventory.getStackInSlot(hand);
			if (ManoActiva != null && ManoActiva == EnumHand.MAIN_HAND && itemstack.getItem() == comparationItem) {

				chat.chatm(playerIn, "replacing the Item in MAIN_HAND");
				playerIn.inventory.setInventorySlotContents(hand, replaceItemStack);
				//playerIn.inventory.markDirty();
			}

			itemstack = playerIn.inventory.getStackInSlot(40);
			if (ManoActiva != null && ManoActiva == EnumHand.OFF_HAND && itemstack.getItem() == comparationItem) {
				chat.chatm(playerIn, "replacing the Item in OFF_HAND");


				playerIn.inventory.setInventorySlotContents(40, replaceItemStack);
				//playerIn.inventory.decrStackSize(40, 1);
				//playerIn.inventory.markDirty();
				//playerIn.inventory.inventoryChanged = true;
			}

			int playerInvZise = playerIn.inventory.getSizeInventory();

			for (int i = 0; i < playerInvZise; ++i) {
				itemstack = playerIn.inventory.getStackInSlot(i);

				if (itemstack != null) {
					System.out.println("SLOT[" + i + "]=" + itemstack.getUnlocalizedName());
				}
			}

		}
	}

	return stack;
}

 

the funny part is that i only cant'not change the selected item but i can change hatever else i want so if i made

 

//MainHand
			itemstack = playerIn.inventory.getStackInSlot(hand);
			if (ManoActiva != null && ManoActiva == EnumHand.MAIN_HAND && itemstack.getItem() == comparationItem) {

				chat.chatm(playerIn, "replacing the Item in MAIN_HAND");
				playerIn.inventory.setInventorySlotContents(40, replaceItemStack);
				//playerIn.inventory.markDirty();
			}

 

being the selected item in the right hand i can change the item in the off hand

and also i can consume the item in the main hand even if its the selected using

playerIn.inventory.decrStackSize(hand, 1);

 

but is not allow to change the item in the main hand for any other if this is the selected  itemStack

 

 

 

 

 

 

 

 

 

 

Posted

well is more like it changes to activates but inmediately comes back to normal

 

alsi if make the change here works 


@Override
public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack itemStackIn) {

	World worldIn = entityLiving.worldObj;

	if (entityLiving instanceof EntityPlayer) {
		EntityPlayer playerIn = (EntityPlayer) entityLiving;

	ItemStack replaceItemStack = new ItemStack(MMMateriales.materialesSuspensionderedstoneActivada, 1, 0);

	int handi = playerIn.inventory.currentItem;
	chat.chatm(playerIn, "replacing the Item in MAIN_HAND");
	playerIn.inventory.setInventorySlotContents(handi, replaceItemStack);

	}

	return true;
}

 

but if i made it here onItemRightClick like this


@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn,
		EnumHand hand) {
	boolean sePudo = true;


	ItemStack replaceItemStack = new ItemStack(MMMateriales.materialesSuspensionderedstoneActivada, 1, 0);

	int handi = playerIn.inventory.currentItem;
	chat.chatm(playerIn, "replacing the Item in MAIN_HAND");
	playerIn.inventory.setInventorySlotContents(handi, replaceItemStack);



	return sePudo ? new ActionResult(EnumActionResult.PASS, itemStackIn) : new ActionResult(EnumActionResult.FAIL, itemStackIn);
}

is curious coze its visually changing for a brief moment but comes back to normal

 

 

 

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.