Jump to content

[1.10.2] Jump on right click


Grodomir

Recommended Posts

Ayo.
I created an item and i wanted it to make me jump (but higher than jumping with space, and can be used once after regular jump) and i founded OnUse funcution but can't find anything working for jumping.

 

package com.testmod.item;

import com.testmod.TestMod;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

public class JumpRune extends Item implements ItemModelProvider {

	protected String name;

	public JumpRune(String name) {
		this.name = name;
		setUnlocalizedName(name);
		setRegistryName(name);
        this.maxStackSize = 1;
        this.setMaxDamage(64);
		//setCreativeTab(TestMod.creativeTab);
	}
	
	@Override
	public void registerItemModel(Item item) {
		TestMod.proxy.registerItemRenderer(this, 0, name);
	}
	
	@Override
	public JumpRune setCreativeTab(CreativeTabs tab) {
		super.setCreativeTab(tab);
		return this;
	}
	
    public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
    {
        if (!playerIn.capabilities.isCreativeMode)
        {
        	itemStackIn.damageItem(1, playerIn);
        }

        worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
        //playerIn.heal(5f);
        if (!worldIn.isRemote)
        {
        	//playerIn.motionY=0.8;
        	//playerIn.jumpMovementFactor=7f;
        }
        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
    }
}

 

Link to comment
Share on other sites

18 hours ago, V0idWa1k3r said:

Remove the !world.isRemote check. 

Yeah thanks it worked.

 

But.. i have now another problem xD. I tried to limit it to 2 jumps but i don't know what i'm doing wrong :/.

package com.testmod.item;

import javax.swing.text.html.parser.Entity;

import com.testmod.TestMod;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

public class JumpRune extends Item implements ItemModelProvider {

	protected String name;
	private boolean hasJumped = false;
	private int jumps = 0;

	public JumpRune(String name) {
		this.name = name;
		setUnlocalizedName(name);
		setRegistryName(name);
        this.maxStackSize = 1;
        this.setMaxDamage(64);
		//setCreativeTab(TestMod.creativeTab);
	}
	
	@Override
	public void registerItemModel(Item item) {
		TestMod.proxy.registerItemRenderer(this, 0, name);
	}
	
	@Override
	public JumpRune setCreativeTab(CreativeTabs tab) {
		super.setCreativeTab(tab);
		return this;
	}
	
    public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
    {
        if (!playerIn.capabilities.isCreativeMode)
        {
        	itemStackIn.damageItem(1, playerIn);
        }
        if(!playerIn.isAirBorne && hasJumped) 
        {
        	hasJumped = false;
        	//System.out.println("(2) isAirBorne " + playerIn.isAirBorne);
        	//System.out.println("(2) hasJumped " + hasJumped);
        }
        if(playerIn.isAirBorne && playerIn.motionY < 0.7 && !hasJumped && jumps <=1) 
        {
        	playerIn.motionY=0.8;
        	hasJumped = true;
        	jumps+=1;
        	//System.out.println("(1) isAirBorne " + playerIn.isAirBorne);
        	//System.out.println("(1) hasJumped " + hasJumped);
        	//System.out.println("(1) jumps " + jumps);
        }
        if(jumps>=2) {
        	jumps = 0;
        	//System.out.println("(1) jumps " + jumps);
        }
        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
    }
}

 

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.