Jump to content

--ItemStack not updating in the GUI [Fixed, but with new problems]


navybofus

Recommended Posts

I wanted to see where the problem lies before I post a bug report.

 

I am using a PlayerInteractEvent handler to take an item from the player and immediately give them another item in exchange. This works fine except the itemstack that the player is holding only decreases (visually) once every other activation. However the result is correct. Even though the number of items doesn't decrease, the exchanged item increases accordingly.

 

The reason I said "visually" above is because on the next exchange the number of items, even after switching to another active slot, does decrease. This make the problem a visual bug.

 

Now, whether or not this bug is forge, minecraft or me. I'm not sure. Has anyone else experienced this sort of thing?

 

I can post my code if needed, but I don't really think its necessary. If anyone needs more information please let me know. Thanks!

Link to comment
Share on other sites

You're doing things on the client side. Try doing it on the server side.

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

once again, I didn't think about the server... isRemote saved me again.

 

EDIT: Okay, so I'm new to this event_bus thing and the isRemote check worked in fixing the visual bug, but something is still wrong. My creative functionality is gone. Can anyone help me find the mistake? Any notes on my code will be helpful as I learn more and more every day. Oh, and sorry that I don't javadoc my methods or comment many code parts.

 

package com.navybofus.sweettea;

import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class CauldronActivateHandler {

public CauldronActivateHandler(){

}

@SubscribeEvent(priority=EventPriority.HIGHEST)
public void handleCauldronActivate(PlayerInteractEvent event) {

	EntityPlayer player = event.entityPlayer;
	World world = player.worldObj;
	int x = event.x;
	int y = event.y;
	int z = event.z;
	Block block = world.getBlock(x, y, z);

	ItemStack itemstack = new ItemStack(BaseSweetTea.itemEmptyCup);

	if(world.isRemote){
		// Not sure if anything should go here
	} else {

		if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
		{
			if(player.getHeldItem() != null){

				if(player.getHeldItem().getItem() == itemstack.getItem()){

					if(block == Blocks.cauldron)
					{
						int metadata = world.getBlockMetadata(x, y, z);

						if(metadata > 0)
						{      // If in creative, don't take a cup or water, but give a water cup.
							if (!player.capabilities.isCreativeMode)
							{
								ItemStack itemstack1 = new ItemStack(BaseSweetTea.itemColdWaterCup);

								if (!player.inventory.addItemStackToInventory(itemstack1))
								{
									world.spawnEntityInWorld(new EntityItem(world, (double)x + 0.5D, (double)y + 1.5D, (double)z + 0.5D, itemstack1));
								}
								else if (player instanceof EntityPlayerMP)
								{//Not sure what this does exactly.
									((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer);
								}

								--player.getHeldItem().stackSize;
								player.inventory.addItemStackToInventory(itemstack1);
								world.setBlockMetadataWithNotify(x, y, z, MathHelper.clamp_int(metadata - 1, 0, 3), 2);

								if (player.getHeldItem().stackSize <= 0)
								{
									player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
								}

							} else {

								if(!player.inventory.addItemStackToInventory(new ItemStack(BaseSweetTea.itemColdWaterCup))){
									player.inventory.addItemStackToInventory(new ItemStack(BaseSweetTea.itemColdWaterCup));
								}
							}
						}
					}
				}
			}
		}
	}
}
}

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.