Résolu Objet qui s'use
-
Salut ! Je suis de retour ! Avec de nouveaux problèmes malheureusement.
Je voudrais que lorsque mon fusil tire ( cc @jglrxavpok ), ma boîte de munitions s’use au lieu de la consommer.
Sans plus tarder, voila mes classes.package assets.ei.Weapons; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import assets.NolanCore.Data.EntityShoot; import assets.ei.Data.EastonIsland; import assets.ei.Data.EntityBullet; import assets.ei.Data.ItemWeapon; import assets.mgs.common.Main; public class W_Tokarev extends ItemWeapon { private int timer = 0; public W_Tokarev(int par1) { super(par1); this.maxStackSize = 1; // dit qu'il ne peut avoir que 1 pistolet this.setCreativeTab(EastonIsland.Ei3); } public boolean onEntitySwing(EntityLivingBase e, ItemStack s) { if (s.getItemDamage() == 0) if (e instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) e; boolean flag = false; if (player.capabilities.isCreativeMode) { flag = true; } else { flag = player.inventory .consumeInventoryItem(EastonIsland.I9mm.itemID); } if (flag) { EntityBullet bullet = new EntityBullet(e.worldObj, e, false, "Tok", 5, 64); if (!e.worldObj.isRemote) e.worldObj.spawnEntityInWorld(bullet); e.worldObj.playSoundAtEntity(e, "ei:pistol_fire", 0.5f, 1); onUsed(s, e); } else e.worldObj.playSoundAtEntity(e, "ei:ClipEmpty_Pistol", 0.5f, 1); } return true; } public boolean onBlockStartBreak(ItemStack s, int x, int y, int z, EntityPlayer player) { return true; } public boolean hitEntity(ItemStack s, EntityLivingBase e, EntityLivingBase source) { if (s.getItemDamage() == 0) if (source instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) source; boolean flag = false; if (player.capabilities.isCreativeMode) { flag = true; } else { flag = player.inventory .consumeInventoryItem(EastonIsland.I9mm.itemID); } if (flag) { if (!e.worldObj.isRemote) new EntityBullet(source.worldObj, source, false, "Tok", 5, 64).onImpact(new MovingObjectPosition(e)); // source.worldObj.playSoundAtEntity(source, // "hl2:magnum_fire", 1, 1); onUsed(s, source); } else source.worldObj.playSoundAtEntity(source, "ei:ClipEmpty_Pistol", 1, 1); } return false; } private void onUsed(ItemStack s, EntityLivingBase e) { s.setItemDamage(15); } public void onUpdate(ItemStack s, World w, Entity p, int i, boolean flag) { super.onUpdate(s, w, p, i, flag); if (s.getItemDamage() > 0) { s.setItemDamage(s.getItemDamage() - 1); } } @Override public void registerIcons(IconRegister iconRegister) { itemIcon = iconRegister.registerIcon("ei:Pistolet Tokarev TT 33"); } }
package assets.ei.ammo; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.item.Item; import assets.ei.Data.EastonIsland; import assets.mgs.common.D_Tabs; public class I_9mm extends Item { public I_9mm(int par1) { super(par1); this.maxStackSize = 15; this.setCreativeTab(EastonIsland.Ei3); } @Override public void registerIcons(IconRegister iconRegister) { itemIcon = iconRegister.registerIcon("ei:9mm"); } }
Merci d’avance pour vos réponses.
-
Il faudrait faire une fonction qui vérifie que le joueur possède l’item sur lui et obtenir son emplacement dans le tableau de l’inventaire :
private int getItemIntoInventory(EntityPlayer player, int itemId) { for(int i = 0; i < player.inventory.mainInventory.lenth; i ++) { if(player.inventory.mainInventory* != null && player.inventory.mainInventory*.itemID == itemId) { return i; } //return -1; EDIT, il va pas ici mais en dessous : } return -1; }
Tu aura juste a utiliser :
if(getItemIntoInventory(player, EastonIsland.I9mm.itemID) > -1) // vérifie que le joueur à l'item sur lui { player.inventory.mainInventory[getItemIntoInventory(player, EastonIsland.I9mm.itemID)].damageItem(player, 1); // fait des dégâts à l'item }
pour endommager l’item.
-
et comment je définit le nombre de munitions dans ma boite ? (= la résistance de l’objet)
-
@‘robin4002’:
for(int i = 0; i < player.inventory.mainInventory.lenth; i ++) { if(player.inventory.mainInventory* != null && player.inventory.mainInventory*.itemID == itemId) { return i; } return -1; } }
Si tu permets, dans une liste il est préférable d’utiliser le système d’itérateurs :
for(ItemStack i : player.inventory.mainInventory){ if(i.itemID == itemId){ return i; } return -1; }
@‘Nolan-XX’:
et comment je définit le nombre de munitions dans ma boite ? (= la résistance de l’objet)
Dans l’initialisation de ton item :
setMaxDamage(int damage)
-
2014-01-12 16:04:19 [Infos] [ForgeModLoader] Unloading dimension 0 2014-01-12 16:04:19 [Infos] [ForgeModLoader] Unloading dimension -1 2014-01-12 16:04:19 [Infos] [ForgeModLoader] Unloading dimension 1 2014-01-12 16:04:19 [Infos] [STDERR] java.lang.ArrayIndexOutOfBoundsException: -1 2014-01-12 16:04:19 [Infos] [STDERR] at assets.ei.Weapons.W_Tokarev.onEntitySwing(W_Tokarev.java:77) 2014-01-12 16:04:19 [Infos] [STDERR] at net.minecraft.entity.EntityLivingBase.swingItem(EntityLivingBase.java:1328) 2014-01-12 16:04:19 [Infos] [STDERR] at net.minecraft.client.entity.EntityClientPlayerMP.swingItem(EntityClientPlayerMP.java:206) 2014-01-12 16:04:19 [Infos] [STDERR] at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1344) 2014-01-12 16:04:19 [Infos] [STDERR] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1863) 2014-01-12 16:04:19 [Infos] [STDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:910) 2014-01-12 16:04:19 [Infos] [STDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:838) 2014-01-12 16:04:19 [Infos] [STDERR] at net.minecraft.client.main.Main.main(Main.java:93) 2014-01-12 16:04:19 [Infos] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2014-01-12 16:04:19 [Infos] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2014-01-12 16:04:19 [Infos] [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2014-01-12 16:04:19 [Infos] [STDERR] at java.lang.reflect.Method.invoke(Unknown Source) 2014-01-12 16:04:19 [Infos] [STDERR] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) 2014-01-12 16:04:19 [Infos] [STDERR] at net.minecraft.launchwrapper.Launch.main(Launch.java:27) 2014-01-12 16:04:19 [Infos] [STDOUT] –-- Minecraft Crash Report ---- 2014-01-12 16:04:19 [Infos] [STDOUT] // This doesn't make any sense! 2014-01-12 16:04:19 [Infos] [STDOUT] 2014-01-12 16:04:19 [Infos] [STDOUT] Time: 12/01/14 16:04 2014-01-12 16:04:19 [Infos] [STDOUT] Description: Unexpected error 2014-01-12 16:04:19 [Infos] [STDOUT] 2014-01-12 16:04:19 [Infos] [STDOUT] java.lang.ArrayIndexOutOfBoundsException: -1 2014-01-12 16:04:19 [Infos] [STDOUT] at assets.ei.Weapons.W_Tokarev.onEntitySwing(W_Tokarev.java:77) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.entity.EntityLivingBase.swingItem(EntityLivingBase.java:1328) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.entity.EntityClientPlayerMP.swingItem(EntityClientPlayerMP.java:206) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1344) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1863) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:910) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.Minecraft.run(Minecraft.java:838) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.main.Main.main(Main.java:93) 2014-01-12 16:04:19 [Infos] [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2014-01-12 16:04:19 [Infos] [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2014-01-12 16:04:19 [Infos] [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2014-01-12 16:04:19 [Infos] [STDOUT] at java.lang.reflect.Method.invoke(Unknown Source) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.launchwrapper.Launch.main(Launch.java:27) 2014-01-12 16:04:19 [Infos] [STDOUT] 2014-01-12 16:04:19 [Infos] [STDOUT] 2014-01-12 16:04:19 [Infos] [STDOUT] A detailed walkthrough of the error, its code path and all known details is as follows: 2014-01-12 16:04:19 [Infos] [STDOUT] –------------------------------------------------------------------------------------- 2014-01-12 16:04:19 [Infos] [STDOUT] 2014-01-12 16:04:19 [Infos] [STDOUT] – Head -- 2014-01-12 16:04:19 [Infos] [STDOUT] Stacktrace: 2014-01-12 16:04:19 [Infos] [STDOUT] at assets.ei.Weapons.W_Tokarev.onEntitySwing(W_Tokarev.java:77) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.entity.EntityLivingBase.swingItem(EntityLivingBase.java:1328) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.entity.EntityClientPlayerMP.swingItem(EntityClientPlayerMP.java:206) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1344) 2014-01-12 16:04:19 [Infos] [STDOUT] 2014-01-12 16:04:19 [Infos] [STDOUT] – Affected level -- 2014-01-12 16:04:19 [Infos] [STDOUT] Details: 2014-01-12 16:04:19 [Infos] [STDOUT] Level name: MpServer 2014-01-12 16:04:19 [Infos] [STDOUT] All players: 1 total; [EntityClientPlayerMP['Player671'/63, l='MpServer', x=-691,16, y=64,62, z=-231,60]] 2014-01-12 16:04:19 [Infos] [STDOUT] Chunk stats: MultiplayerChunkCache: 441 2014-01-12 16:04:19 [Infos] [STDOUT] Level seed: 0 2014-01-12 16:04:19 [Infos] [STDOUT] Level generator: ID 00 - default, ver 1\. Features enabled: false 2014-01-12 16:04:19 [Infos] [STDOUT] Level generator options: 2014-01-12 16:04:19 [Infos] [STDOUT] Level spawn location: World: (-390,64,-286), Chunk: (at 10,4,2 in -25,-18; contains blocks -400,0,-288 to -385,255,-273), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1) 2014-01-12 16:04:19 [Infos] [STDOUT] Level time: 130270 game time, 206 day time 2014-01-12 16:04:19 [Infos] [STDOUT] Level dimension: 0 2014-01-12 16:04:19 [Infos] [STDOUT] Level storage version: 0x00000 - Unknown? 2014-01-12 16:04:19 [Infos] [STDOUT] Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) 2014-01-12 16:04:19 [Infos] [STDOUT] Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false 2014-01-12 16:04:19 [Infos] [STDOUT] Forced entities: 90 total; [EntityZombie['Zombie'/139, l='MpServer', x=-719,50, y=17,00, z=-293,50], EntitySkeleton['Squelette'/141, l='MpServer', x=-714,50, y=13,00, z=-284,50], EntityZombie['Zombie'/140, l='MpServer', x=-719,50, y=17,00, z=-294,50], EntitySpider['Araignée'/143, l='MpServer', x=-709,34, y=32,00, z=-281,44], EntityZombie['Zombie'/142, l='MpServer', x=-704,45, y=16,81, z=-273,27], EntityZombie['Zombie'/129, l='MpServer', x=-723,69, y=20,00, z=-234,59], EntityZombie['Zombie'/128, l='MpServer', x=-729,16, y=14,00, z=-285,56], EntitySquid['Calmar'/131, l='MpServer', x=-733,90, y=41,00, z=-239,47], EntityZombie['Zombie'/130, l='MpServer', x=-721,31, y=20,00, z=-236,50], EntityBat['Chauve-souris'/132, l='MpServer', x=-735,22, y=36,87, z=-152,42], EntitySquid['Calmar'/152, l='MpServer', x=-678,17, y=55,00, z=-204,41], EntityCreeper['Creeper'/153, l='MpServer', x=-702,50, y=12,00, z=-186,50], EntitySkeleton['Squelette'/155, l='MpServer', x=-676,50, y=35,00, z=-177,50], EntityZombie['Zombie'/156, l='MpServer', x=-673,50, y=19,00, z=-165,50], EntityPig['Cochon'/159, l='MpServer', x=-667,31, y=57,00, z=-262,53], EntitySpider['Araignée'/144, l='MpServer', x=-709,00, y=32,00, z=-279,53], EntityCreeper['Creeper'/145, l='MpServer', x=-712,50, y=17,00, z=-181,50], EntitySquid['Calmar'/146, l='MpServer', x=-714,06, y=56,34, z=-182,44], EntitySkeleton['Squelette'/147, l='MpServer', x=-719,50, y=24,00, z=-172,50], EntityMinecartChest['entity.MinecartChest.name'/150, l='MpServer', x=-692,50, y=41,50, z=-278,50], EntityZombie['Zombie'/151, l='MpServer', x=-694,50, y=41,00, z=-274,50], EntityPig['Cochon'/171, l='MpServer', x=-632,53, y=64,00, z=-249,69], EntitySkeleton['Squelette'/517, l='MpServer', x=-725,47, y=32,00, z=-271,84], EntityBat['Chauve-souris'/170, l='MpServer', x=-649,51, y=18,30, z=-263,50], EntitySkeleton['Squelette'/518, l='MpServer', x=-717,50, y=32,00, z=-276,50], EntityCreeper['Creeper'/169, l='MpServer', x=-645,50, y=23,00, z=-278,50], EntityPig['Cochon'/175, l='MpServer', x=-649,50, y=64,00, z=-231,75], EntitySheep['Mouton'/174, l='MpServer', x=-646,50, y=63,00, z=-228,50], EntitySheep['Mouton'/173, l='MpServer', x=-647,50, y=63,00, z=-236,50], EntityPig['Cochon'/172, l='MpServer', x=-652,50, y=63,00, z=-238,50], EntityBat['Chauve-souris'/163, l='MpServer', x=-657,06, y=43,10, z=-173,31], EntityZombie['Zombie'/162, l='MpServer', x=-669,50, y=21,00, z=-180,50], EntitySquid['Calmar'/161, l='MpServer', x=-666,03, y=55,94, z=-201,28], EntityCreeper['Creeper'/160, l='MpServer', x=-666,69, y=13,00, z=-206,97], EntityBat['Chauve-souris'/164, l='MpServer', x=-665,24, y=19,00, z=-154,18], EntityWolf['Loup'/186, l='MpServer', x=-628,53, y=64,00, z=-226,06], EntityBat['Chauve-souris'/187, l='MpServer', x=-630,50, y=31,00, z=-221,65], EntityChicken['Poulet'/184, l='MpServer', x=-634,53, y=64,00, z=-241,47], EntityZombie['Zombie'/185, l='MpServer', x=-633,69, y=31,00, z=-238,66], EntitySkeleton['Squelette'/190, l='MpServer', x=-630,16, y=36,00, z=-186,44], EntityBat['Chauve-souris'/191, l='MpServer', x=-630,25, y=46,10, z=-184,25], EntityPig['Cochon'/188, l='MpServer', x=-624,50, y=64,00, z=-219,50], EntityZombie['Zombie'/189, l='MpServer', x=-633,53, y=16,00, z=-205,09], EntityZombie['Zombie'/178, l='MpServer', x=-644,50, y=21,00, z=-168,50], EntityCreeper['Creeper'/176, l='MpServer', x=-651,50, y=46,00, z=-218,50], EntityZombie['Zombie'/177, l='MpServer', x=-652,00, y=23,00, z=-195,56], EntityItem['item.item.porkchopRaw'/183, l='MpServer', x=-630,06, y=65,13, z=-256,81], EntitySkeleton['Squelette'/1157, l='MpServer', x=-731,50, y=26,00, z=-297,50], EntitySkeleton['Squelette'/76, l='MpServer', x=-771,50, y=33,00, z=-253,50], EntityPig['Cochon'/197, l='MpServer', x=-622,03, y=64,00, z=-223,19], EntityPig['Cochon'/196, l='MpServer', x=-611,53, y=58,00, z=-224,87], EntityBat['Chauve-souris'/77, l='MpServer', x=-766,98, y=17,06, z=-199,51], EntityBat['Chauve-souris'/78, l='MpServer', x=-768,48, y=17,00, z=-196,94], EntityChicken['Poulet'/198, l='MpServer', x=-619,50, y=64,00, z=-219,50], EntityClientPlayerMP['Player671'/63, l='MpServer', x=-691,16, y=64,62, z=-231,60], EntityChicken['Poulet'/195, l='MpServer', x=-617,53, y=62,00, z=-221,47], EntityCreeper['Creeper'/85, l='MpServer', x=-763,50, y=27,00, z=-275,50], EntityZombie['Zombie'/84, l='MpServer', x=-758,69, y=17,00, z=-266,50], EntityCreeper['Creeper'/87, l='MpServer', x=-755,70, y=36,04, z=-161,70], EntityZombie['Zombie'/86, l='MpServer', x=-760,50, y=16,00, z=-262,50], EntityBat['Chauve-souris'/83, l='MpServer', x=-752,46, y=33,00, z=-283,32], EntityBat['Chauve-souris'/82, l='MpServer', x=-758,52, y=34,62, z=-288,28], EntityBat['Chauve-souris'/89, l='MpServer', x=-759,66, y=33,10, z=-155,25], EntitySquid['Calmar'/88, l='MpServer', x=-752,97, y=52,34, z=-169,94], EntitySkeleton['Squelette'/102, l='MpServer', x=-737,63, y=28,00, z=-303,72], EntitySkeleton['Squelette'/103, l='MpServer', x=-741,53, y=27,00, z=-309,41], EntityCreeper['Creeper'/100, l='MpServer', x=-749,50, y=18,00, z=-309,50], EntityEnderman['Enderman'/510, l='MpServer', x=-768,99, y=14,14, z=-258,13], EntitySkeleton['Squelette'/101, l='MpServer', x=-735,44, y=27,00, z=-309,16], EntityEnderman['Enderman'/511, l='MpServer', x=-770,25, y=18,00, z=-261,69], EntityZombie['Zombie'/99, l='MpServer', x=-749,91, y=29,00, z=-306,50], EntityZombie['Zombie'/110, l='MpServer', x=-744,50, y=31,00, z=-277,50], EntityCreeper['Creeper'/111, l='MpServer', x=-746,50, y=30,00, z=-261,50], EntityZombie['Zombie'/108, l='MpServer', x=-749,50, y=14,00, z=-277,50], EntityBat['Chauve-souris'/109, l='MpServer', x=-738,47, y=24,10, z=-286,25], EntityMinecartChest['entity.MinecartChest.name'/107, l='MpServer', x=-736,50, y=42,50, z=-297,50], EntityZombie['Zombie'/104, l='MpServer', x=-740,47, y=27,00, z=-308,00], EntityZombie['Zombie'/105, l='MpServer', x=-739,50, y=42,00, z=-308,50], EntitySkeleton['Squelette'/119, l='MpServer', x=-739,50, y=22,00, z=-156,50], EntitySkeleton['Squelette'/118, l='MpServer', x=-741,50, y=22,00, z=-152,50], EntityZombie['Zombie'/117, l='MpServer', x=-738,53, y=19,00, z=-156,09], EntitySquid['Calmar'/116, l='MpServer', x=-750,78, y=54,97, z=-256,75], EntityBat['Chauve-souris'/115, l='MpServer', x=-728,35, y=38,46, z=-249,51], EntityZombie['Zombie'/114, l='MpServer', x=-743,84, y=36,00, z=-254,25], EntityZombie['Zombie'/113, l='MpServer', x=-746,50, y=30,00, z=-259,50], EntityZombie['Zombie'/112, l='MpServer', x=-744,50, y=30,00, z=-266,50], EntitySkeleton['Squelette'/127, l='MpServer', x=-730,13, y=33,00, z=-294,75], EntityCreeper['Creeper'/126, l='MpServer', x=-724,50, y=36,00, z=-301,50], EntityCreeper['Creeper'/124, l='MpServer', x=-732,72, y=28,00, z=-305,38], EntitySkeleton['Squelette'/120, l='MpServer', x=-742,50, y=22,00, z=-152,50]] 2014-01-12 16:04:19 [Infos] [STDOUT] Retry entities: 0 total; [] 2014-01-12 16:04:19 [Infos] [STDOUT] Server brand: fml,forge 2014-01-12 16:04:19 [Infos] [STDOUT] Server type: Integrated singleplayer server 2014-01-12 16:04:19 [Infos] [STDOUT] Stacktrace: 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:440) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2312) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.Minecraft.run(Minecraft.java:863) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.client.main.Main.main(Main.java:93) 2014-01-12 16:04:19 [Infos] [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2014-01-12 16:04:19 [Infos] [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2014-01-12 16:04:19 [Infos] [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2014-01-12 16:04:19 [Infos] [STDOUT] at java.lang.reflect.Method.invoke(Unknown Source) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) 2014-01-12 16:04:19 [Infos] [STDOUT] at net.minecraft.launchwrapper.Launch.main(Launch.java:27) 2014-01-12 16:04:19 [Infos] [STDOUT] 2014-01-12 16:04:19 [Infos] [STDOUT] – System Details -- 2014-01-12 16:04:19 [Infos] [STDOUT] Details: 2014-01-12 16:04:19 [Infos] [STDOUT] Minecraft Version: 1.6.4 2014-01-12 16:04:19 [Infos] [STDOUT] Operating System: Windows 8 (amd64) version 6.2 2014-01-12 16:04:19 [Infos] [STDOUT] Java Version: 1.7.0_45, Oracle Corporation 2014-01-12 16:04:19 [Infos] [STDOUT] Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation 2014-01-12 16:04:19 [Infos] [STDOUT] Memory: 747186336 bytes (712 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) 2014-01-12 16:04:19 [Infos] [STDOUT] JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M 2014-01-12 16:04:19 [Infos] [STDOUT] AABB Pool Size: 10931 (612136 bytes; 0 MB) allocated, 2 (112 bytes; 0 MB) used 2014-01-12 16:04:19 [Infos] [STDOUT] Suspicious classes: FML and Forge are installed 2014-01-12 16:04:19 [Infos] [STDOUT] IntCache: cache: 0, tcache: 0, allocated: 1, tallocated: 63 2014-01-12 16:04:19 [Infos] [STDOUT] FML: MCP v8.11 FML v6.4.49.965 Minecraft Forge 9.11.1.965 6 mods loaded, 6 mods active 2014-01-12 16:04:19 [Infos] [STDOUT] mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-01-12 16:04:19 [Infos] [STDOUT] FML{6.4.49.965} [Forge Mod Loader] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-01-12 16:04:19 [Infos] [STDOUT] Forge{9.11.1.965} [Minecraft Forge] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-01-12 16:04:19 [Infos] [STDOUT] ei{1.5.2} [Easton Island] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-01-12 16:04:19 [Infos] [STDOUT] MGS{1.1.0} [Metal gear cubid] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-01-12 16:04:19 [Infos] [STDOUT] NolanCore{1.5.2} [Nolan's Core] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-01-12 16:04:19 [Infos] [STDOUT] Launched Version: 1.6 2014-01-12 16:04:19 [Infos] [STDOUT] LWJGL: 2.9.0 2014-01-12 16:04:19 [Infos] [STDOUT] OpenGL: GeForce GTX 760 (192-bit)/PCIe/SSE2 GL version 4.3.0, NVIDIA Corporation 2014-01-12 16:04:19 [Infos] [STDOUT] Is Modded: Definitely; Client brand changed to 'fml,forge' 2014-01-12 16:04:19 [Infos] [STDOUT] Type: Client (map_client.txt) 2014-01-12 16:04:19 [Infos] [STDOUT] Resource Pack: Default 2014-01-12 16:04:19 [Infos] [STDOUT] Current Language: Français (CA) 2014-01-12 16:04:19 [Infos] [STDOUT] Profiler Position: N/A (disabled) 2014-01-12 16:04:19 [Infos] [STDOUT] Vec3 Pool Size: 2192 (122752 bytes; 0 MB) allocated, 13 (728 bytes; 0 MB) used 2014-01-12 16:04:19 [Infos] [STDOUT] #@!@# Game crashed! Crash report saved to: #@!@# D:\Forge 1.6\mcp\jars\.\crash-reports\crash-2014-01-12_16.04.19-client.txt AL lib: (EE) alc_cleanup: 1 device not closed
Le code du fusil :
package assets.ei.Weapons; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import assets.NolanCore.Data.EntityShoot; import assets.ei.Data.EastonIsland; import assets.ei.Data.EntityBullet; import assets.ei.Data.ItemWeapon; import assets.mgs.common.Main; public class W_Tokarev extends ItemWeapon { private int timer = 0; public W_Tokarev(int par1) { super(par1); this.maxStackSize = 1; this.setCreativeTab(EastonIsland.Ei3); } /* * private int getItemIntoInventory(EntityPlayer player, int itemId) { for(int i = 0; i < player.inventory.mainInventory.lenth; i ++) { if(player.inventory.mainInventory* != null && player.inventory.mainInventory*.itemID == itemId) { return i; } return -1; } }*/ @SuppressWarnings("unused") private int getItemIntoInventory(EntityPlayer player, int itemId) { for(int i = 0; i < player.inventory.mainInventory.length; i ++) { if(player.inventory.mainInventory* != null && player.inventory.mainInventory*.itemID == itemId) { return i; } return -1; } return itemId; } public boolean onEntitySwing(EntityLivingBase e, ItemStack s) { if (s.getItemDamage() == 0) if (e instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) e; boolean flag = false; if (player.capabilities.isCreativeMode) { flag = true; } else { flag = player.inventory.hasItem(EastonIsland.I9mm.itemID); } if (flag) { EntityBullet bullet = new EntityBullet(e.worldObj, e, false, "Tok", 5, 64); if (!e.worldObj.isRemote) e.worldObj.spawnEntityInWorld(bullet); e.worldObj.playSoundAtEntity(e, "ei:pistol_fire", 0.5f, 1); onUsed(s, e); player.inventory.mainInventory[getItemIntoInventory(player, EastonIsland.I9mm.itemID)].damageItem(1, player); } else e.worldObj.playSoundAtEntity(e, "ei:ClipEmpty_Pistol",0.5f, 1); } return true; } public boolean onBlockStartBreak(ItemStack s, int x, int y, int z,EntityPlayer player) { return true; } public boolean hitEntity(ItemStack s, EntityLivingBase e, EntityLivingBase source) { if (s.getItemDamage() == 0) if (source instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) source; boolean flag = false; if (player.capabilities.isCreativeMode) { flag = true; } else { flag = player.inventory .consumeInventoryItem(EastonIsland.I9mm.itemID); } if (flag) { if (!e.worldObj.isRemote) new EntityBullet(source.worldObj, source, false, "Tok",5, 64).onImpact(new MovingObjectPosition(e)); onUsed(s, source); } else source.worldObj.playSoundAtEntity(source,"ei:ClipEmpty_Pistol", 1, 1); } return false; } private void onUsed(ItemStack s, EntityLivingBase e) { s.setItemDamage(20); } public void onUpdate(ItemStack s, World w, Entity p, int i, boolean flag) { super.onUpdate(s, w, p, i, flag); if (s.getItemDamage() > 0) { s.setItemDamage(s.getItemDamage() - 1); } } @Override public void registerIcons(IconRegister iconRegister) { itemIcon = iconRegister.registerIcon("ei:Pistolet Tokarev TT 33"); } }
et des munitions
package assets.ei.ammo; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.item.Item; import assets.ei.Data.EastonIsland; import assets.mgs.common.D_Tabs; public class I_9mm extends Item { public I_9mm(int par1) { super(par1); this.maxStackSize = 1; this.setMaxDamage(15); this.setCreativeTab(EastonIsland.Ei3); } @Override public void registerIcons(IconRegister iconRegister) { itemIcon = iconRegister.registerIcon("ei:9mm"); } }
-
Essaye avec le code que j’ai conseillé, l’exception vient du fait que la boucle dépasse la taille de la liste.
for(ItemStack i : player.inventory.mainInventory){ if(i != null && i.itemID == itemId){ return i; } return -1; }
-
@‘EclipseOnFire’:
Essaye avec le code que j’ai conseillé, l’exception vient du fait que la boucle dépasse la taille de la liste.
for(ItemStack i : player.inventory.mainInventory){ if(i != null && i.itemID == itemId){ return i; } return -1; }
Il me donne une erreur à
return i;
-
Oui évidemment… T_T J’ai bouzillé ma boucle ^^ Essaye ça :
int j = 0; for(ItemStack i : player.inventory.mainInventory){ if(i != null && i.itemID == itemId){ return j; } j++; } return -1;
-
@‘EclipseOnFire’:
Essaye avec le code que j’ai conseillé, l’exception vient du fait que la boucle dépasse la taille de la liste.
for(ItemStack i : player.inventory.mainInventory){ if(i != null && i.itemID == itemId){ return i; } return -1; }
Regarde bien ce que tu fais ici. i est un ItemStack, et tu return i or la fonction est un int. Ça ne peux pas fonctionner …
Si j’ai utiliser un nombre i c’est pas pour rien, je connais aussi les itérateurs, mais ils ne convient pas dans ce cas.Je comprends pas pourquoi il return -1 alors que ton code vérifie que le joueur à bien l’item sur lui, c’est étrange.
Tu peux faire du debug ?
private int getItemIntoInventory(EntityPlayer player, int itemId) { for(int i = 0; i < player.inventory.mainInventory.lenth; i ++) { if(player.inventory.mainInventory* != null && player.inventory.mainInventory*.itemID == itemId) { return i; System.out.println("l'item se trouve dans le slot : " + i); } } System.out.println("l'item non trouvé"); return -1; }
EDIT : j’ai mit le return -1 au mauvais endroit, c’est pour ça x)
-
Parfait, ça marche, sauf que la boite de munition ne se détruit pas lorsqu’elle est vide.
-
Remplace
player.inventory.mainInventory[getItemIntoInventory(player, EastonIsland.I9mm.itemID)].damageItem(1, player);
par :
int slotId = getItemIntoInventory(player, EastonIsland.I9mm.itemID); player.inventory.mainInventory[slotId].damageItem(1, player); if(player.inventory.mainInventory[slotId].getItemDamage == 0) { player.inventory.mainInventory[slotId] = null; }
-
Je vire mes posts ça va alléger !
-
Une erreur a
int slotId = player.inventory.mainInventory[getItemIntoInventory(player, EastonIsland.I9mm.itemID)];
:```
Type mismatch: cannot convert from ItemStack to int -
oups x)
int slotId = getItemIntoInventory(player, EastonIsland.I9mm.itemID); -
Parfait, merci.
-
En fait non, il m’envoie une erreur à :
java.lang.ArrayIndexOutOfBoundsException: -1
La classe de l’item
package assets.ei.Weapons; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import assets.NolanCore.Data.EntityShoot; import assets.ei.Data.EastonIsland; import assets.ei.Data.EntityBullet; import assets.ei.Data.ItemWeapon; import assets.mgs.common.Main; public class W_GP extends ItemWeapon { private int timer = 0; public W_GP(int par1) { super(par1); this.maxStackSize = 1; this.setCreativeTab(EastonIsland.Ei3); } /* * private int getItemIntoInventory(EntityPlayer player, int itemId) { for(int i = 0; i < player.inventory.mainInventory.lenth; i ++) { if(player.inventory.mainInventory* != null && player.inventory.mainInventory*.itemID == itemId) { return i; } return -1; } }*/ public boolean onEntitySwing(EntityLivingBase e, ItemStack s) { if (s.getItemDamage() == 0) if (e instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) e; boolean flag = false; if (player.capabilities.isCreativeMode) { flag = true; } else { player.inventory.mainInventory[getItemIntoInventory(player, EastonIsland.I9mm.itemID)].damageItem(1, player); } if (flag) { EntityBullet bullet = new EntityBullet(e.worldObj, e, false, "GP", 5, 64); if (!e.worldObj.isRemote) e.worldObj.spawnEntityInWorld(bullet); e.worldObj.playSoundAtEntity(e, "ei:pistol_fire", 0.5f, 1); onUsed(s, e); int slotId = getItemIntoInventory(player, EastonIsland.I9mm.itemID); player.inventory.mainInventory[slotId].damageItem(1, player); if(player.inventory.mainInventory[slotId].getItemDamage() == 0) { player.inventory.mainInventory[slotId] = null; } } else e.worldObj.playSoundAtEntity(e, "ei:ClipEmpty_Pistol",0.5f, 1); } return true; } private int getItemIntoInventory(EntityPlayer player, int itemId) { for(int i = 0; i < player.inventory.mainInventory.length; i ++) { if(player.inventory.mainInventory* != null && player.inventory.mainInventory*.itemID == itemId) { return i; } } System.out.println("l'item non trouvé"); return -1; } public boolean onBlockStartBreak(ItemStack s, int x, int y, int z,EntityPlayer player) { return true; } public boolean hitEntity(ItemStack s, EntityLivingBase e, EntityLivingBase source) { if (s.getItemDamage() == 0) if (source instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) source; boolean flag = false; if (player.capabilities.isCreativeMode) { flag = true; } else { flag = player.inventory .consumeInventoryItem(EastonIsland.I9mm.itemID); } if (flag) { if (!e.worldObj.isRemote) new EntityBullet(source.worldObj, source, false, "GP",5, 64).onImpact(new MovingObjectPosition(e)); onUsed(s, source); } else source.worldObj.playSoundAtEntity(source,"ei:ClipEmpty_Pistol", 1, 1); } return false; } private void onUsed(ItemStack s, EntityLivingBase e) { s.setItemDamage(20); } public void onUpdate(ItemStack s, World w, Entity p, int i, boolean flag) { super.onUpdate(s, w, p, i, flag); if (s.getItemDamage() > 0) { s.setItemDamage(s.getItemDamage() - 1); } } @Override public void registerIcons(IconRegister iconRegister) { itemIcon = iconRegister.registerIcon("ei:Pistolet Browning GP"); } }
-
int slotId = getItemIntoInventory(player, EastonIsland.I9mm.itemID); if(slotId >= 0) { player.inventory.mainInventory[slotId].damageItem(1, player); if(player.inventory.mainInventory[slotId].getItemDamage() == 0) { player.inventory.mainInventory[slotId] = null; } }
Tu n’avais pas de munition quand tu as eu le crash, si ?
-
Non, je n’en n’avais pas