Résolu Aide pour item avec meta data
-
Bonjour à tous, je me présente, Eryah.
Je voudrais faire en sorte que ma balle de fusil et la douille soit le même item, donc avec des metadatas.
J’ai pris un code sur un tuto sur internet (http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/blockstates-and-metadata/)
Et la, je bloque
Je pense que j’ai fais du bousin, en même temps, déjà que j’ai moi-même une manière étrange de fonctionner, et que lui de même ( Français pas être ), c’est assez dur de reprendre son code
Je crash au lancement du jeuCrashReport
–-- Minecraft Crash Report ---- // Everything's going to plan. No, really, that was supposed to happen. Time: 21/07/15 23:49 Description: Initializing game java.lang.NullPointerException: Initializing game at net.minecraft.client.resources.model.ModelBakery.addVariantName(ModelBakery.java:835) at eryah.usefulthings.UsefulthingsMod.preInit(UsefulthingsMod.java:166) 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.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:537) 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 com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212) at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190) 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 com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:527) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:246) at net.minecraft.client.Minecraft.startGame(Minecraft.java:446) at net.minecraft.client.Minecraft.run(Minecraft.java:356) 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 net.minecraft.client.resources.model.ModelBakery.addVariantName(ModelBakery.java:835) at eryah.usefulthings.UsefulthingsMod.preInit(UsefulthingsMod.java:166) 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.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:537) 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 com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212) at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190) 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 com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:527) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:246) at net.minecraft.client.Minecraft.startGame(Minecraft.java:446) -- Initialization -- Details: Stacktrace: at net.minecraft.client.Minecraft.run(Minecraft.java:356) 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_51, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 831315232 bytes (792 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 FML{8.99.8.1412} [Forge Mod Loader] (forgeSrc-1.8-11.14.1.1412.jar) Unloaded->Constructed->Pre-initialized Forge{11.14.1.1412} [Minecraft Forge] (forgeSrc-1.8-11.14.1.1412.jar) Unloaded->Constructed->Pre-initialized ut{Beta 1.0} [Useful Things] (bin) Unloaded->Constructed->Errored 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: Yes Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: English (US) Profiler Position: N/A (disabled)
MainClass
@EventHandler public void preInit(FMLPreInitializationEvent event) { ModelBakery.addVariantName(Bullet.bullet, "ut:bullet", "ut:bullet_casing"); } public static void registerItemRenderer() { reg(Bullet.bullet, 0, "bullet"); reg(Bullet.bullet, 1, "bullet_casing"); } public static void reg(Item item, int meta, String file) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, new ModelResourceLocation(Reference.MOD_ID + ":" + file, "inventory")); }
Classe de l’item
package eryah.usefulthings.init; import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.registry.GameRegistry; import eryah.usefulthings.Reference; import eryah.usefulthings.UsefulthingsMod; public class Bullet extends Item { public static Item bullet; public Bullet(){ this.setHasSubtypes(true); } public static void init(){ bullet = new Bullet().setUnlocalizedName("bullet").setCreativeTab(UsefulthingsMod.UTTab); } public static void register() { GameRegistry.registerItem(bullet, bullet.getUnlocalizedName().substring(5)); } public static void registerRenders() { registerRender(bullet); } 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 void getSubItems(Item itemIn, CreativeTabs tab, List subItems) { subItems.add(new ItemStack(itemIn, 1, 0)); subItems.add(new ItemStack(itemIn, 1, 1)); } @Override public String getUnlocalizedName(ItemStack stack) { return super.getUnlocalizedName() + "." + (stack.getItemDamage() == 0 ? "" : "_casing"); } }
Sur le getUnlocalizedName, j’ai rien compris, je pense que sa ce voit bien
-
Il faut mettre la fonction
ModelBakery.addVariantName(Bullet.bullet, “ut:bullet”, “ut:bullet_casing”);
après avoir initialisé l’item en question, sinon c’est normal que ça fasse un NPE. -
Je coince pour la texture, faut mettre les 2 textures dans le même json ?
-
Non. Il faut 2 json, un nommé bullet et l’autre bullet_casing (ce que tu as mit dans la méthode addVariantName).
Ensuite pour enregistrer le json au lieu d’utiliser la méthode normal avec l’itemMesher il faut faire :ModelLoader.setCustomMeshDefinition(tonItem, new ItemMeshDefinition() { @Override public ModelResourceLocation getModelLocation(ItemStack stack) { if(stack.getItemDamage() == 1) // metadata 1 { return new ModelResourceLocation("ut:bullet_casing", "inventory"); } return new ModelResourceLocation("ut:bullet", "inventory"); // autres metadatas, 0 comprit. } });
(à mettre dans preInit, après l’initialisation de l’item)
-
J’ai mis dans Postinit, comme c’est, c’est sûr
Mais j’ai toujours pas de texture sur Bullet_casing.
Sa gène si ma texture à un nom différent ? Je pense que non, vu que le model redirige vers la texture -
(à mettre dans preInit, après l’initialisation de l’item)
J’ai dit preInit, c’est pas pour rien. Si tu ne mets pas dans preInit ça ne peut pas fonctionner. -
AH c’est bon.
Bah Erreur de ma part désolé.