Jump to content

[1.6.4] how to fly when armor worn ¿?


nic2307

Recommended Posts

Hello, can you please show me a method that allows you to fly when i put on the boots of my armor? i already have a method that gives you effects when you put on the armor, if i allow the player to fly in this method, it works, but when i put off the armor i can still fly. ( yes, im in gamemode 0  ;) ) i have googled it but i didnt find a solution.

Here is my method:

@Override
public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemstack){

	if (itemstack.itemID == Superman.itemArmorSupermanHelmet.itemID){

		player.addPotionEffect(new PotionEffect(Potion.waterBreathing.id, 5, 15));
	}
	if(itemstack.itemID == Superman.itemArmorSupermanPlate.itemID){
		player.addPotionEffect(new PotionEffect(Potion.resistance.id, 5, 15));
		player.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 5, 15));
		player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 5, 15));
	}
	if(itemstack.itemID == Superman.itemArmorSupermanLegs.itemID){
		player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 5, 15));
	}
	if(itemstack.itemID == Superman.itemArmorSupermanBoots.itemID){
		player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 5, 15));
		player.fallDistance = 0.0F;
		player.capabilities.allowFlying = true;
	}
}

and here is my whole armor class:

package net.Superman.mod;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;

public class ItemSupermanArmor extends ItemArmor {

private String texturePath = Superman.modid + ":" + "textures/model/armor/";

public ItemSupermanArmor(int par1, EnumArmorMaterial armorMaterial, int par3, int par4, String type) {
	super(par1, armorMaterial, par3, par4);

	this.setMaxStackSize(1);
	this.setCreativeTab(Superman.supermanTab);
	this.setTextureName(type, par4);
}

private void setTextureName(String type, int armorPart){

	if(armorType == 0 || armorType == 1 || armorType == 3){
		this.texturePath += type + "_layer_1.png";
	}else{
		this.texturePath += type + "_layer_2.png";
	}


}

@Override
public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemstack){

	if (itemstack.itemID == Superman.itemArmorSupermanHelmet.itemID){

		player.addPotionEffect(new PotionEffect(Potion.waterBreathing.id, 5, 15));
	}
	if(itemstack.itemID == Superman.itemArmorSupermanPlate.itemID){
		player.addPotionEffect(new PotionEffect(Potion.resistance.id, 5, 15));
		player.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 5, 15));
		player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 5, 15));
	}
	if(itemstack.itemID == Superman.itemArmorSupermanLegs.itemID){
		player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 5, 15));
	}
	if(itemstack.itemID == Superman.itemArmorSupermanBoots.itemID){
		player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 5, 15));
		player.fallDistance = 0.0F;
		player.capabilities.allowFlying = true;
	}
}





public void registerIcons(IconRegister register){
	this.itemIcon = register.registerIcon(Superman.modid + ":" + this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".")+1));
}

public String getArmorTexture(ItemStack itemStack, Entity entity, int slot, int layer){

	return this.texturePath;

}

}

here is my main mod class:

package net.Superman.mod;

import net.Superman.mod.item.ItemBasic;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.EnumHelper;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;


