Enchantement Amure et Effet Nourriture



  • Bonjour à tous,

    aujourd'hui, j'ai deux questions :

    1 Comment créer un enchantement sur une armures qui donne un effet au joueur?

    2 Comment mettre un effet au joueur quand il mange quelque chose ?

    Voilà c'est tout merci d'avance pour votre aide et si vous voulez plus de détails demandez .

    Bonne journée


  • Administrateurs



  • excuse moi mais le  .setPotionEffect(Potion.effet.id, 5, 2, 1.0F) ne fonctionne pas



  • il faut un player.set…, ensuite si jamais tu ne peux pas ajoute dessous le nom de la classe ou au dessus de la méthode EntityPlayer player; et la ça sera bon.



  • je comprends pas ce que tu veux dire si tu pouvais m'éclairer ce serais gentils  🙂


  • Administrateurs

    Envoie ton code.



  • main class :

    package mod.kingdom.common;
    
    import java.awt.Color;
    
    import net.minecraft.block.Block;
    import net.minecraft.block.material.Material;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.enchantment.Enchantment;
    import net.minecraft.entity.EnumCreatureType;
    import net.minecraft.init.Blocks;
    import net.minecraft.item.Item;
    import net.minecraft.item.Item.ToolMaterial;
    import net.minecraft.item.ItemArmor.ArmorMaterial;
    import net.minecraft.item.ItemFood;
    import net.minecraft.item.ItemSeeds;
    import net.minecraft.potion.Potion;
    import net.minecraft.world.biome.BiomeGenBase;
    import net.minecraftforge.common.MinecraftForge;
    import net.minecraftforge.common.util.EnumHelper;
    import mod.kingdom.proxy.ClientProxy;
    import mod.kingdom.proxy.CommonProxy;
    import cpw.mods.fml.common.Mod;
    import cpw.mods.fml.common.Mod.EventHandler;
    import cpw.mods.fml.common.Mod.Instance;
    import cpw.mods.fml.common.SidedProxy;
    import cpw.mods.fml.common.event.FMLInitializationEvent;
    import cpw.mods.fml.common.event.FMLPostInitializationEvent;
    import cpw.mods.fml.common.event.FMLPreInitializationEvent;
    import cpw.mods.fml.common.registry.EntityRegistry;
    import cpw.mods.fml.common.registry.GameRegistry;
    
    @Mod(modid = "kingdom", name = "Kingdom", version = "1.0.0")
    
    public class Kingdom
    {
        @Instance("kingdom")
        public static Kingdom instance;
    
        @SidedProxy(clientSide = "mod.kingdom.proxy.ClientProxy", serverSide = "mod.kingdom.proxy.CommonProxy")
        public static ClientProxy proxy;
    
        public static BiomeGenBase[] biomes = new BiomeGenBase[] {BiomeGenBase.plains, BiomeGenBase.extremeHills, BiomeGenBase.beach, BiomeGenBase.desert, BiomeGenBase.desertHills, BiomeGenBase.extremeHillsEdge, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.icePlains, BiomeGenBase.iceMountains, BiomeGenBase.river, BiomeGenBase.birchForest, BiomeGenBase.birchForestHills, BiomeGenBase.coldBeach, BiomeGenBase.coldTaiga, BiomeGenBase.coldTaigaHills, BiomeGenBase.deepOcean, BiomeGenBase.extremeHillsPlus, BiomeGenBase.jungleEdge, BiomeGenBase.megaTaiga, BiomeGenBase.megaTaigaHills, BiomeGenBase.mesa, BiomeGenBase.mesaPlateau, BiomeGenBase.mesaPlateau_F, BiomeGenBase.roofedForest, BiomeGenBase.savanna, BiomeGenBase.savannaPlateau, BiomeGenBase.stoneBeach};
    
        public static Block blockOrgeCulture;
        public static Item itemOrge, orgeSeed;
    
        public static Block blockAzuriteOre;
        public static Block blockPyriteOre;
        public static Block blockPyrite;
        public static Block blockPlatine;
        public static Block blockAzurite;
    
        public static Item azuriteSword;
        public static Item pyriteSword;
        public static Item platineSword;
    
        public static Item itemBeer;
    
        public static Item azuriteHammer;
        public static Item pyriteHammer;
        public static Item platineHammer;
    
        public static Item pieceOr;
        public static Item pieceArgent;
        public static Item pieceBronze;
    
        public static Item itemAzurite;
        public static Item itemPyrite;
        public static Item itemPlatine;
    
        public static Item itemAzuriteHelmet;
        public static Item itemAzuriteChestplate;
        public static Item itemAzuriteLeggings;
        public static Item itemAzuriteBoots;
    
        public static Item itemPyriteHelmet;
        public static Item itemPyriteChestplate;
        public static Item itemPyriteLeggings;
        public static Item itemPyriteBoots;
    
        public static Item itemPlatineHelmet;
        public static Item itemPlatineChestplate;
        public static Item itemPlatineLeggings;
        public static Item itemPlatineBoots;
    
        public static ArmorMaterial armorAzurite = EnumHelper.addArmorMaterial("armorAzurite", 35, new int[] {4, 6, 5, 4}, 10);
        public static ArmorMaterial armorPyrite = EnumHelper.addArmorMaterial("armorPyrite", 40, new int[] {4, 6, 5, 4}, 8);
        public static ArmorMaterial armorPlatine = EnumHelper.addArmorMaterial("armorPlatine", 45, new int[] {4, 6, 5, 4}, 6);
    
        static ToolMaterial swordAzuriteMaterial = EnumHelper.addToolMaterial("swordAzuriteMaterial", 3, 1300, 8.0F, 4.0F, 10);
        static ToolMaterial swordPyriteMaterial = EnumHelper.addToolMaterial("swordPyriteMaterial", 3, 1800, 8.0F, 5.0F, 8);
        static ToolMaterial swordPlatineMaterial = EnumHelper.addToolMaterial("swordPlatineMaterial", 3, 2500, 8.0F, 6.0F, 6);
        static ToolMaterial hammerAzuriteMaterial = EnumHelper.addToolMaterial("hammerAzuriteMaterial", 1300, 854, 8.0F, 5.0F, 10);
        static ToolMaterial hammerPyriteMaterial = EnumHelper.addToolMaterial("hammerPyriteMaterial", 1800, 854, 8.0F, 6.0F, 8);
        static ToolMaterial hammerPlatineMaterial = EnumHelper.addToolMaterial("hammerPlatineMaterial", 2500, 854, 8.0F, 7.0F, 6);
    
        public static Enchantment enchantSlowdown;
        public static Enchantment enchantConfusion;
        public static Enchantment enchantBlindness;
        public static Enchantment enchantHunger;
        public static Enchantment enchantWeakness;
        public static Enchantment enchantPoison;
        public static Enchantment enchantWither;
        public static Enchantment enchantNightVision;
    
        @EventHandler
        public void preInit(FMLPreInitializationEvent event)
        {
            blockOrgeCulture = new BlockOrgeCulture().setBlockName("block_orgeCulture").setCreativeTab(CreativeTabs.tabBlock).setBlockTextureName("kingdom:orgeculture");
    
            MinecraftForge.EVENT_BUS.register(new EnchantmentManager());
    
            enchantSlowdown = new EnchantmentSlowdown().setName("enchantSlowdown");
            enchantConfusion = new EnchantmentConfusion().setName("enchantConfusion");
            enchantBlindness = new EnchantmentBlindness().setName("enchantBlindness");
            enchantHunger = new EnchantmentHunger().setName("enchantHunger");
            enchantWeakness = new EnchantmentWeakness().setName("enchantWeakness");
            enchantPoison = new EnchantmentPoison().setName("enchantPoison");
            enchantWither = new EnchantmentWither().setName("enchantWither");
            enchantNightVision = new EnchantmentNightVision().setName("enchantNightVision");
    
            itemBeer = new ItemFood(4, 4, false).setUnlocalizedName("beer").setTextureName("kingdom:beer");
    
            itemAzurite = new ItemAzurite().setUnlocalizedName("azurite").setTextureName("kingdom:azurite").setCreativeTab(CreativeTabs.tabMaterials);
            itemPyrite = new ItemPyrite().setUnlocalizedName("pyrite").setTextureName("kingdom:pyrite").setCreativeTab(CreativeTabs.tabMaterials);
            itemPlatine = new ItemPlatine().setUnlocalizedName("platine").setTextureName("kingdom:platine").setCreativeTab(CreativeTabs.tabMaterials);
    
            orgeSeed = new ItemSeeds(Kingdom.blockOrgeCulture, Blocks.farmland).setUnlocalizedName("seed_orge").setTextureName("kingdom:seed_orge").setCreativeTab(CreativeTabs.tabMaterials);
            itemOrge = new Item().setUnlocalizedName("item_orge").setTextureName("kingdom:orge").setCreativeTab(CreativeTabs.tabMaterials);
    
            pieceOr = new PieceOr().setUnlocalizedName("piece_or").setTextureName("kingdom:or").setCreativeTab(CreativeTabs.tabMaterials);
            pieceArgent = new PieceArgent().setUnlocalizedName("piece_argent").setTextureName("kingdom:argent").setCreativeTab(CreativeTabs.tabMaterials);
            pieceBronze = new PieceBronze().setUnlocalizedName("piece_bronze").setTextureName("kingdom:bronze").setCreativeTab(CreativeTabs.tabMaterials);
    
            azuriteSword = new AzuriteSword(swordAzuriteMaterial).setUnlocalizedName("azurite_sword").setTextureName("kingdom:azurite_sword").setCreativeTab(CreativeTabs.tabCombat);
            pyriteSword = new PyriteSword(swordPyriteMaterial).setUnlocalizedName("pyrite_sword").setTextureName("kingdom:pyrite_sword").setCreativeTab(CreativeTabs.tabCombat);
            platineSword = new PlatineSword(swordPlatineMaterial).setUnlocalizedName("platine_sword").setTextureName("kingdom:platine_sword").setCreativeTab(CreativeTabs.tabCombat);
    
            azuriteHammer = new AzuriteHammer(hammerAzuriteMaterial).setUnlocalizedName("azurite_hammer").setCreativeTab(CreativeTabs.tabCombat);
            pyriteHammer = new PyriteHammer(hammerPyriteMaterial).setUnlocalizedName("pyrite_hammer").setCreativeTab(CreativeTabs.tabCombat);
            platineHammer = new PlatineHammer(hammerPlatineMaterial).setUnlocalizedName("platine_hammer").setCreativeTab(CreativeTabs.tabCombat);
    
            blockAzuriteOre = new BlockAzuriteOre(Material.rock).setBlockName("azuriteore").setHardness(3.0F).setResistance(5.0F).setBlockTextureName("kingdom:block_azuriteore").setCreativeTab(CreativeTabs.tabBlock);
            blockPyriteOre = new BlockPyriteOre(Material.rock).setBlockName("pyriteore").setHardness(3.0F).setResistance(5.0F).setBlockTextureName("kingdom:block_pyriteore").setCreativeTab(CreativeTabs.tabBlock);
            blockPyrite = new BlockPyrite(Material.rock).setBlockName("pyrite").setHardness(3.0F).setResistance(5.0F).setBlockTextureName("kingdom:block_pyrite").setCreativeTab(CreativeTabs.tabBlock);
            blockPlatine = new BlockPlatine(Material.rock).setBlockName("platine").setHardness(3.0F).setResistance(5.0F).setBlockTextureName("kingdom:block_platine").setCreativeTab(CreativeTabs.tabBlock);
            blockAzurite = new BlockAzurite(Material.rock).setBlockName("azurite").setHardness(3.0F).setResistance(5.0F).setBlockTextureName("kingdom:azurite").setCreativeTab(CreativeTabs.tabBlock);
    
            itemAzuriteHelmet = new ItemAzuriteArmor(armorAzurite, 0).setUnlocalizedName("helmetAzurite").setTextureName("kingdom:helmetAzurite").setCreativeTab(CreativeTabs.tabCombat);
            itemAzuriteChestplate = new ItemAzuriteArmor(armorAzurite, 1).setUnlocalizedName("chestPlateAzurite").setTextureName("kingdom:helmetAzurite").setCreativeTab(CreativeTabs.tabCombat);
            itemAzuriteLeggings = new ItemAzuriteArmor(armorAzurite, 2).setUnlocalizedName("leggingsAzurite").setTextureName("kingdom:helmetAzurite").setCreativeTab(CreativeTabs.tabCombat);
            itemAzuriteBoots = new ItemAzuriteArmor(armorAzurite, 3).setUnlocalizedName("bootsAzurite").setTextureName("kingdom:helmetAzurite").setCreativeTab(CreativeTabs.tabCombat);
    
            itemPyriteHelmet = new ItemPyriteArmor(armorPyrite, 0).setUnlocalizedName("helmetPyrite").setTextureName("kingdom:helmetPyrite").setCreativeTab(CreativeTabs.tabCombat);
            itemPyriteChestplate = new ItemPyriteArmor(armorPyrite, 1).setUnlocalizedName("chestPlatePyrite").setTextureName("kingdom:helmetPyrite").setCreativeTab(CreativeTabs.tabCombat);
            itemPyriteLeggings = new ItemPyriteArmor(armorPyrite, 2).setUnlocalizedName("leggingsPyrite").setTextureName("kingdom:helmetPyrite").setCreativeTab(CreativeTabs.tabCombat);
            itemPyriteBoots = new ItemPyriteArmor(armorPyrite, 3).setUnlocalizedName("bootsPyrite").setTextureName("kingdom:helmetPyrite").setCreativeTab(CreativeTabs.tabCombat);
    
            itemPlatineHelmet = new ItemPlatineArmor(armorPlatine, 0).setUnlocalizedName("helmetPlatine").setTextureName("kingdom:helmetPlatine").setCreativeTab(CreativeTabs.tabCombat);
            itemPlatineChestplate = new ItemPlatineArmor(armorPlatine, 1).setUnlocalizedName("chestPlatePlatine").setTextureName("kingdom:helmetPlatine").setCreativeTab(CreativeTabs.tabCombat);
            itemPlatineLeggings = new ItemPlatineArmor(armorPlatine, 2).setUnlocalizedName("leggingsPlatine").setTextureName("kingdom:helmetPlatine").setCreativeTab(CreativeTabs.tabCombat);
            itemPlatineBoots = new ItemPlatineArmor(armorPlatine, 3).setUnlocalizedName("bootsPlatine").setTextureName("kingdom:helmetPlatine").setCreativeTab(CreativeTabs.tabCombat);
    
            GameRegistry.registerItem(itemAzurite, "item_azurite");
            GameRegistry.registerItem(itemPyrite, "item_pyrite");
            GameRegistry.registerItem(itemPlatine, "item_platine");
    
            GameRegistry.registerBlock(blockAzuriteOre, "block_azuriteore");
            GameRegistry.registerBlock(blockPyriteOre, "block_pyriteore");
            GameRegistry.registerBlock(blockPyrite, "block_pyrite");
            GameRegistry.registerBlock(blockPlatine, "block_platine");
            GameRegistry.registerBlock(blockAzurite, "block_azurite");
    
            GameRegistry.registerItem(itemPlatineHelmet, "platine_helmet");
            GameRegistry.registerItem(itemPlatineChestplate, "platine_chestplate");
            GameRegistry.registerItem(itemPlatineLeggings, "platine_leggings");
            GameRegistry.registerItem(itemPlatineBoots, "platine_boots");
    
            GameRegistry.registerItem(itemPyriteHelmet, "pyrite_helmet");
            GameRegistry.registerItem(itemPyriteChestplate, "pyrite_chestplate");
            GameRegistry.registerItem(itemPyriteLeggings, "pyrite_leggings");
            GameRegistry.registerItem(itemPyriteBoots, "pyrite_boots");
    
            GameRegistry.registerItem(itemAzuriteHelmet, "azurite_helmet");
            GameRegistry.registerItem(itemAzuriteChestplate, "azurite_chestplate");
            GameRegistry.registerItem(itemAzuriteLeggings, "azurite_leggings");
            GameRegistry.registerItem(itemAzuriteBoots, "azurite_boots");
    
            GameRegistry.registerItem(azuriteSword, "azurite_sword");
            GameRegistry.registerItem(pyriteSword, "pyrite_sword");
            GameRegistry.registerItem(platineSword, "platine_sword");
    
            GameRegistry.registerItem(azuriteHammer, "azurite_hammer");
            GameRegistry.registerItem(pyriteHammer, "pyrite_hammer");
            GameRegistry.registerItem(platineHammer, "platine_hammer");
    
            GameRegistry.registerItem(orgeSeed, "orge_seed");
            GameRegistry.registerItem(itemOrge, "orge");
            GameRegistry.registerBlock(blockOrgeCulture, "block_orge");
    
            GameRegistry.registerItem(itemBeer, "item_beer");
    
        }
    
        @EventHandler
        public void init(FMLInitializationEvent event)
        {
            EntityRegistry.registerGlobalEntityID(EntityMino.class, "mobmino", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 0, 0).getRGB(), new Color(255, 0, 0).getRGB());
            EntityRegistry.registerModEntity(EntityMino.class, "mobmino", 424, this.instance, 40, 1, true);
            proxy.registerRender();
    
            EntityRegistry.registerGlobalEntityID(EntityForza.class, "mobforza", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 0, 0).getRGB(), new Color(255, 0, 0).getRGB());
            EntityRegistry.registerModEntity(EntityForza.class, "mobforza", 425, this.instance, 40, 1, true);
            proxy.registerRender();
    
            EntityRegistry.registerGlobalEntityID(EntityChest.class, "mobchest", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 0, 0).getRGB(), new Color(255, 0, 0).getRGB());
            EntityRegistry.registerModEntity(EntityChest.class, "mobchest", 426, this.instance, 40, 1, true);
            proxy.registerRender();
    
            EntityRegistry.registerGlobalEntityID(EntityDragon.class, "mobdragon", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 0, 0).getRGB(), new Color(255, 0, 0).getRGB());
            EntityRegistry.registerModEntity(EntityDragon.class, "mobdragon", 427, this.instance, 40, 1, true);
            proxy.registerRender();
    
            EntityRegistry.registerGlobalEntityID(EntityEnderBoss.class, "mobender", EntityRegistry.findGlobalUniqueEntityId(), new Color(0, 0, 0).getRGB(), new Color(255, 0, 0).getRGB());
            EntityRegistry.registerModEntity(EntityEnderBoss.class, "mobender", 428, this.instance, 40, 1, true);
            proxy.registerRender();
        }
    
        @EventHandler
        public void postInit(FMLPostInitializationEvent event)
        {
    
        }
    
        public static final String MODID = "kingdom";
    }
    

    et la class de ma nourriture

    
    package mod.kingdom.common;
    
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.EnumAction;
    import net.minecraft.item.ItemFood;
    import net.minecraft.item.ItemStack;
    import net.minecraft.potion.Potion;
    import net.minecraft.potion.PotionEffect;
    import net.minecraftforge.event.entity.living.LivingHurtEvent;
    import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
    
    public class ItemBeer extends ItemFood
    {
        public ItemBeer(int gigot, float saturation, boolean loup)
        {
            super(gigot, saturation, loup);
    
        }
    }
    


  • –> http://www.minecraftforgefrance.fr/showthread.php?tid=684#bonus (Tu mets la fonction .addPotionEffect aux setters de ton item (.setUnlocalizedName("patate").addPotionEffect(...);))

    Si tu veux ajouter plusieurs effets, il faut que tu mette la fonction "onEaten" dans la classe de ton item hérité de "ItemFood".



  • le problème c'est que ça ne fonctionne pas il y a une erreur 😞



  • Laquelle ?



  • re j'ai trouvé ! j'avais déjà essayer de metre le set… dans le constructeur de la class de la nourriture mais j'vais laissé ItemFood dans le preInit donc forcement ça marchait pas xD merci quand même



  • au faite, passe en résolut.