• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Problème avec une arbalète + Item zoom

    Sans suite
    1.10.x
    3
    4
    886
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • M
      Mereny78 dernière édition par

      Bien le bonjour,
      Aujourd’hui j’ai besoin de votre aide ^^',
      Ne pouvant pas me contenter d’un seul problème, je solliciterai de l’aide sur plusieurs points:
      J’ai crée une arbalète et celle-ci me pose quelques soucis:
      CustomArbalete.java

      public class CustomArbalete extends Item {
      
      public static final Class PROJECTILE = ItemArrow.class;
      int USE_DURATION = 72000; // Default: 72000
      double DAMAGE_MODIFIER = 500; // Default: 0.5D
      float DISTANCE_MODIFIER = 0.5F; // Default: 2.0F
      
      public CustomArbalete(int USE_DURATION, double DAMAGE_MODIFIER, float DISTANCE_MODIFIER) {
      this.USE_DURATION = USE_DURATION;
      this.DAMAGE_MODIFIER = DAMAGE_MODIFIER;
      this.DISTANCE_MODIFIER = DISTANCE_MODIFIER;
      this.setMaxStackSize(1);
      this.setMaxDamage(150);
      this.setCreativeTab(CreativeTabs.COMBAT);
      this.setUnlocalizedName(TestMod.MODID + ".custom_bow");
      this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter()
      {
      @SideOnly(Side.CLIENT)
      public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
      {
      if (entityIn == null)
      {
      return 0.0F;
      }
      else
      {
      ItemStack itemstack = entityIn.getActiveItemStack();
      return itemstack != null && itemstack.getItem() == ModItems.CUSTOM_BOW ? (float)(stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20.0F : 0.0F;
      }
      }
      });
      this.addPropertyOverride(new ResourceLocation("pulling"), new IItemPropertyGetter()
      {
      @SideOnly(Side.CLIENT)
      public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
      {
      return (entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack)||
      (stack.hasTagCompound() && stack.getTagCompound().hasKey("isCharged") && stack.getTagCompound().getBoolean("isCharged")) ? 1.0F : 0.0F;
        }
        });
      }
      
      private ItemStack findAmmo(EntityPlayer player) {
      if (this.isProjectile(player.getHeldItem(EnumHand.OFF_HAND))) {
      return player.getHeldItem(EnumHand.OFF_HAND);
      } else if (this.isProjectile(player.getHeldItem(EnumHand.MAIN_HAND))) {
      return player.getHeldItem(EnumHand.MAIN_HAND);
      } else {
      for (int i = 0; i < player.inventory.getSizeInventory(); ++i) {
      ItemStack itemstack = player.inventory.getStackInSlot(i);
      
      if (this.isProjectile(itemstack)) {
      return itemstack;
      }
      }
      
      return null;
      }
      }
      
      protected boolean isProjectile(@Nullable ItemStack stack) {
      return stack != null && PROJECTILE.isInstance(stack.getItem());
      }
      
      @Override
      public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
      if(stack.getTagCompound().hasKey("isCharged") && stack.getTagCompound().getBoolean("isCharged")) {
      return;
      }
      
      EntityPlayer playerIn = (EntityPlayer) entityLiving;
      boolean flag = playerIn.capabilities.isCreativeMode
      || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
      ItemStack itemstack = this.findAmmo(playerIn);
      
      int i = this.getMaxItemUseDuration(stack) - timeLeft;
      i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, i,
      itemstack != null || flag);
      if (i < 0)
      return;
      
      if (itemstack != null || flag) {
      if (itemstack == null) {
      itemstack = new ItemStack(Items.ARROW);
      }
      
      float f = getArrowVelocity(i);
      
      if ((double) f >= 0.1D) {
      boolean flag1 = playerIn.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow
      ? ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, playerIn) : false);
      
      stack.getTagCompound().setBoolean("isCharged", true);
      
      if (!flag1) {
      
      –itemstack.stackSize;
      
      if (itemstack.stackSize == 0) {
      playerIn.inventory.deleteStack(itemstack);
      }
      }
      }
      }
      
      }
      
      public float getArrowVelocity(int charge) {
      float f = (float) charge / 20.0F;
      f = (f * f + f * 2) / 3.0F;
      
      if (f > 1.0F) {
      f = 1.0F;
      }
      
      return f*DISTANCE_MODIFIER;
      }
      
      @Override
      public int getMaxItemUseDuration(ItemStack stack) {
      return USE_DURATION;
      }
      
      @Override
      public EnumAction getItemUseAction(ItemStack stack) {
      return EnumAction.BOW;
      }
      
      @Override
      public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn) {
      createNbt(stack);
      super.onCreated(stack, worldIn, playerIn);
      }
      
      public void createNbt(ItemStack stack){
      if(!stack.hasTagCompound()) {
      stack.setTagCompound(new NBTTagCompound());
      stack.getTagCompound().setBoolean("isCharged", false);
      }
      }
      
      @Override
      public ActionResult <itemstack>onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn,
      EnumHand hand) {
      createNbt(itemStackIn);
      if (!playerIn.hasAchievement(AchievementHandler.bow_use)) {
      playerIn.addStat(AchievementHandler.bow_use);
      }
      if(!itemStackIn.hasTagCompound()){
      System.out.println("ERROR");
      return new ActionResult(EnumActionResult.FAIL, itemStackIn);
      }
      
      if((!itemStackIn.getTagCompound().hasKey("isCharged") || !itemStackIn.getTagCompound().getBoolean("isCharged"))) {
      if(playerIn.getRidingEntity() != null)
      return new ActionResult(EnumActionResult.FAIL, itemStackIn);
      
      boolean flag = this.findAmmo(playerIn) != null;
      
      ActionResult <itemstack>ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemStackIn, worldIn,
      playerIn, hand, flag);
      if (ret != null)
      return ret;
      
      if (!playerIn.capabilities.isCreativeMode && !flag) {
      return !flag ? new ActionResult(EnumActionResult.FAIL, itemStackIn)
      : new ActionResult(EnumActionResult.PASS, itemStackIn);
      } else {
      playerIn.setActiveHand(hand);
      return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
      }
      }
      else{
      float f = getArrowVelocity(getMaxItemUseDuration(itemStackIn));
      
      if ((double) f >= 0.1D) {
      
      if (!worldIn.isRemote) {
      ItemArrow itemarrow = (ItemArrow) Items.ARROW;
      EntityArrow entityarrow = itemarrow.createArrow(worldIn, new ItemStack(Items.ARROW), playerIn);
      entityarrow.setAim(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, f * 3.0F,
      1.0F);
      
      if (f == 1.0F) {
      entityarrow.setIsCritical(true);
      }
      
      int powerModifier = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, itemStackIn);
      
      if (powerModifier > 0) {
      entityarrow.setDamage(entityarrow.getDamage() + (double)powerModifier * 0.5D + 0.5D);
      }
      
      int punchModifier = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, itemStackIn);
      
      if (punchModifier > 0) {
      entityarrow.setKnockbackStrength(punchModifier);
      }
      
      if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, itemStackIn) > 0) {
      entityarrow.setFire(100);
      }
      
      itemStackIn.damageItem(1, playerIn);
      
      entityarrow.setDamage(entityarrow.getDamage() * DAMAGE_MODIFIER);
      worldIn.spawnEntity(entityarrow);
      }
      
      worldIn.playSound((EntityPlayer) null, playerIn.posX, playerIn.posY, playerIn.posZ,
      SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F,
      1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
      
      itemStackIn.getTagCompound().setBoolean("isCharged", false);
      itemStackIn.getTagCompound().setBoolean("alreadyUse", true);
      return new ActionResult(EnumActionResult.FAIL, itemStackIn);
      }
      }
      return new ActionResult(EnumActionResult.FAIL, itemStackIn);
      }
      
      @Override
      public int getItemEnchantability() {
      return 1;
      }
      }
      

      La propriété pull pour l’animation, ne se met pas à jour, seule pulling est vérifié (après avoir essayé plusieurs de comprendre pourquoi, je n’ai toujours pas trouvé; même en enlevant pulling, pull n’est toujours pas vérifiée); comment faire ?
      Une fois la flèche chargée (après l’avoir rechargé donc), l’arbalète se remet à se charger automatiquement si on maintient le clic droit, comment faire pour “obliger” un “reclic” pour pouvoir recharger ?
      Comment ralentir l’animation (pas celle relative à la texture) qui montre l’item chargé au maximum ? Je pensais que c’était maxDuration mais celui-ci est de base à une heure pour l’arc (or on sait tous que quelques secondes suffisent)

      Enfin, (aucun rapport), j’ai crée un item qui permet de zoomer (en suivant le tuto sur le forum) sauf que ça ne marche pas exactement 😛 , seul les chunks dans la zone zoomée sont chargés mais la caméra ne zoom pas (donc on ne voit pas certains chunks, oui), l’event est bien activé et la variable est bien changée

         @SubscribeEvent
          @SideOnly(Side.CLIENT)
          public void onRenderExperienceBar(RenderGameOverlayEvent event)
          {
              if(FortifyMod.zoom)
              {
                  if(Minecraft.getMinecraft().gameSettings.thirdPersonView == 0)
                  {
                      zoom(6.0D); //c'est d�j� pas mal, mais libre � vous de jongler sur la valeur
                  }
              }
       else{
                  zoom(1.0d); //par défaut, le zoom de la cam�ra est � 1.0d
              }
          }
      private void zoom(double zoomValue) {
              try {
                  EntityRenderer.class.getClass().getField("field_78503_V").set(Minecraft.getMinecraft().entityRenderer, zoomValue);
              } catch (IllegalAccessException | NoSuchFieldException e) {
                  e.printStackTrace();
              }
      }
      

      Comment pourrais-je corriger ce problème ? (j’ai déjà tester plusieurs méthodes permettant de changer la valeur de cette variable sans succès (et j’ai bien évidemment chercher sur internet))

      Merci d’avance pour votre aide ^^ !  :D</itemstack></itemstack>

      1 réponse Dernière réponse Répondre Citer 0
      • robin4002
        robin4002 Moddeurs confirmés Rédacteurs Administrateurs dernière édition par

        Salut,

        Pour le zoom j’ai constaté le même problème, cette méthode ne semble plus fonctionner en 1.10.
        Utilises plutôt l’event FOVUpdateEvent, tu pourra faire event.setNewfov(1.0F / zoom); pour changer le zoom dans l’event.

        Pour le problème de l’arbalète je ne sais pas, il faudrait que je regardes plus en détails.

        1 réponse Dernière réponse Répondre Citer 0
        • M
          Mereny78 dernière édition par

          Oki, merci robin 🙂 !
          Si quelqu’un sait comment m’aider qu’il n’hésite pas hein 😛 je sèche

          1 réponse Dernière réponse Répondre Citer 0
          • Infinite
            Infinite dernière édition par

            Déja il semble que tu n’a pas configuré ton eclipse en UTF-8 parce que les é se sont transformés en ? quand tu les a copiés collés.

            Mes Sites(Mes Sites)
            |
            |    Site général : Game & play
            |   Site de projets (en dev !) :Infinite's Ressources
            J'ai et je suis content d'avoir 16,75 points d'ICRating

            1 réponse Dernière réponse Répondre Citer 0
            • 1 / 1
            • Premier message
              Dernier message
            Design by Woryk
            Contact / Mentions Légales

            MINECRAFT FORGE FRANCE © 2018

            Powered by NodeBB