Jump to content

Taking fall damage on landing


nickfromgreek

Recommended Posts

i am trying to make afree flight jetpack but on landong i get fall damage why?

 

package enderCraft;

import java.util.EnumSet;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class Tickjetpack implements ITickHandler{
public int tickpnumber = 0;
public int isjactive = 0;
public int isfull = 0;
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
if(type.equals(EnumSet.of(TickType.RENDER)))
{
onRenderTick();
}
else
if(type.equals(EnumSet.of(TickType.CLIENT)))
{
Minecraft mc = Minecraft.getMinecraft();
GuiScreen gui = mc.currentScreen;
if(gui != null)
{
onTickInGui(mc, gui);
}
else
{
onTickInGame(mc);
}
}
}
private void onTickInGame(Minecraft minecraft)
{	

	tickpnumber++;
	if (minecraft.thePlayer.inventory.armorItemInSlot(2) != null)
    {
		System.out.println("Armor ON");
        	System.out.println(tickpnumber);
		minecraft.thePlayer.fallDistance = 0.0F;





        ItemStack itemstack = minecraft.thePlayer.inventory.armorItemInSlot(2);
        
        if (itemstack.itemID == Main.enderjetpack.shiftedIndex)
        {
        	
        	isjactive = tickpnumber;
        	
        	
        	if(minecraft.thePlayer.inventory.hasItem(Item.coal.shiftedIndex)){
        		
        		
        		
        			if(minecraft.theWorld.isRemote){
        				if(isjactive == 200 && isfull == 0){
        		minecraft.thePlayer.addChatMessage("Jetpack at full power");
        		isfull++;
        				}
        		}
        		
        			
        		if(isjactive == 200 && minecraft.thePlayer.capabilities.allowFlying == false){
        			
	        		minecraft.thePlayer.capabilities.allowFlying = true;
	        		minecraft.thePlayer.capabilities.isFlying = true;
	        		tickpnumber = 0;
        		}
        		
        		
        	}else{
        		if(tickpnumber == 200){
        		if(minecraft.theWorld.isRemote){
        		minecraft.thePlayer.addChatMessage("Unexpected error!!Do you have fuel?");
        		}
        		}
        		minecraft.thePlayer.capabilities.allowFlying = false;
        		minecraft.thePlayer.capabilities.isFlying = false;
        		if(isjactive == 400){
        		isjactive = 0;
        		tickpnumber = 0;
        	}
        	}
        	
        	
        }else{
        		if(minecraft.theWorld.isRemote && tickpnumber == 160){
        		minecraft.thePlayer.addChatMessage("You took off your jetpack");
        		}
        		minecraft.thePlayer.capabilities.allowFlying = false;
        		minecraft.thePlayer.capabilities.isFlying = false;
        		tickpnumber = 0;
        }
        
        
    }
}

private void onTickInGui(Minecraft minecraft, GuiScreen gui)
{

}
private void onRenderTick()
{

}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.CLIENT, TickType.RENDER);
}
@Override
public String getLabel()
{
return "TickHandler.CLIENT";
}
}

Link to comment
Share on other sites

@ForgeSubscribe
public void onEntityDammage(LivingHurtEvent event)
{
    if (event.entity instanceof EntityPlayer && event.source == DamageSource.fall && event.isCancelable())
    {
        if(((EntityPlayer)event.entity).inventory.armorInventory[1] instanceof YourJetpack)
        {
            if(((YourJetpack)((EntityPlayer)event.entity).inventory.armorInventory[1]).getIsOn())
            {
                event.setCanceled(true)
            }
        }
    }
}

this assumes that the jetpack is worn on the chest, that the Class<? extends Item> has a method called getIsOn() that returns true if the jetpack is on, and that the Class<? extends Item>.class== YourJetpack.class

 

Edit: Chibill: FeatherFall only goes on boots

Link to comment
Share on other sites

@ForgeSubscribe
public void onEntityDammage(LivingHurtEvent event)
{
    if (event.entity instanceof EntityPlayer && event.source == DamageSource.fall && event.isCancelable())
    {
        if(((EntityPlayer)event.entity).inventory.armorInventory[1] instanceof YourJetpack)
        {
            if(((YourJetpack)((EntityPlayer)event.entity).inventory.armorInventory[1]).getIsOn())
            {
                event.setCanceled(true)
            }
        }
    }
}

this assumes that the jetpack is worn on the chest, that the Class<? extends Item> has a method called getIsOn() that returns true if the jetpack is on, and that the Class<? extends Item>.class== YourJetpack.class

in which class do i put this in the tick handler or in a new class?

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.