Jump to content

(SOLVED)[1.7.2] Creating potion that makes you fly


DonKresenko

Recommended Posts

I'm trying to make an item that gives you a fly potion when you right click with it. I made everything, should work but it ain't

 

Here's some src

 

In my main class

public static Potion flyingEffect;
flyingEffect = (new FlyingPotionEffect(32, false, 7889559)).setPotionName("potion.fly");

 

FlyingPotionEffect.class

public class FlyingPotionEffect extends Potion {

protected FlyingPotionEffect(int par1, boolean par2, int par3) {
	super(par1, par2, par3);
}

public void performEffect(EntityLivingBase lb, int par2) {
	if (this.id == InfusionCraft.flyingEffect.id && lb instanceof EntityPlayer) {
		if (!lb.worldObj.isRemote)
			((EntityPlayer)lb).capabilities.allowFlying = true;
	}      
    }
}

 

Item on right click method

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer player) {
	player.addPotionEffect((new PotionEffect(InfusionCraft.flyingEffect.id, 200, 1))); // ticks 20, level 1
    return par1ItemStack;
}

 

 

 

I hope you guys can help me :)

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

Link to comment
Share on other sites

Wow, i set the id to 31 and it worked :D When i right click with item i get my potion of flying and i can fly. That cool! But 1 thing...when the potion effect ends i can still fly. Is there a way that i can check if the player has potion effect? And where should i put it?

 

 

Here's the PotionEffect class

public class FlyingPotionEffect extends Potion {

protected FlyingPotionEffect(int par1, boolean par2, int par3) {
	super(par1, par2, par3);
}

@Override
public void performEffect(EntityLivingBase lb, int par2) {
	if (this.id == InfusionCraft.flyingEffect.id && lb instanceof EntityPlayer) {
			((EntityPlayer)lb).capabilities.allowFlying = true;
	}      
    }

@Override
public boolean isReady(int par1, int par2) {
	return this.id == InfusionCraft.flyingEffect.id;
}
}

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

Link to comment
Share on other sites

Well, I can't get it to work. I tried everything. Setting if statements, changing 0 to 1, nothing. Here's what i did so far

@Override
public void performEffect(EntityLivingBase lb, int ticksLeft) {
	if(this.id == InfusionCraft.flyingEffect.id && lb instanceof EntityPlayer) {
		if(ticksLeft == 0) {
			((EntityPlayer)lb).capabilities.allowFlying = false;
			((EntityPlayer)lb).capabilities.isFlying = false;
		}
		else
			((EntityPlayer)lb).capabilities.allowFlying = true;
	}
    }

 

 

 

 

Also, I tried to add an icon for the potion effect. The image is loaded and it's there, just it doesn't show the whole image. Here's what i mean

http://i.imgur.com/XApGbPg.png

 

It's like the image is too big (Don't think so, i copied the vanilla template 17x17 for potion icon)

 

Here's my class

package com.nuclearbanana.ic;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;

public class FlyingPotionEffect extends Potion {

private static final ResourceLocation icon = new ResourceLocation(InfusionCraft.modid,"/textures/potion/fly.png");

protected FlyingPotionEffect(int par1, boolean par2, int par3) {
	super(par1, par2, par3);
	this.setIconIndex(0, 0);
}

@Override
public void performEffect(EntityLivingBase lb, int ticksLeft) {
	if(this.id == InfusionCraft.flyingEffect.id && lb instanceof EntityPlayer) {
		if(ticksLeft == 0) {
			((EntityPlayer)lb).capabilities.allowFlying = false;
			((EntityPlayer)lb).capabilities.isFlying = false;
		}
		else
			((EntityPlayer)lb).capabilities.allowFlying = true;
	}
    }

@Override
public boolean isReady(int par1, int par2) {
	return this.id == InfusionCraft.flyingEffect.id;
}

@Override
@SideOnly(Side.CLIENT)
public boolean hasStatusIcon() {
    Minecraft.getMinecraft().renderEngine.bindTexture(icon);
    return true;
}
}

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

Link to comment
Share on other sites

After debugging, i saw that it only prints the number 1, always. So when i set if it is 0, that code never executes

@Override
public void performEffect(EntityLivingBase lb, int ticksLeft) {
	if(this.id == InfusionCraft.flyingEffect.id && lb instanceof EntityPlayer) {
		if(ticksLeft == 1) {
			((EntityPlayer)lb).capabilities.allowFlying = true;
			System.out.println("If: "+ticksLeft);
		}
		else {
			((EntityPlayer)lb).capabilities.allowFlying = false;
			((EntityPlayer)lb).capabilities.isFlying = false;
			System.out.println("Else: "+ticksLeft);
		}
		System.out.println("N: "+ticksLeft);
	}
    }

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

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.