Ajout d'effets sur des armures



  • Bonjour ou bonsoir :D,
    Version : 1.7.2
    API utilisée(s) : Forge
    Recherche(s) effectuée(s) : Ironcraft, MinecraftForgeFrance, Google, Forum anglais (mais pas beaucoup sur la 1.7)
    Explication détaillée du problème : Après énormément d'essaie et des milliards de code faux testé, je n'arrive toujours pas a ajouté des effets à une armure en 1.7.
    Explication(s) complémentaire(s) liée(s) au problème: Aucune
    Code erreur : /
    Code(s) : ItemAluminiumArmor:

    package mod.epicrafting.items;
    
    import java.util.List;
    
    import cpw.mods.fml.common.FMLCommonHandler;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import mod.epicrafting.Epicrafting;
    import net.minecraft.client.renderer.texture.IIconRegister;
    import net.minecraft.enchantment.Enchantment;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    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;
    import net.minecraft.world.WorldServer;
    
    public class ItemAluminiumArmor extends ItemArmor{
    
    public ItemAluminiumArmor(int i, ArmorMaterial enumArmorMaterial, int j, int k) {
    super(enumArmorMaterial, j, k);
    }
    
    public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type){
    if(stack.getItem() == Epicrafting.aluminiumHelmet || stack.getItem() == Epicrafting.aluminiumChestplate || stack.getItem() == Epicrafting.aluminiumBoots){
    return "Epicrafting:textures/models/armor/aluminium_1.png";
    }
    if(stack.getItem() == Epicrafting.titaneLeggings){
    return "Epicrafting:textures/models/armor/aluminium_2.png";
    }
    else return null;
    
    };
    
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister reg){
    if(this == Epicrafting.aluminiumHelmet){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumHelmet");
    }
    if(this == Epicrafting.aluminiumChestplate){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumChestplate");
    }
    if(this == Epicrafting.aluminiumLeggings){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumLeggings");
    }
    if(this == Epicrafting.aluminiumBoots){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumBoots");
    }
    }
    
    public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean bool){
    if(this == Epicrafting.aluminiumHelmet){
    // Do Nothing //
    }
    if(this == Epicrafting.aluminiumChestplate){
    // Do Nothing //
    }
    if(this == Epicrafting.aluminiumLeggings){
    // Do Nothing //
    }
    if(this == Epicrafting.aluminiumBoots){
    // Do Nothing //
    }
    }
    public boolean getIsRepairable(ItemStack stack, ItemStack repairItem)
    {
    if(stack.getItem().equals(this) && repairItem.getItem() == Epicrafting.aluminium)
    return true;
    return false;
    }
    }
    

    Screens: /
    Merci 🙂


  • Administrateurs

    Tu cherches à ajouter quoi comme effet ?



  • Pour savoir si ton armure est équipée, tu peux le faire dans un TickHandler.

    Ensuite, juste un if() et voilà, tu fais ce que tu veux


  • Administrateurs

    ou alors dans la fonction onArmorTick
    ça évite d'avoir un tick handler.



  • En ayant ajouté cette fonction :

    public void onArmorTick(World world, EntityPlayer player, ItemStack itemstack)
    {
    int parX = (int)player.posX, parY = (int)player.posY, parZ = (int)player.posZ; //On récupère les coordonnées du joueur
    WorldServer classicWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(0); //Classique = 0, Nether = -1, End = 1
    ItemStack boots = player.getCurrentArmor(1);
    ItemStack legs = player.getCurrentArmor(2);
    ItemStack chest = player.getCurrentArmor(3);
    ItemStack helmet = player.getCurrentArmor(4);
    
    if(boots != null && legs != null && chest != null && helmet != null)
    {
    if(boots.getItem() == Epicrafting.aluminiumBoots && legs.getItem() == Epicrafting.aluminiumLeggings &&
    chest.getItem() == Epicrafting.aluminiumChestplate && helmet.getItem() ==Epicrafting.aluminiumHelmet)
    {
    player.motionX *= 1.4F;
    player.motionZ *= 1.4F;
    }
    }
    }
    

    Mon jeu plante :

    –-- Minecraft Crash Report ----
    // Why is it breaking :(
    
    Time: 1/03/14 13:09
    Description: Ticking player
    
    java.lang.ArrayIndexOutOfBoundsException: 4
    at net.minecraft.entity.player.InventoryPlayer.armorItemInSlot(InventoryPlayer.java:701)
    at net.minecraft.entity.player.EntityPlayer.getCurrentArmor(EntityPlayer.java:2104)
    at mod.epicrafting.items.ItemAluminiumArmor.onArmorTick(ItemAluminiumArmor.java:81)
    at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:365)
    at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:643)
    at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1856)
    at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:360)
    at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:363)
    at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:334)
    at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37)
    at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:218)
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:763)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:651)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:530)
    at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:788)
    
    A detailed walkthrough of the error, its code path and all known details is as follows:
    ---------------------------------------------------------------------------------------
    
    -- Head --
    Stacktrace:
    at net.minecraft.entity.player.InventoryPlayer.armorItemInSlot(InventoryPlayer.java:701)
    at net.minecraft.entity.player.EntityPlayer.getCurrentArmor(EntityPlayer.java:2104)
    at mod.epicrafting.items.ItemAluminiumArmor.onArmorTick(ItemAluminiumArmor.java:81)
    at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:365)
    at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:643)
    at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1856)
    at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:360)
    
    -- Player being ticked --
    Details:
    Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
    Entity ID: 372
    Entity Name: Player218
    Entity's Exact location: 249,95, 67,00, 266,34
    Entity's Block location: World: (249,67,266), Chunk: (at 9,4,10 in 15,16; contains blocks 240,0,256 to 255,255,271), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Entity's Momentum: 0,01, -0,08, 0,01
    Stacktrace:
    at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:363)
    at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:334)
    at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37)
    at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:218)
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:242)
    
    -- Ticking connection --
    Details:
    Connection: net.minecraft.network.NetworkManager@5bd14f97
    Stacktrace:
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:190)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:763)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:651)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:530)
    at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:788)
    
    -- System Details --
    Details:
    Minecraft Version: 1.7.2
    Operating System: Windows 8 (amd64) version 6.2
    Java Version: 1.7.0_51, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 915752568 bytes (873 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
    AABB Pool Size: 5686 (318416 bytes; 0 MB) allocated, 5358 (300048 bytes; 0 MB) used
    IntCache: cache: 0, tcache: 1, allocated: 13, tallocated: 94
    FML: MCP v9.01-pre FML v7.2.125.1033 Minecraft Forge 10.12.0.1033 4 mods loaded, 4 mods active
    mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    FML{7.2.125.1033} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.0.1033.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    Forge{10.12.0.1033} [Minecraft Forge] (forgeSrc-1.7.2-10.12.0.1033.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    Epicrafting{1.1} [EpiCrafting] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
    Profiler Position: N/A (disabled)
    Vec3 Pool Size: 1727 (96712 bytes; 0 MB) allocated, 1714 (95984 bytes; 0 MB) used
    Player Count: 1 / 8; [EntityPlayerMP['Player218'/372, l='New World', x=249,95, y=67,00, z=266,34]]
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'fml,forge'
    

  • Administrateurs

    WorldServer classicWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension?(0); //Classique = 0, Nether = -1, End = 1
    Inutile, tu as déjà le paramètre world dans la fonction onArmorTick.
    Pour les getCurrentArmor(int) c'est 0, 1, 2, et 3 et non 1, 2, 3 et 4.



  • Merci ça fonctionne :).
    Par contre sais tu pourquoi lorsque mon joueur saute avec l'armure équipée, sa vitesse en l'air devient énorme (au point de ne plus charger le monde).
    Mon code:

    package mod.epicrafting.items;
    
    import java.util.List;
    
    import cpw.mods.fml.common.FMLCommonHandler;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import mod.epicrafting.Epicrafting;
    import net.minecraft.client.renderer.texture.IIconRegister;
    import net.minecraft.enchantment.Enchantment;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    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;
    import net.minecraft.world.WorldServer;
    
    public class ItemAluminiumArmor extends ItemArmor{
    
    public ItemAluminiumArmor(int i, ArmorMaterial enumArmorMaterial, int j, int k) {
    super(enumArmorMaterial, j, k);
    }
    
    public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type){
    if(stack.getItem() == Epicrafting.aluminiumHelmet || stack.getItem() == Epicrafting.aluminiumChestplate || stack.getItem() == Epicrafting.aluminiumBoots){
    return "Epicrafting:textures/models/armor/aluminium_1.png";
    }
    if(stack.getItem() == Epicrafting.titaneLeggings){
    return "Epicrafting:textures/models/armor/aluminium_2.png";
    }
    else return null;
    
    };
    
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister reg){
    if(this == Epicrafting.aluminiumHelmet){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumHelmet");
    }
    if(this == Epicrafting.aluminiumChestplate){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumChestplate");
    }
    if(this == Epicrafting.aluminiumLeggings){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumLeggings");
    }
    if(this == Epicrafting.aluminiumBoots){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumBoots");
    }
    }
    
    public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean bool){
    if(this == Epicrafting.aluminiumHelmet){
    // Do Nothing //
    }
    if(this == Epicrafting.aluminiumChestplate){
    // Do Nothing //
    }
    if(this == Epicrafting.aluminiumLeggings){
    // Do Nothing //
    }
    if(this == Epicrafting.aluminiumBoots){
    // Do Nothing //
    }
    }
    public boolean getIsRepairable(ItemStack stack, ItemStack repairItem)
    {
    if(stack.getItem().equals(this) && repairItem.getItem() == Epicrafting.aluminium)
    return true;
    return false;
    }
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemstack)
    {
    int parX = (int)player.posX, parY = (int)player.posY, parZ = (int)player.posZ; //On récupère les coordonnées du joueur
    ItemStack boots = player.getCurrentArmor(0);
    ItemStack legs = player.getCurrentArmor(1);
    ItemStack chest = player.getCurrentArmor(2);
    ItemStack helmet = player.getCurrentArmor(3);
    
    if(boots != null && legs != null && chest != null && helmet != null)
    {
    if(boots.getItem() == Epicrafting.aluminiumBoots && legs.getItem() == Epicrafting.aluminiumLeggings &&
    chest.getItem() == Epicrafting.aluminiumChestplate && helmet.getItem() ==Epicrafting.aluminiumHelmet)
    {
    player.motionX *= 1.1F;
    player.motionZ *= 1.1F;
    }
    }
    }
    }
    

  • Administrateurs

    Non, aucune idée 😕
    Sinon utilise les balises java plutôt que code pour le code java.



  • En modifiant l'effet par un effet de potion speed donc: ```java
    player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 10, 10));

    J'ai réussi à retirer le bug.
    Pour ceux que ça interresse:
    ItemMonArmure:
    ```java
    package mod.epicrafting.items;
    
    import java.util.List;
    
    import cpw.mods.fml.common.FMLCommonHandler;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import mod.epicrafting.Epicrafting;
    import net.minecraft.client.renderer.texture.IIconRegister;
    import net.minecraft.enchantment.Enchantment;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    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;
    import net.minecraft.world.WorldServer;
    
    public class ItemAluminiumArmor extends ItemArmor{
    
    public ItemAluminiumArmor(int i, ArmorMaterial enumArmorMaterial, int j, int k) {
    super(enumArmorMaterial, j, k);
    }
    
    public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type){
    if(stack.getItem() == Epicrafting.aluminiumHelmet || stack.getItem() == Epicrafting.aluminiumChestplate || stack.getItem() == Epicrafting.aluminiumBoots){
    return "Epicrafting:textures/models/armor/aluminium_1.png";
    }
    if(stack.getItem() == Epicrafting.titaneLeggings){
    return "Epicrafting:textures/models/armor/aluminium_2.png";
    }
    else return null;
    
    };
    
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister reg){
    if(this == Epicrafting.aluminiumHelmet){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumHelmet");
    }
    if(this == Epicrafting.aluminiumChestplate){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumChestplate");
    }
    if(this == Epicrafting.aluminiumLeggings){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumLeggings");
    }
    if(this == Epicrafting.aluminiumBoots){
    this.itemIcon = reg.registerIcon("Epicrafting:aluminiumBoots");
    }
    }
    
    public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean bool){
    if(this == Epicrafting.aluminiumHelmet){
    // Do Nothing //
    }
    if(this == Epicrafting.aluminiumChestplate){
    // Do Nothing //
    }
    if(this == Epicrafting.aluminiumLeggings){
    // Do Nothing //
    }
    if(this == Epicrafting.aluminiumBoots){
    // Do Nothing //
    }
    }
    public boolean getIsRepairable(ItemStack stack, ItemStack repairItem)
    {
    if(stack.getItem().equals(this) && repairItem.getItem() == Epicrafting.aluminium)
    return true;
    return false;
    }
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemstack)
    {
    int parX = (int)player.posX, parY = (int)player.posY, parZ = (int)player.posZ;
    ItemStack boots = player.getCurrentArmor(0);
    ItemStack legs = player.getCurrentArmor(1);
    ItemStack chest = player.getCurrentArmor(2);
    ItemStack helmet = player.getCurrentArmor(3);
    
    if(boots != null && legs != null && chest != null && helmet != null)
    {
    if(boots.getItem() == Epicrafting.aluminiumBoots && legs.getItem() == Epicrafting.aluminiumLeggings &&
    chest.getItem() == Epicrafting.aluminiumChestplate && helmet.getItem() ==Epicrafting.aluminiumHelmet)
    {
    player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 10, 10));
    }
    }
    }
    }
    

    Merci Robin :). Résolu (Désolé je n'ai pas trouvé comment mettre des balises :/)


Log in to reply