@‘DayZerd’:
Je n’y arrive pas
voila la class de mon épée :
| |
| package mod.felmod; |
| |
| import net.minecraftforge.common.util.EnumHelper; |
| |
| import net.minecraft.world.World; |
| import net.minecraft.item.ItemSword; |
| import net.minecraft.item.ItemStack; |
| import net.minecraft.item.Item; |
| import net.minecraft.init.Items; |
| |
| import java.util.Set; |
| import java.util.Random; |
| import java.util.HashMap; |
| |
| import cpw.mods.fml.common.registry.GameRegistry; |
| import cpw.mods.fml.common.event.FMLServerStartingEvent; |
| import cpw.mods.fml.common.event.FMLPreInitializationEvent; |
| |
| public class felmod_saphirrSword { |
| |
| public felmod_saphirrSword() { |
| } |
| |
| public static Item block; |
| public static Object instance; |
| |
| public void load() { |
| ItemStack stack = new ItemStack(block, 1); |
| GameRegistry.addRecipe(stack, |
| new Object[]{"0XX", "3XX", "6XX", Character.valueOf('0'), new ItemStack(felmod_saphirr.block, 1), Character.valueOf('3'), |
| new ItemStack(felmod_saphirr.block, 1), Character.valueOf('6'), new ItemStack(Items.stick, 1),}); |
| GameRegistry.addRecipe(stack, |
| new Object[]{"X0X", "X3X", "X6X", Character.valueOf('0'), new ItemStack(felmod_saphirr.block, 1), Character.valueOf('3'), |
| new ItemStack(felmod_saphirr.block, 1), Character.valueOf('6'), new ItemStack(Items.stick, 1),}); |
| GameRegistry.addRecipe(stack, |
| new Object[]{"XX0", "XX3", "XX6", Character.valueOf('0'), new ItemStack(felmod_saphirr.block, 1), Character.valueOf('3'), |
| new ItemStack(felmod_saphirr.block, 1), Character.valueOf('6'), new ItemStack(Items.stick, 1),}); |
| } |
| public boolean getIsRepairable(ItemStack input, ItemStack repair) |
| |
| { |
| |
| if(repair.getItem() == mod.felmod.felmod_saphirr.block) |
| |
| { |
| |
| return true; |
| |
| } |
| |
| return false; |
| |
| } |
| public void generateNether(World world, Random random, int chunkX, int chunkZ) { |
| } |
| |
| public void generateSurface(World world, Random random, int chunkX, int chunkZ) { |
| } |
| |
| public int addFuel(ItemStack fuel) { |
| return 0; |
| } |
| |
| public void serverLoad(FMLServerStartingEvent event) { |
| } |
| |
| public void preInit(FMLPreInitializationEvent event) { |
| } |
| |
| public void registerRenderers() { |
| } |
| |
| static { |
| Item.ToolMaterial enumt = EnumHelper.addToolMaterial("SAPHIRRSWORD", 0, 1600, 0F, 6, 10); |
| block = (Item) (new ItemSword(enumt) { |
| public Set <string>getToolClasses(ItemStack stack) { |
| HashMap <string, integer="">ret = new HashMap<string, integer="">(); |
| ret.put("sword", 0); |
| return ret.keySet(); |
| } |
| }).setUnlocalizedName("SaphirrSword").setTextureName("saphirr_sword"); |
| Item.itemRegistry.addObject(486, "SaphirrSword", block); |
| |
| } |
| |
| } |
| |
et celui de mon saphir (que je veux utiliser pour réparer mon item)
| |
| package mod.felmod; |
| |
| import net.minecraft.world.World; |
| import net.minecraft.item.ItemStack; |
| import net.minecraft.item.Item; |
| import net.minecraft.creativetab.CreativeTabs; |
| import net.minecraft.block.Block; |
| |
| import java.util.Random; |
| |
| import cpw.mods.fml.common.registry.GameRegistry; |
| import cpw.mods.fml.common.event.FMLServerStartingEvent; |
| import cpw.mods.fml.common.event.FMLPreInitializationEvent; |
| |
| @SuppressWarnings("unchecked") |
| public class felmod_saphirr { |
| |
| public felmod_saphirr() { |
| } |
| |
| public static Item block; |
| public static Object instance; |
| |
| public void load() { |
| GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"0XX", "XXX", "XXX", Character.valueOf('0'), |
| new ItemStack(felmod_saphirrBlock.block, 1),}); |
| GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"X0X", "XXX", "XXX", Character.valueOf('0'), |
| new ItemStack(felmod_saphirrBlock.block, 1),}); |
| GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"XX0", "XXX", "XXX", Character.valueOf('0'), |
| new ItemStack(felmod_saphirrBlock.block, 1),}); |
| GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"XXX", "0XX", "XXX", Character.valueOf('0'), |
| new ItemStack(felmod_saphirrBlock.block, 1),}); |
| GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"XXX", "X0X", "XXX", Character.valueOf('0'), |
| new ItemStack(felmod_saphirrBlock.block, 1),}); |
| GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"XXX", "XX0", "XXX", Character.valueOf('0'), |
| new ItemStack(felmod_saphirrBlock.block, 1),}); |
| GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"XXX", "XXX", "0XX", Character.valueOf('0'), |
| new ItemStack(felmod_saphirrBlock.block, 1),}); |
| GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"XXX", "XXX", "X0X", Character.valueOf('0'), |
| new ItemStack(felmod_saphirrBlock.block, 1),}); |
| GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"XXX", "XXX", "XX0", Character.valueOf('0'), |
| new ItemStack(felmod_saphirrBlock.block, 1),}); |
| GameRegistry.addSmelting(felmod_saphirrOre.block, new ItemStack(block), 1.0f); |
| } |
| |
| public void generateNether(World world, Random random, int chunkX, int chunkZ) { |
| } |
| |
| public void generateSurface(World world, Random random, int chunkX, int chunkZ) { |
| } |
| |
| public int addFuel(ItemStack fuel) { |
| return 0; |
| } |
| |
| public void serverLoad(FMLServerStartingEvent event) { |
| } |
| |
| public void preInit(FMLPreInitializationEvent event) { |
| } |
| |
| public void registerRenderers() { |
| } |
| |
| static { |
| block = (new Itemsaphirr(485)); |
| Item.itemRegistry.addObject(485, "Saphirr", block); |
| |
| } |
| |
| static class Itemsaphirr extends Item { |
| |
| public Itemsaphirr(int par1) { |
| setMaxDamage(0); |
| maxStackSize = 64; |
| setUnlocalizedName("Saphirr"); |
| setTextureName("saphirr"); |
| setCreativeTab(CreativeTabs.tabMaterials); |
| } |
| |
| public int getItemEnchantability() { |
| return 0; |
| } |
| |
| public int getMaxItemUseDuration(ItemStack par1ItemStack) { |
| return 0; |
| } |
| |
| public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) { |
| return 1.0F; |
| } |
| |
| } |
| } |
| |
| ```</string,></string,></string> |
Essaye en créant une classe étendue à ItemSword contenant la fonction pour réparer ton item.
Ta classe étendue devrait ressembler à ça :
| package mod.Items; |
| |
| import net.minecraft.creativetab.CreativeTabs; |
| import net.minecraft.item.ItemStack; |
| |
| public class saphirrSword extends ItemSword |
| { |
| private int weaponDamage; |
| private final EnumToolMaterial toolMaterial; |
| |
| public ItemDarksword(int par1, EnumToolMaterial par2EnumToolMaterial) |
| { |
| super(par1, par2EnumToolMaterial); |
| this.toolMaterial = par2EnumToolMaterial; |
| this.maxStackSize = 1; |
| this.setMaxDamage(par2EnumToolMaterial.getMaxUses()); |
| this.setCreativeTab(CreativeTabs.tabCombat); |
| this.weaponDamage = 4 + par2EnumToolMaterial.getDamageVsEntity(); |
| } |
| |
| |
| |
| |
| public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) |
| { |
| if (par1ItemStack.getItem()==mod.felmod.felmod_saphirrSword.block) { |
| if (par2ItemStack.getItem()==mod.felmod.felmod_saphirr.block) { |
| return true; |
| } else { |
| return false; |
| } |
| } |
| return false; |
| } |
| } |
Il suffira ensuite d’appeler la nouvelle classe saphirrSword au lieu de ItemSword :
| |
| package mod.mcreator; |
| |
| import net.minecraftforge.common.util.EnumHelper; |
| |
| import net.minecraft.world.World; |
| import net.minecraft.item.ItemSword; |
| import net.minecraft.item.ItemStack; |
| import net.minecraft.item.Item; |
| import net.minecraft.init.Items; |
| |
| import java.util.Set; |
| import java.util.Random; |
| import java.util.HashMap; |
| |
| import cpw.mods.fml.common.registry.GameRegistry; |
| import cpw.mods.fml.common.event.FMLServerStartingEvent; |
| import cpw.mods.fml.common.event.FMLPreInitializationEvent; |
| |
| public class felmod_saphirrSword { |
| |
| public felmod_saphirrSword() { |
| } |
| |
| public static Item block; |
| public static Object instance; |
| |
| public void load() { |
| ItemStack stack = new ItemStack(block, 1); |
| GameRegistry.addRecipe(stack, |
| new Object[]{"0XX", "3XX", "6XX", Character.valueOf('0'), new ItemStack(felmod_saphirr.block, 1), Character.valueOf('3'), |
| new ItemStack(felmod_saphirr.block, 1), Character.valueOf('6'), new ItemStack(Items.stick, 1),}); |
| GameRegistry.addRecipe(stack, |
| new Object[]{"X0X", "X3X", "X6X", Character.valueOf('0'), new ItemStack(felmod_saphirr.block, 1), Character.valueOf('3'), |
| new ItemStack(felmod_saphirr.block, 1), Character.valueOf('6'), new ItemStack(Items.stick, 1),}); |
| GameRegistry.addRecipe(stack, |
| new Object[]{"XX0", "XX3", "XX6", Character.valueOf('0'), new ItemStack(felmod_saphirr.block, 1), Character.valueOf('3'), |
| new ItemStack(felmod_saphirr.block, 1), Character.valueOf('6'), new ItemStack(Items.stick, 1),}); |
| } |
| |
| public boolean getIsRepairable(ItemStack input, ItemStack repair) |
| { |
| if(repair.getItem() == mod.felmod.felmod_saphirr.block) |
| { |
| return true; |
| } |
| |
| return false; |
| } |
| |
| public void generateNether(World world, Random random, int chunkX, int chunkZ) { |
| } |
| |
| public void generateSurface(World world, Random random, int chunkX, int chunkZ) { |
| } |
| |
| public int addFuel(ItemStack fuel) { |
| return 0; |
| } |
| |
| public void serverLoad(FMLServerStartingEvent event) { |
| } |
| |
| public void preInit(FMLPreInitializationEvent event) { |
| } |
| |
| public void registerRenderers() { |
| } |
| |
| static { |
| Item.ToolMaterial enumt = EnumHelper.addToolMaterial("SAPHIRRSWORD", 0, 1600, 0F, 6, 10); |
| block = (Item) (new saphirrSword(enumt) { |
| public Set <string>getToolClasses(ItemStack stack) { |
| HashMap <string, integer="">ret = new HashMap<string, integer="">(); |
| ret.put("sword", 0); |
| return ret.keySet(); |
| } |
| }).setUnlocalizedName("SaphirrSword").setTextureName("saphirr_sword"); |
| Item.itemRegistry.addObject(442, "SaphirrSword", block); |
| |
| } |
| |
| } |
| |
Je ne sais pas si ça va fonctionner de cette façon pour toi car pour mes épées j’avais créé une nouvelle classe ItemSword et une nouvelle classe EnumToolMaterial pour les personnaliser au maximum. Il faudra peut être que tu fasse quelques ajustements pour que ça fonctionne.</string,></string,></string>