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 have this event and its supposed to be whenever a player sneak right clicks with a empty glass bottle they take 3 hearts of damage and gives them a vial of blood but it doesn't do anything. Any help appreciated, thanks.

 

Event:

Spoiler

@SubscribeEvent
    public void bloodVialRightClick(LivingEntityUseItemEvent.Start e)
    {
        EntityPlayer player = (EntityPlayer) e.getEntityLiving();
        ItemStack itemUsed = e.getItem();
        
        if(itemUsed == new ItemStack(Items.GLASS_BOTTLE) && player.isSneaking())
        {
            float health = player.getHealth();
            float newHealth = player.getHealth() - 3;
            player.setHealth(newHealth);
            player.inventory.addItemStackToInventory(new ItemStack(ItemRegistry.bloodVial));
        
            itemUsed.shrink(1);
        }
    }

 

Edited by Blackwing_Forged

this should fix things the LivingEntityUseItemEvent.Start only works for items that can be used i.e. food i wrote the fixed code for you below.

EDIT: just realized you wanted sneak-right-click i fixed the code below

 

	//used when rightclicking while looking at a block
	@SubscribeEvent()
	public void rightClickBlock(PlayerInteractEvent.RightClickBlock e){
		//this checks if the entities world is the server we only run this on the server so it doesn't mess with things
		if(!e.getEntity().getEntityWorld().isRemote){
			EntityPlayer player = e.getEntityPlayer();//the player
			//check if player is sneaking
			if(player.isSneaking()){
				ItemStack heldItem = player.getHeldItemMainhand();//the items in the players hand
				//we compare the Item contained in the ItemStack not the ItemStack itself
				//we use .equals here not == only use == for numbers or booleans
				if(heldItem.getItem().equals(Items.GLASS_BOTTLE)){
					onGlassBottleRightClick(player, heldItem);//this is the method where you put the code when the player right-clicks with an item
				}	
			}
			
		}
	}
	
	//used when rightclicking with an item while not looking at a block
	@SubscribeEvent()
	public void rightClickItem(PlayerInteractEvent.RightClickItem e){
			//this checks if the entities world is the server we only run this on the server so it doesn't mess with things
			if(!e.getEntity().getEntityWorld().isRemote){
				EntityPlayer player = e.getEntityPlayer();//the player
				//check if player is sneaking
				if(player.isSneaking()){
					ItemStack heldItem = player.getHeldItemMainhand();//the items in the players hand
					//we compare the Item contained in the ItemStack not the ItemStack itself
					//we use .equals here not == only use == for numbers or booleans
					if(heldItem.getItem().equals(Items.GLASS_BOTTLE)){
						onGlassBottleRightClick(player, heldItem);//this is the method where you put the code when the player right-clicks with an item
					}	
				}
				
			}
	}
	
	private void onGlassBottleRightClick(EntityPlayer player, ItemStack bottlestack){
		player.attackEntityFrom(DamageSource.GENERIC, 3F);
		//player.inventory.addItemStackToInventory(new ItemStack(ItemRegistry.bloodVial));
	}

 

Edited by jtsfour
error

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.