Netherite Elytra

Netherite Elytra

236k Downloads

With what code do you enable your custom Elytra to fly?

CaptainZidgel opened this issue ยท 2 comments

commented

Sorry if this is a weird non-issue but I'm starting learning Forge modding and I've been looking through GitHub for example code. I'm working on a mod much like yours that adds a new Elytra Item with different item properties but flight functions are not modified.
I'm able to equip my Elytra but it is functionless, and I think the reason of that is that internal code for the LivingEntity class refers to Items.ELYTRA instead of generalizing for Items that have Elytra methods, For example, from LivingEntity.java:

private void updateElytra() {
      boolean flag = this.getFlag(7);
      if (flag && !this.onGround && !this.isPassenger() && !this.isPotionActive(Effects.LEVITATION)) {
         ItemStack itemstack = this.getItemStackFromSlot(EquipmentSlotType.CHEST);
         flag = itemstack.canElytraFly(this) && itemstack.elytraFlightTick(this, this.ticksElytraFlying);
         if (false) //Forge: Moved to ElytraItem
         if (itemstack.getItem() == Items.ELYTRA && ElytraItem.isUsable(itemstack)) { //<< NOTICE THIS LINE
            flag = true;
            if (!this.world.isRemote && (this.ticksElytraFlying + 1) % 20 == 0) {
               itemstack.damageItem(1, this, (p_233652_0_) -> {
                  p_233652_0_.sendBreakAnimation(EquipmentSlotType.CHEST);
               });
            }
         } else {
            flag = false;
         }
      } else {
         flag = false;
      }

      if (!this.world.isRemote) {
         this.setFlag(7, flag);
      }

   }

Then there's getflag, where value 7 is elytra flight, and God only knows how it determines if you're flying (I cannot Intellij 'Edit Source' my way to understanding this, but I would bet the farm that it also checks if you have Items.ELYTRA).

The point being, I don't see anything in your code that I can relate to this.
I'd much appreciate anything you can elucidate for me. Thank you!

commented

I used this commit.
In this commit there is a test mod showing a minimal implementation.
Remember that this commit was small in scope as you can tell by this pull. So take care of the scope of the features. There is also an API on cuseforge which might help you too but I did not use it

commented

I see, thank you for your quick response!
I scoured the example mod to see what was different from my code or stood out from your code, but there was not much. I will leave this here in case anyone in the future has my same issue:
I was registering my Item with these properties: new Item.Properties().group(ModItemGroups.MOD_ITEM_GROUP), not bothering to set many properties until I could figure out how to fly.
But as I saw in the example code and Drunk's code, they both used new Item.Properties().maxDamage(X).group(X)
Wagering a guess, I added the max Damage property and my Elytra became flyable. It would appear to me that max Damage is either uninitiated when left out, or initiated with 0/1, causing
public static boolean isUsable(ItemStack stack) { return stack.getDamage() < stack.getMaxDamage() - 1; }
to return false.