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

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

 

  • Author
34 minutes ago, Lucius Q. User said:

Entities have a "motionY" field. I believe that that is what you're looking for. 

In file (which i gave code in post) i commented motionY because it wasn't working.

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

 

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.