Jump to content

Recommended Posts

Posted

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]

Posted

You need to set player.capabilities.allowFlying = false; when you unequip the 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

Posted

ok, but how do i do this? i tried it with

if(itemstack.itemID != Superman.itemArmorSupermanBoots.itemID){
		player.capabilities.allowFlying = false;
	}

in my onArmorTickUpdate method, but it dont work D:

Posted

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

Posted

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 >.<

Posted

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.

Posted

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!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi,  I'm using Forge 47.3.0 for Minecraft 1.20.1 I apologise if this is obvious I am very new to modding for Minecraft. I sucessfully made a mod that launched without errors or crashes (without it doing anything) but in order to add the features I need, I need to add "Custom Portal API [Forge]" as a dependency. However no matter the way I've tried to acheive this, it crashes. I am pretty sure it's not the way I'm putting it in the repositories, the dependencies or the way I'm refrencing it, as I've a hundred diffrent combinations and multiple Maven methods. And on all those diffrent variations I still get this crash: pastebin.com/UhumzZCZ Any tips would be invaluable as I've been loosing my mind over this!
    • Hi, i'm really having problems trying to set the texture to my custom item. I thought i'm doing everything correctly, but all i see is the missing texture block for my item. I am trying this for over a week now and getting really frustrated. The only time i could make the texture work, was when i used an older Forge version (52.0.1) for Minecraft (1.21.4). Was there a fundamental change for textures and models somewhere between versions that i'm missing? I started with Forge 54.1.0 and had this problem, so in my frustration i tried many things: Upgrading to Forge 54.1.1, created multiple new projects, workspaces, redownloaded everything and setting things up multiple times, as it was suggested in an older thread. Therea are no errors in the console logs, but maybe i'm blind, so i pasted the console logs to pastebin anyway: https://pastebin.com/zAM8RiUN The only time i see an error is when i change the models JSON file to an incorrect JSON which makes sense and that suggests to me it is actually reading the JSON file.   I set the github repository to public, i would be so thankful if anyone could take a look and tell me what i did wrong: https://github.com/xLorkin/teleport_pug_forge   As a note: i'm pretty new to modding, this is my first mod ever. But i'm used to programming. I had some up and downs, but through reading the documentation, using google and experimenting, i could solve all other problems. I only started modding for Minecraft because my son is such a big fan and wanted this mod.
    • Please read the FAQ (link in orange bar at top of page), and post logs as described there.
    • Hello fellow Minecrafters! I recently returned to Minecraft and realized I needed a wiki that displays basic information easily and had great user navigation. That’s why I decided to build: MinecraftSearch — a site by a Minecraft fan, for Minecraft fans. Key Features So Far Straight-to-the-Point Info: No extra fluff; just the essentials on items, mobs, recipes, loot and more. Clean & Intuitive Layout: Easy navigation so you spend less time scrolling and more time playing. Optimized Search: Search for anything—items, mobs, blocks—and get results instantly. What I’m Thinking of Adding More data/information: Catch chances for fishing rod, traveling villager trades, biomes info and a lot more. The website is still under development and need a lot more data added. Community Contributions: Potential for user-uploaded tips for items/mobs/blocks in the future. Feature Requests Welcome: Your ideas could shape how the wiki evolves! You can see my roadmap at the About page https://minecraftsearch.com/about I’d love for you to check out MinecraftSearch and see if it helps you find the info you need faster. Feedback is crucial—I want to develop this further based on what the community needs most, so please let me know what you think. Thanks, and happy crafting!
    • Instructions on how to install newer Java can be found in the FAQ
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.