Jump to content

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


Recommended Posts

Posted

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!

Posted

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));
								}
							}
						}
					}
				}
			}
		}
	}
}
}

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

    • 39056As a committed high school teacher, I have devoted my career to imparting knowledge about business studies and entrepreneurship to my students. Over the past few years, my professional journey took an unexpected turn, leading me to embark on a thrilling yet challenging adventure. This is the story of how I established my own consulting firm, ventured into the dynamic world of cryptocurrency trading, and faced a nerve-wracking situation that nearly cost me my digital fortune.After years of teaching fundamental business principles, I felt compelled to apply my knowledge in a practical setting. This desire culminated in the launch of US Consulting, a firm aimed at providing affordable and pragmatic business advice to small and medium sized enterprises. Leveraging the skills and extensive network I had cultivated over the years, I quickly built a robust client base. To my astonishment, the firm took off faster than I had anticipated, generating significant revenue and allowing me to realize my entrepreneurial dreams.With the profits from my consulting business, I recognised a burgeoning opportunity in the rapidly evolving field of cryptocurrency. I decided to invest $100,000 in Bitcoin and $70,000 in Ethereum, driven by the potential I saw in these digital assets. I immersed myself in studying market trends and the underlying technology, and my diligence paid off. Within six months, my initial investment had more than doubled, soaring to over $200,000. The exhilaration of witnessing such rapid returns reinforced my belief in the transformative power of cryptocurrencies. This took a dramatic turn one fateful day. During a particularly lively class, a group of students decided to play a prank on me. I had left my phone in my desk drawer, but when I returned to retrieve it, I discovered it was missing. At first, I thought I had misplaced it, but soon the reality of the prank set in. Panic surged through me as I realized that my phone was my primary access point to my cryptocurrency wallets.The sense of helplessness was overwhelming. Without my phone, I could not access my digital assets, and the thought of losing control over my investments was distressing. My frustration morphed into fear as I contemplated the potential financial loss. In this moment of crisis, I remembered the recommendation of Salvage Asset Recovery, a tool that my colleague had mentioned earlier. He assured me that  Salvage Asset Recovery could help recover my digital assets, which brought me a glimmer of hope, especially since I hadn’t set up my security measures properly. Salvage Asset Recovery successfully managed to recover all my cryptocurrency, allowing me to regain control over my investments. This situation not only taught me valuable insights about security but also reinforced my commitment to guiding my students through the complexities of the business world. With the support of Salvage Asset Recovery, I emerged from this ordeal with a renewed sense of purpose, eager to share my recovery ordeal and to raise awareness for  Salvage Asset Recovery good work.   Get in touch with Salvage Asset Recovery via below CONTACT DETAILS TELEGRAM—@Salvageasset  
    • i have removed  phosphor and phosphorcrashfix and it is still crashing https://pastebin.com/ZdA1J25p
    • I have removed stevekunglib and it is still crashing again https://pastebin.com/9vE8pji0
  • Topics

×
×
  • Create New...

Important Information

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