@Mod(modid = Superman.modid, name = "Superman Mod", version = "Pre-Alpha v0.01")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Superman {

public static final String modid = "superman";


public static Block blockKryptonite;

public static Block oreKryptonite;

public static CreativeTabs supermanTab;

public static EnumToolMaterial toolMaterialKryptonite;

public static EnumToolMaterial toolMaterialKryptonite2;

public static Item itemKryptonite;

public static Item itemAxeKryptonite;

public static Item itemPickaxeKryptonite;

public static Item itemSpadeKryptonite;

public static Item itemHoeKryptonite;

public static Item itemSwordKryptonite;

public static Item itemArmorSupermanHelmet;

public static Item itemArmorSupermanPlate;

public static Item itemArmorSupermanLegs;

public static Item itemArmorSupermanBoots;


public static EnumArmorMaterial armorMaterialSuperman;



@EventHandler
public void load(FMLInitializationEvent e){

	supermanTab = new CreativeTabs("Superman"){
		@SideOnly(Side.CLIENT)
		public int getTabIconItemIndex(){
			return Superman.itemKryptonite.itemID;

		}
	};

	LanguageRegistry.instance().addStringLocalization(supermanTab.getTranslatedTabLabel(), "Superman");




	armorMaterialSuperman = EnumHelper.addArmorMaterial("SupermanArmorMaterial", 100, new int[]{16, 17, 12, 9}, 50);

	blockKryptonite = new BlockKryptonite(1000, Material.iron).setUnlocalizedName("Kryptoniteblock");

	oreKryptonite = new OreKryptonite(1043, Material.iron).setUnlocalizedName("Kryptonite Ore");

	toolMaterialKryptonite = EnumHelper.addToolMaterial("kryptoniteToolMaterial", 3, 9876, 100F, 3.5F, 25);

	toolMaterialKryptonite2 = EnumHelper.addToolMaterial("kryptonite2ToolMaterial", 3, 9876, 100F, 25F, 30);


	itemKryptonite = new ItemKryptonite(999).setUnlocalizedName("kryptonite");

	itemAxeKryptonite = new ItemAxeKryptonite(1005, toolMaterialKryptonite).setUnlocalizedName("axeKryptonite");

	itemPickaxeKryptonite = new ItemPickaxeKryptonite(1006, toolMaterialKryptonite).setUnlocalizedName("pickaxeKryptonite");

	itemSpadeKryptonite = new ItemSpadeKryptonite(1007, toolMaterialKryptonite).setUnlocalizedName("spadeKryptonite");

	itemHoeKryptonite = new ItemHoeKryptonite(1008, toolMaterialKryptonite).setUnlocalizedName("hoeKryptonite");

	itemSwordKryptonite = new ItemSwordKryptonite(1009, toolMaterialKryptonite2).setUnlocalizedName("swordKryptonite");

	itemArmorSupermanHelmet = new ItemSupermanArmor(7012, armorMaterialSuperman, 0, 0, "Superman").setUnlocalizedName("SupermanHelmet");

	itemArmorSupermanPlate = new ItemSupermanArmor(7013, armorMaterialSuperman, 0, 1, "Superman").setUnlocalizedName("SupermanPlate");

	itemArmorSupermanLegs = new ItemSupermanArmor(7014, armorMaterialSuperman, 0, 2, "Superman").setUnlocalizedName("SupermanLegs");

	itemArmorSupermanBoots = new ItemSupermanArmor(7015, armorMaterialSuperman, 0, 3, "Superman").setUnlocalizedName("SupermanBoots");




	 GameRegistry.registerWorldGenerator(new WorldGeneratorSuperman());


	 GameRegistry.addSmelting(oreKryptonite.blockID, new ItemStack(itemKryptonite), 0.5F);



	GameRegistry.addRecipe(new ItemStack(blockKryptonite, 1), new Object[]{

		"XXX",
		"XXX",
		"XXX", 'X', itemKryptonite

	});

	GameRegistry.addRecipe(new ItemStack(itemKryptonite, 9), new Object[]{

		"X", 'X', blockKryptonite

	});

	GameRegistry.addRecipe(new ItemStack(itemAxeKryptonite), new Object[]{

		"XXY",
		"XZY",
		"YZY", 'X', itemKryptonite , 'Z', Item.stick
	});

	GameRegistry.addRecipe(new ItemStack(itemPickaxeKryptonite), new Object[]{

		"XXX",
		"YZY",
		"YZY", 'X', itemKryptonite, 'Z', Item.stick

	});

	GameRegistry.addRecipe(new ItemStack(itemSpadeKryptonite), new Object[]{

		"YXY",
		"YZY",
		"YZY", 'X', itemKryptonite, 'Z', Item.stick

	});

	GameRegistry.addRecipe(new ItemStack(itemHoeKryptonite), new Object[]{

		"XXY",
		"YZY",
		"YZY", 'X', itemKryptonite, 'Z', Item.stick

	});

	GameRegistry.addRecipe(new ItemStack(itemSwordKryptonite), new Object[]{

		"YXY",
		"YXY",
		"YZY", 'X', itemKryptonite, 'Z', Item.stick

	});

	GameRegistry.addRecipe(new ItemStack(itemArmorSupermanHelmet), new Object[]{

		"XXX",
		"XYX",
		"ZZZ", 'X', itemKryptonite, 'Y', Block.obsidian

	});

	GameRegistry.addRecipe(new ItemStack(itemArmorSupermanHelmet), new Object[]{

		"ZZZ",
		"XXX",
		"XYX", 'X', itemKryptonite, 'Y', Block.obsidian
	});

	GameRegistry.addRecipe(new ItemStack(itemArmorSupermanPlate), new Object[]{

		"XYX",
		"XXX",
		"XXX", 'X', itemKryptonite, 'Y', Block.blockLapis

	});

	GameRegistry.addRecipe(new ItemStack(itemArmorSupermanLegs), new Object[]{

		"XXX",
		"XYX",
		"XZX", 'X', itemKryptonite, 'Y', Block.blockLapis

	});

	GameRegistry.addRecipe(new ItemStack(itemArmorSupermanBoots), new Object[]{

		"XYX",
		"XZX",
		"ZZZ", 'X', itemKryptonite, 'Y', Item.redstone

	});

	GameRegistry.addRecipe(new ItemStack(itemArmorSupermanBoots), new Object[]{

		"ZZZ",
		"XYX",
		"XZX", 'X', itemKryptonite, 'Y', Item.redstone

	});



	NetworkRegistry.instance().registerConnectionHandler(new ConnectionHandler());




	registerBlock(blockKryptonite, blockKryptonite.getUnlocalizedName().substring(5));

	registerBlock(oreKryptonite, oreKryptonite.getUnlocalizedName().substring(5));

	registerItem(itemKryptonite, "Kryptonite");

	registerItem(itemAxeKryptonite, "Kryptonite Axt");

	registerItem(itemPickaxeKryptonite, "Kryptonite Spitzhacke");

	registerItem(itemSpadeKryptonite, "Kryptonite Schaufel");

	registerItem(itemHoeKryptonite, "Kryptonite Hoe");

	registerItem(itemSwordKryptonite, "Kryptonite Schwert");

	registerItem(itemArmorSupermanHelmet, "Superman Helmet");

	registerItem(itemArmorSupermanPlate, "Superman Chestplate");

	registerItem(itemArmorSupermanLegs, "Superman Leggings");

	registerItem(itemArmorSupermanBoots, "Superman Boots");






}
public void registerBlock(Block block, String name){
	GameRegistry.registerBlock(block, block.getUnlocalizedName());
	LanguageRegistry.addName(block, name);
}

public void registerItem(Item item, String name){
	GameRegistry.registerItem(item, item.getUnlocalizedName());
	LanguageRegistry.addName(item, name);
}
}

 

