Résolu Transformer un item en un autre comme les fioles
-
Bonjour, je me présente, Eryah. je m’attaque enfin , à l’item que je voulait créer un PREMIER, car c’est lui qui m’a donné envie de faire ce mod : La bouteille d’air.
Elle est inutile sur terre, mais dans l’eau, elle permet de regagner entièrement sa jauge d’oxygène. Pour l’obtenir, il suffit de right click dans l’air avec une bouteille présice. Mais…
Je n’arrive pas à faire un sorte de cela
J’ai pris le code de la bouteille de verre de base de MinecraftCode de la bouteille hermétique ( Partie concernée)
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true); if (movingobjectposition == null) { return itemStackIn; } else { if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { BlockPos blockpos = movingobjectposition.getBlockPos(); if (!worldIn.isBlockModifiable(playerIn, blockpos)) { return itemStackIn; } if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn)) { return itemStackIn; } if (worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.air) { --itemStackIn.stackSize; playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]); if (itemStackIn.stackSize <= 0) { return new ItemStack(Items.potionitem); } if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potionitem))) { playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potionitem, 1, 0), false); } } } return itemStackIn; }
L’item destiné a étre obtenu n’existant pas encore, je laisse le drop du code de base ( fiole d’eau )
-
À mon avis cela ne fonctionne pas car
movingobjectposition.typeOfHit n’est pas du type MovingObjectPosition.MovingObjectType.BLOCK quand on clic dans le vide.
Ajoute System.out.println(movingobjectposition.typeOfHit.toString()); avant la condition et fait un clic droit dans le vide pour voir ce qu’il vaut. -
Je n ai pas eclipse sous mes yeux mais je crois que c’est plutôt
MovingObjectType.Air -
public static enum MovingObjectType { MISS, BLOCK, ENTITY; private static final String __OBFID = "CL_00000611"; }
Non, c’est MISS
-
Ah j avais cru que c’était en 1.7.10 autant pour moi.
-
J’ai tenté d’allegé le code ( J’ai peut-etre fait de la merde :S ) car je trouvait toute ses conditions inutiles.
Sinon, je ne sais pas si j’ai bien placé le system.out.printIn, car il ne fonctionne pasPartie concernée du code
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true); System.out.println(movingobjectposition.typeOfHit.toString()); if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { BlockPos blockpos = movingobjectposition.getBlockPos(); if (worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.air) { –itemStackIn.stackSize; playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]); if (itemStackIn.stackSize <= 0) { return new ItemStack(Items.potionitem); } if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potionitem))) { playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potionitem, 1, 0), false); } } } return itemStackIn; } }
Petite erreur lors de la création de l’item en question
package eryah.usefulthings.init; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraftforge.fml.common.registry.GameRegistry; import eryah.usefulthings.Reference; import eryah.usefulthings.UsefulthingsMod; public class AirBottle extends ItemFood { ***public AirBottle(int amount,float saturationModifier, boolean alwaysEdible ***) { super(amount,saturationModifier ,alwaysEdible); } public static Item air_bottle; public final int itemUseDuration; private final int healAmount; private final float saturationModifier; private final boolean isWolfsFavoriteMeat; private boolean alwaysEdible; private int potionId; private int potionDuration; private int potionAmplifier; private float potionEffectProbability; public static void init(){ air_bottle = new Item().setUnlocalizedName("air_bottle").setCreativeTab(UsefulthingsMod.UTTab); } public static void register() { GameRegistry.registerItem(air_bottle, air_bottle.getUnlocalizedName().substring(5)); } public static void registerRenders() { registerRender(air_bottle); } public static void registerRender(Item item) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory")); } public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.DRINK; } public ItemFood setPotionEffect(int id, int duration, int amplifier, float probability) { this.potionId = 16; this.potionDuration = 1; this.potionAmplifier = 200; this.potionEffectProbability = 1.0F; return this; } }
The blank final field saturationModifier may not have been initialized
-
Tu l’as mit au bon endroit. Il n’affiche rien ?
Essayes d’ajouter @Override au dessus de ta fonction ? -
Toujours rien
-
Pas possible. Il faudrait forcement avoir quelque chose dans les logs. Envoie toute ta classe.
-
package eryah.usefulthings.init; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.stats.StatList; import net.minecraft.util.BlockPos; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import eryah.usefulthings.Reference; import eryah.usefulthings.UsefulthingsMod; public class BottleHerm extends Item { public static Item bottleherm; public static void init(){ bottleherm = new Item().setUnlocalizedName("bottleherm").setCreativeTab(UsefulthingsMod.UTTab); } public static void register() { GameRegistry.registerItem(bottleherm, bottleherm.getUnlocalizedName().substring(5)); } public static void registerRenders() { registerRender(bottleherm); } public static void registerRender(Item item) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory")); } @Override public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true); System.out.println(movingobjectposition.typeOfHit.toString()); if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { BlockPos blockpos = movingobjectposition.getBlockPos(); if (worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.air) { –itemStackIn.stackSize; playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]); if (itemStackIn.stackSize <= 0) { return new ItemStack(Items.potionitem); } if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potionitem))) { playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potionitem, 1, 0), false); } } } return itemStackIn; } }
-
bottleherm = new Item().setUnlocalizedName(“bottleherm”).setCreativeTab(UsefulthingsMod.UTTab);
–’
Est-ce que tu comprends au moins cette ligne ?!
Ici, tu initialise ton item avec la classe Item. Donc il prend ce qu’il y a dans la casse Item et ignore complètement ta classe.Il faut faire :
bottleherm = new BottleHerm().setUnlocalizedName(“bottleherm”).setCreativeTab(UsefulthingsMod.UTTab); -
Ah… Eh bien je vais faire la modification sur la totalité des items de mon mod ^^’
C’est le code de MrCrayFish, et moi comme un con, je vérifiais même pas ses codes, que je recopiait aveuglément…
Mon jeu crash quand je rightClick dans le vide
---- Minecraft Crash Report ---- // On the bright side, I bought you a teddy bear! Time: 25/06/15 21:02 Description: Unexpected error java.lang.NullPointerException: Unexpected error at eryah.usefulthings.init.BottleHerm.onItemRightClick(BottleHerm.java:45) at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:168) at net.minecraft.client.multiplayer.PlayerControllerMP.sendUseItem(PlayerControllerMP.java:475) at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1599) at net.minecraft.client.Minecraft.runTick(Minecraft.java:2130) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1087) at net.minecraft.client.Minecraft.run(Minecraft.java:376) at net.minecraft.client.main.Main.main(Main.java:117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at eryah.usefulthings.init.BottleHerm.onItemRightClick(BottleHerm.java:45) at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:168) at net.minecraft.client.multiplayer.PlayerControllerMP.sendUseItem(PlayerControllerMP.java:475) at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1599) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityPlayerSP['Eryah'/77, l='MpServer', x=171,12, y=65,00, z=295,42]] Chunk stats: MultiplayerChunkCache: 25, 25 Level seed: 0 Level generator: ID 01 - flat, ver 0\. Features enabled: false Level generator options: Level spawn location: 182,00,4,00,237,00 - World: (182,4,237), Chunk: (at 6,0,13 in 11,14; contains blocks 176,0,224 to 191,255,239), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 443339 game time, 1 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 38 total; [EntityCow['Vache'/7, l='MpServer', x=139,16, y=64,00, z=262,22], EntityChicken['Poule'/8, l='MpServer', x=141,66, y=64,00, z=303,63], EntityPig['Cochon'/9, l='MpServer', x=133,91, y=64,00, z=319,16], EntityPlayerSP['Eryah'/77, l='MpServer', x=171,12, y=65,00, z=295,42], EntityItem['item.item.egg'/14, l='MpServer', x=149,16, y=64,00, z=308,25], EntityItemFrame['entity.ItemFrame.name'/26, l='MpServer', x=182,97, y=65,50, z=263,50], EntityItemFrame['entity.ItemFrame.name'/27, l='MpServer', x=182,97, y=65,50, z=257,50], EntityItemFrame['entity.ItemFrame.name'/28, l='MpServer', x=182,97, y=65,50, z=261,50], EntityItemFrame['entity.ItemFrame.name'/29, l='MpServer', x=182,97, y=65,50, z=271,50], EntityItemFrame['entity.ItemFrame.name'/30, l='MpServer', x=182,97, y=65,50, z=265,50], EntityItemFrame['entity.ItemFrame.name'/31, l='MpServer', x=182,97, y=65,50, z=269,50], EntityItemFrame['entity.ItemFrame.name'/32, l='MpServer', x=182,97, y=65,50, z=267,50], EntityItemFrame['entity.ItemFrame.name'/33, l='MpServer', x=182,97, y=65,50, z=259,50], EntityItemFrame['entity.ItemFrame.name'/34, l='MpServer', x=182,97, y=65,50, z=273,50], EntityItemFrame['entity.ItemFrame.name'/35, l='MpServer', x=182,97, y=65,50, z=279,50], EntityItemFrame['entity.ItemFrame.name'/36, l='MpServer', x=182,97, y=65,50, z=277,50], EntityItemFrame['entity.ItemFrame.name'/37, l='MpServer', x=182,97, y=65,50, z=281,50], EntityItemFrame['entity.ItemFrame.name'/38, l='MpServer', x=182,97, y=65,50, z=285,50], EntityItemFrame['entity.ItemFrame.name'/39, l='MpServer', x=182,97, y=65,50, z=287,50], EntityItemFrame['entity.ItemFrame.name'/40, l='MpServer', x=182,97, y=65,50, z=275,50], EntityItemFrame['entity.ItemFrame.name'/41, l='MpServer', x=182,97, y=65,50, z=283,50], EntityItemFrame['entity.ItemFrame.name'/42, l='MpServer', x=182,97, y=65,50, z=289,50], EntityItemFrame['entity.ItemFrame.name'/43, l='MpServer', x=182,97, y=65,50, z=293,50], EntityItemFrame['entity.ItemFrame.name'/44, l='MpServer', x=182,97, y=65,50, z=297,50], EntityItemFrame['entity.ItemFrame.name'/45, l='MpServer', x=182,97, y=65,50, z=295,50], EntityItemFrame['entity.ItemFrame.name'/46, l='MpServer', x=182,97, y=65,50, z=303,50], EntityItemFrame['entity.ItemFrame.name'/47, l='MpServer', x=182,97, y=65,50, z=291,50], EntityItemFrame['entity.ItemFrame.name'/48, l='MpServer', x=182,97, y=65,50, z=299,50], EntityItemFrame['entity.ItemFrame.name'/49, l='MpServer', x=182,97, y=65,50, z=301,50], EntityItemFrame['entity.ItemFrame.name'/50, l='MpServer', x=182,97, y=65,50, z=305,50], EntityItemFrame['entity.ItemFrame.name'/51, l='MpServer', x=182,97, y=65,50, z=313,50], EntityItemFrame['entity.ItemFrame.name'/52, l='MpServer', x=182,97, y=65,50, z=317,50], EntityItemFrame['entity.ItemFrame.name'/53, l='MpServer', x=182,97, y=65,50, z=311,50], EntityItemFrame['entity.ItemFrame.name'/54, l='MpServer', x=182,97, y=65,50, z=307,50], EntityItemFrame['entity.ItemFrame.name'/55, l='MpServer', x=182,97, y=65,50, z=315,50], EntityItemFrame['entity.ItemFrame.name'/56, l='MpServer', x=182,97, y=65,50, z=309,50], EntityItem['item.item.golden_egg'/59, l='MpServer', x=204,81, y=64,00, z=283,69], GoldenEggChicken['Golden Egg Chicken'/60, l='MpServer', x=201,63, y=64,00, z=288,28]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:392) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2613) at net.minecraft.client.Minecraft.run(Minecraft.java:405) at net.minecraft.client.main.Main.main(Main.java:117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) – System Details -- Details: Minecraft Version: 1.8 Operating System: Windows 8.1 (amd64) version 6.3 Java Version: 1.8.0_45, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 799214144 bytes (762 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.10 FML v8.99.8.1412 Minecraft Forge 11.14.1.1412 4 mods loaded, 4 mods active mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{8.99.8.1412} [Forge Mod Loader] (forgeSrc-1.8-11.14.1.1412.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{11.14.1.1412} [Minecraft Forge] (forgeSrc-1.8-11.14.1.1412.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available ut{Beta 1.0} [Useful Things] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Loaded coremods (and transformers): GL info: ' Vendor: 'ATI Technologies Inc.' Version: '4.2.12420 Compatibility Profile Context 13.151.0.0' Renderer: 'AMD Radeon HD 8240' Launched Version: 1.8 LWJGL: 2.9.1 OpenGL: AMD Radeon HD 8240 GL version 4.2.12420 Compatibility Profile Context 13.151.0.0, ATI Technologies Inc. GL Caps: Using GL 1.3 multitexturing. Using GL 1.3 texture combiners. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Shaders are available because OpenGL 2.1 is supported. VBOs are available because OpenGL 1.5 is supported. Using VBOs: No Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: Français (France) Profiler Position: N/A (disabled)
-
Bon c’est bien ce que je pensais.
movingobjectposition est null quand on clic dans le vide.
Du-coup il faut faire :public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true); System.out.println(movingobjectposition.typeOfHit.toString()); if (movingobjectposition == null) { –itemStackIn.stackSize; playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]); if (itemStackIn.stackSize <= 0) { return new ItemStack(Items.potionitem); } if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potionitem))) { playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potionitem, 1, 0), false); } } return itemStackIn; } }
-
Il y a une erreur invisible… sur public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
Multiple markers at this line- Syntax error on token “Invalid Character”, delete
this token - overrides
net.minecraft.item.Item.onItemRightClick
je dis invisible, car il n’y a pas le soulignement rouge
- Syntax error on token “Invalid Character”, delete
-
Ré-écrit à la main la partie qui bug. Des fois les copier/coller depuis le fofo fait des trucs étrange.
-
Il faut également supprimer le printIn, sinon cela ne fonctionne pas
Plus d’erreur, je lance mon client
j’espère que cela va fonctionner !Ça fonctionne
Merci beaucoup robin pour ton aide