Résolu Problème texture arc
-
Bonjour,
J’essaye de créer un arc, mais j’ai quelques problèmes, notamment au niveau de la texture. Voici la déclaration de mon arc dans la class principale de mon mod:bowEmerald = (ItemBowEmerald)(new ItemBowEmerald(212)).setUnlocalizedName("bowEmerald").setTextureName("rm:bowEmerald");
Et voici la class ItemBowEmerald:
package monMod; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.EnumAction; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.ArrowLooseEvent; import net.minecraftforge.event.entity.player.ArrowNockEvent; public class ItemBowEmerald extends Item { public static final String[] bowPullIconNameArray = new String[] {"bow_pull_emerald_0", "bow_pull_emerald_1", "bow_pull_emerald_2"}; @SideOnly(Side.CLIENT) private Icon[] iconArray; public ItemBowEmerald(int par1) { super(par1); this.maxStackSize = 1; this.setMaxDamage(384); this.setCreativeTab(CreativeTabs.tabCombat); } /** * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount */ public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { int j = this.getMaxItemUseDuration(par1ItemStack) - par4; ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return; } j = event.charge; boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (flag || par3EntityPlayer.inventory.hasItem(Item.arrow.itemID)) { float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F); entityarrow.setDamage(3.8D); if (f == 1.0F) { entityarrow.setIsCritical(true); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (k > 0) { entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D); } int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (l > 0) { entityarrow.setKnockbackStrength(l); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { entityarrow.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (flag) { entityarrow.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Item.arrow.itemID); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(entityarrow); } } } public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { return par1ItemStack; } /** * How long it takes to use or consume an item */ public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } /** * returns the action that specifies what animation to play when the items is being used */ public EnumAction getItemUseAction(ItemStack par1ItemStack) { this.setFull3D(); return EnumAction.bow; } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack); MinecraftForge.EVENT_BUS.post(event); if (event.isCanceled()) { return event.result; } if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Item.arrow.itemID)) { par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); } return par1ItemStack; } /** * Return the enchantability factor of the item, most of the time is based on material. */ public int getItemEnchantability() { return 1; } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister) { this.itemIcon = par1IconRegister.registerIcon(this.getIconString() + "_standby"); this.iconArray = new Icon[bowPullIconNameArray.length]; for (int i = 0; i < this.iconArray.length; ++i) { this.iconArray* = par1IconRegister.registerIcon(this.getIconString() + "_" + bowPullIconNameArray*); } } @SideOnly(Side.CLIENT) /** * used to cycle through icons based on their used duration, i.e. for the bow */ public Icon getItemIconForUseDuration(int par1) { return this.iconArray[par1]; } }
Donc j’ai un problème au niveau de la texture, c’est celle par défaut dans l’inventaire et aussi quand on se met à viser. Quelqu’un pourrait-il m’aider ?
Je vous remercie d’avance. -
-
Merci ! Ca fonctionne !
-
désolé de remonter ce vieux sujet mais c’est suite au lien que tu as donné, a quoi correspond cette ligne : MinecraftForge.EVENT_BUS.post(event);
car je n’ai pas un réel arc, c’est comme un stick, ça sert a rien xD
package fr.craftesys.items.common; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.init.Items; import net.minecraft.item.EnumAction; import net.minecraft.item.ItemBow; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.ArrowLooseEvent; import net.minecraftforge.event.entity.player.ArrowNockEvent; public class BowItem extends ItemBow { private IIcon[] iconbuffer; private static String[] rubisbow = new String[] {"_pull_0", "_pull_1", "_pull_2"}; public BowItem() { super(); this.maxStackSize = 1; this.setMaxDamage(1000); } @Override public void registerIcons(IIconRegister iconregister) { iconbuffer = new IIcon[rubisbow.length]; itemIcon = iconregister.registerIcon(this.getIconString()); for(int i = 0; i < rubisbow.length; i++) { iconbuffer* = iconregister.registerIcon(this.getIconString() + rubisbow*); } } @Override public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) { if(usingItem != null && usingItem.getItem().equals(ModItems.rubisbow)) { int k = usingItem.getMaxItemUseDuration() - useRemaining; if(k >= 18) return iconbuffer[2]; if(k > 13) return iconbuffer[1]; if(k > 0) return iconbuffer[0]; } return getIconIndex(stack); } @Override public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int itemInUseCount) { int charge = this.getMaxItemUseDuration(stack) - itemInUseCount; ArrowLooseEvent event = new ArrowLooseEvent(player, stack, charge); MinecraftForge.EVENT_BUS.post(event); if(event.isCanceled()) { return; } charge = event.charge; boolean creativeOrInfinity = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0; if(creativeOrInfinity || player.inventory.hasItem(Items.arrow)) { float power = 1000000000000000000F; if((double)power < 0.1D) { return; } if(power > 1.0F) { power = 1.0F; } EntityArrow arrow = new EntityArrow(world, player, power * 4.0F); if(power == 1.0F) { arrow.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack); if(var9 > 0) { arrow.setDamage(arrow.getDamage() + (double)var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack); if(var10 > 0) { arrow.setKnockbackStrength(var10); } if(EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0) { arrow.setFire(100); } stack.damageItem(1, player); world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + power * 0.5F); if(creativeOrInfinity) { arrow.canBePickedUp = 2; } else { player.inventory.consumeInventoryItem(Items.arrow); } if(!world.isRemote) { world.spawnEntityInWorld(arrow); } } } @Override public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) { return stack; } @Override public int getMaxItemUseDuration(ItemStack stack) { return 1000; } @Override public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.bow; } @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { ArrowNockEvent event = new ArrowNockEvent(player, stack); MinecraftForge.EVENT_BUS.post(event); if(event.isCanceled()) { return event.result; } if(player.capabilities.isCreativeMode || player.inventory.hasItem(Items.arrow)) { player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); } return stack; } @Override public int getItemEnchantability() { return 1; } }
-
La ligne MinecraftForge.EVENT_BUS.post(event) déclenche un event Forge.
-
un event que vous avez fait vous ?
et sais tu la raison pour laquelle il m’est impossible de charger mon arc ?
-
Tu n’as pas comrpis comment fonctionnaient les event, regarde ce code :
@Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { ArrowNockEvent event = new ArrowNockEvent(player, stack); // Tu crées une event pour les flèches, inutile dans ton cas MinecraftForge.EVENT_BUS.post(event); // Tu le post, toujours inutile if(event.isCanceled()) // Tu regarde s'il est annulé, toujours inutile { return event.result; } if(player.capabilities.isCreativeMode || player.inventory.hasItem(Items.arrow)) // Tu regardes si le joueur est en créatif ou a des flèches dans son inventaire { player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); Si c'est le cas, tu mets ton item en "utilisation" } return stack; }
-
j’ai supprimé ce qui était inutile mais je peux toujours pas charger ma flèche je dois déclarer toutes les formes que prend l’arc dans la classe principale ?
-
Non. Tu as bien des flèches dans l’inventaire ou es-tu ne créatif ?
-
c’est bon, j’ai réglé le problème, j’avais fait une faute toute bête –’ j’avais écrit :
rubisbow = new ItemMod().setUnlocalizedName(“rubisbow”).setTextureName(MODID + “:rubisbow”).setCreativeTab(CreativeTabs.tabCombat);
rubisbow = new BowItem().setUnlocalizedName(“rubisbow”).setTextureName(MODID + “:rubisbow”).setCreativeTab(CreativeTabs.tabCombat);
docn bon, c’est vrai que si je me sers pas de la classe BowItem c’est un peu bête xD