i hope you can help me :) (sorry for my bad english, if it is bad ;) ) [glow=green,2,300]thx[/glow]

Link to comment
Share on other sites

public class YourEventHandler
{
private static int flyTime = 0;

@ForgeSubscribe
public void onLivingFallEvent(LivingFallEvent event) {
// if (flyTime > 0) { event.distance = 0; } // does NOT work correctly
if (flyTime > 0) { event.setCanceled(true); } // will not take fall damage while flying
}

/*
* Use whichever Event works best for you; I used ArrowLooseEvent because
* my scroll item charges up like a bow and activates upon release.
* A list of Forge Events can be found here: http://www.minecraftforge.net/wiki/Event_Reference
*/
@ForgeSubscribe
public void onArrowLooseEvent(ArrowLooseEvent event) {
// Check that the entity is a player
if (event.entity != null && event.entity instanceof EntityPlayer) {
// Check that the item (named 'bow' in the event) being used is of the right class
if (event.bow != null && event.bow.getItem() instanceof ItemScroll) {
// Check if the item is the one that allows you to fly
if (((ItemScroll)event.bow.getItem()).getEffectType() == ItemScroll.FLY) {
// Set how long you are allowed to fly, or use a toggle instead
flyTime = ((ItemScroll)event.bow.getItem()).getDuration();
}
}
}
}
}

@ForgeSubscribe
public void onLivingUpdateEvent(LivingUpdateEvent event)
{
if (event.entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.entity;
ItemStack itemInUse = player.getItemInUse();

if (itemInUse != null) {
updateItems(player, itemInUse);
}

// Need to allowFlying every update or it's difficult to get off the ground
if (flyTime > 0) { --flyTime; player.capabilities.allowFlying = true; }

if (flyTime == 0 && !player.capabilities.isCreativeMode) {
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false; // drops player out of sky when timer runs out <ouch!>
}
}
}
}

 

Seriously the first thing i found when i googled flying armor minecraft forge.

 

EDIT: src http://www.minecraftforum.net/topic/1828278-forge-flying-with-custom-armor/

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Link to comment
Share on other sites

yes, thank you, i found that too, but the problem here is, that im getting a lot of errors, even if i import all the things that i can import... for example im getting an error everywhere at ItemScroll, i cant import that. or there is an error at updateItems eclipse (and me) dont know this method. maybe im too dumb >.<

Link to comment
Share on other sites

Posting arbitrary code and expecting it to help other people is not helpful at all. Do not post code with your own classes imported or defined in some outside invisible method. It just frustrates everyone.

Link to comment
Share on other sites

You could have your tick handler look for the armor in the slot by looking at the nbt data and when you take off the armor it disables

Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!

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.