Posted July 5, 20178 yr 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); } }
July 5, 20178 yr 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.
July 5, 20178 yr Look at what EntityPlayer.jump()does. Edited July 5, 20178 yr by Kokkie Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
July 6, 20178 yr 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); } }
July 6, 20178 yr Items are singletons. If you set a variable for one it will affect all items. You need to attach either meta data or nbt to an ItemStack instance of the item.
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.