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

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!

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/

  • Author

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...

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.