Résolu Ignorer un item
-
Bonjours,
Je poste car j’ai un petit probleme je voudrai ignoré un item
package fr.darkvince.ultra; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class itemRepaire extends Item { public itemRepaire() { this.maxStackSize = 1; } public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean selected) { if(entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)entity; for(int i = 0; i < 4; i++) { ItemStack armor = player.getCurrentArmor(i); if(armor != null) { if(armor.getItemDamage() > 0 && stack.getItemDamage() < stack.getMaxDamage()) { stack.setItemDamage(stack.getItemDamage() + 1); armor.setItemDamage(armor.getItemDamage() - 1); } } } for(int i = 0; i < 9; i++) { ItemStack targetStack = player.inventory.getStackInSlot(i); Item target = Main.Cuprite_sword; { if(targetStack != null && targetStack.getItem().isRepairable() && target.isDamaged(targetStack)) { stack.setItemDamage(stack.getItemDamage() + 1); targetStack.setItemDamage(targetStack.getItemDamage() - 1); } } } } } }
En gros se que ej voudrai faire c’est que l’épée En Cuprite ne puisse pas etre reparable
-
Bonjour !
Dans le if de ton deuxième for, tu n’a qu’a ajouter à ta condition “&& targetStack.getItem() != target”
-
@‘LeBossMax2’:
Bonjour !
Dans le if de ton deuxième for, tu n’a qu’a ajouter à ta condition “&& targetStack.getItem() != target”
Merci de ta reponse
Mais c’est pas que je veut pas mais y a un probleme
for(int i = 0; i < 9 && targetStack.getItem() != target; i++ ) { Item target = Main.Cuprite_sword; ItemStack targetStack = player.inventory.getStackInSlot(i); { if(targetStack != null && targetStack.getItem().isRepairable()) { stack.setItemDamage(stack.getItemDamage() + 1); targetStack.setItemDamage(targetStack.getItemDamage() - 1); }
Si je mais comme sa targetStack.getItem() != target; y a une erreur sur targetStack et target se qui est normal
et si je mais comme se y a mon i en erreur normal aussi car il est en dessous
Item target = Main.Cuprite_sword; ItemStack targetStack = player.inventory.getStackInSlot(i); for(int i = 0; i < 9 && targetStack.getItem() != target; i++ ) { { if(targetStack != null && targetStack.getItem().isRepairable()) { stack.setItemDamage(stack.getItemDamage() + 1); targetStack.setItemDamage(targetStack.getItemDamage() - 1); }
-
Tu n’a pas compris ce que je voulais dire :
Il faut mettre “&& targetStack.getItem() != target” dans la condition du If, pas dans la condition du For. -
@‘LeBossMax2’:
Tu n’a pas compris ce que je voulais dire :
Il faut mettre “&& targetStack.getItem() != target” dans la condition du If, pas dans la condition du For.J’ai essayé sa marche pas
-
Beh tout simplement ça dans la classe de ton épée :
@Override public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { return false; }
-
@‘Plaigon’:
Beh tout simplement ça dans la classe de ton épée :
@Override public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { return false; }
Non justement sa marche pas
Edit:
Tu n’a pas compris ce que je voulais dire :Il faut mettre “&& targetStack.getItem() != target” dans la condition du If, pas dans la condition du For.
C’est pas que sa marche pas enfaîte c’est que l’item qui repaire les item s’utilise toute seul apres
-
Pas compris …
Explique clairement ce que tu souhaites faire, car là je ne vois pas pourquoi mon code ne te satisfait pas -
@‘Plaigon’:
Pas compris …
Explique clairement ce que tu souhaites faire, car là je ne vois pas pourquoi mon code ne te satisfait pasCar ton code fait que sa repaire quand meme l’item en faite l’item que j’ai actuellement permet de reparer des item et armures quand il sont dans ton inventaire le probleme je veut ignorer 1 seul item mais avec ton code bah sa repaire quand meme l’item car la c’est pas une itemSword c’est une épee refaite en Item
Moi j’avais penser a faire sa
if(si c’est equal a épée Cuprite)
Sa fait rien
else(Si c’est pas une cuprite)
J’execute ma fonctionMais j’y arrive pas
-
Est-ce que ça va comme ceci ?
@Override public void onUpdate(ItemStack stack, World world, Entity entity, int slotIndex, boolean isInHand) { super.onUpdate(stack, world, entity, slotIndex, isInHand); EntityPlayer player = (EntityPlayer)entity; for(int i = 0; i <= player.inventory.getSizeInventory(); i++) { ItemStack currentInventoryStack = player.inventory.getStackInSlot(i); if(currentInventoryStack != null) { if(!currentInventoryStack.equals(Items.coal) && currentInventoryStack.getClass().equals(ItemSword.class))//remplace coal par ton item { if(!world.isRemote) { stack.damageItem(1, (EntityLivingBase)entity); currentInventoryStack.setItemDamage(currentInventoryStack.getItemDamage() - 1 <= 0 ? currentInventoryStack.getItemDamage() - 1 : 0); } } } } for(int i = 0; i < player.inventory.armorInventory.length; i++) { ItemStack currentArmorStack = player.inventory.armorItemInSlot(i); if(currentArmorStack != null) { if(!world.isRemote) { stack.damageItem(1, (EntityLivingBase)entity); currentArmorStack.setItemDamage(currentArmorStack.getItemDamage() - 1 <= 0 ? currentArmorStack.getItemDamage() - 1 : 0); } } } }
-
@‘Plaigon’:
Est-ce que ça va comme ceci ?
@Override public void onUpdate(ItemStack stack, World world, Entity entity, int slotIndex, boolean isInHand) { super.onUpdate(stack, world, entity, slotIndex, isInHand); EntityPlayer player = (EntityPlayer)entity; for(int i = 0; i <= player.inventory.getSizeInventory(); i++) { ItemStack currentInventoryStack = player.inventory.getStackInSlot(i); if(currentInventoryStack != null) { if(!currentInventoryStack.equals(Items.coal) && currentInventoryStack.getClass().equals(ItemSword.class))//remplace coal par ton item { if(!world.isRemote) { stack.damageItem(1, (EntityLivingBase)entity); currentInventoryStack.setItemDamage(currentInventoryStack.getItemDamage() - 1 <= 0 ? currentInventoryStack.getItemDamage() - 1 : 0); } } } } for(int i = 0; i < player.inventory.armorInventory.length; i++) { ItemStack currentArmorStack = player.inventory.armorItemInSlot(i); if(currentArmorStack != null) { if(!world.isRemote) { stack.damageItem(1, (EntityLivingBase)entity); currentArmorStack.setItemDamage(currentArmorStack.getItemDamage() - 1 <= 0 ? currentArmorStack.getItemDamage() - 1 : 0); } } } }
Crash direct
C’est un ItemSword.class c’ets un Item tous court tien la class de l’item sa peut peut etre t’aiderpackage fr.darkvince.ultra; import java.util.List; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.Item.ToolMaterial; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; public class Cuprite_sword extends Item { public Cuprite_sword() { super(); setMaxStackSize(1); setMaxDamage(90); } public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) { par1ItemStack.damageItem(1, par3EntityLivingBase); if (getDamage(par1ItemStack) == 30) { par1ItemStack.addEnchantment(Enchantment.sharpness, 10); } if (getDamage(par1ItemStack) == 45) { par1ItemStack.addEnchantment(Enchantment.sharpness, 11); } if (getDamage(par1ItemStack) == 60) { par1ItemStack.addEnchantment(Enchantment.sharpness, 12); } if (getDamage(par1ItemStack) == 75) { par1ItemStack.addEnchantment(Enchantment.sharpness, 13); } if (getDamage(par1ItemStack) == 85) { par1ItemStack.addEnchantment(Enchantment.sharpness, 25); } return true; } @SideOnly(Side.CLIENT) public boolean isFull3D() { return true; } public EnumAction getItemUseAction(ItemStack p_77661_1_) { return EnumAction.block; } @Override public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { return false; } public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) { p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_)); return p_77659_1_; } @SideOnly(Side.CLIENT) public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { par3List.add(EnumChatFormatting.WHITE + "Epee de dieux LVL 1"); } }
at fr.darkvince.ultra.itemRepaire.onUpdate(itemRepaire.java:25)
La ligne 25 : ItemStack currentInventoryStack = player.inventory.getStackInSlot(i);
-
Crash report ?
-
Remplace :
if(!currentInventoryStack.equals(Items.coal) && currentInventoryStack.getClass().equals(ItemSword.class))
Par :
if(!currentInventoryStack.equals(Items.coal) && currentInventoryStack.getItem ().getClass().equals(ItemSword.class))EDIT = Crash report stp
-
Crash report aussi stp
-
@‘Plaigon’:
Crash report aussi stp
Aucun crash report est les log non plus
Edit:
J’était dans le mauvais dossier de mods
–-- Minecraft Crash Report ---- // Oh - I know what I did wrong! Time: 23/04/16 15:02 Description: Ticking player java.lang.ArrayIndexOutOfBoundsException: 4 at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:646) at fr.darkvince.ultra.itemRepaire.onUpdate(itemRepaire.java:25) at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:476) at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:347) at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:610) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327) at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:271) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:646) at fr.darkvince.ultra.itemRepaire.onUpdate(itemRepaire.java:25) at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:476) at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:347) at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:610) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327) -- Player being ticked -- Details: Entity Type: null (net.minecraft.entity.player.EntityPlayerMP) Entity ID: 534 Entity Name: Player88 Entity's Exact location: -172,50, 63,00, 257,50 Entity's Block location: World: (-173,63,257), Chunk: (at 3,3,1 in -11,16; contains blocks -176,0,256 to -161,255,271), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511) Entity's Momentum: 0,00, -0,08, 0,00 Stacktrace: at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:271) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@70604eee Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_74, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 936570232 bytes (893 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94 FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1558 4 mods loaded, 4 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) UCHIJAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar) UCHIJAAAA Forge{10.13.4.1558} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar) UCHIJAAAA ultra{1.0} [ultra] (bin) GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Player88'/534, l='New World', x=-172,50, y=63,00, z=257,50]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
-
Envoi la classe entière de l’Item sinon on peut pas savoir où c’est précisément
-
C’est telement difficile de faire un
if(itemstack != null && itemstack.getItem() != ClassPrincipale.itemAExclure)
???