[TUTORIAL] Making a flying armor 2022.x - Forge 1.18.2 - Look at the comments for updates up to 2023.x 1.20.1

Started by __SK__ on

Topic category: User side tutorials

Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[TUTORIAL] Making a flying armor 2022.x - Forge 1.18.2 - Look at the comments for updates up to 2023.x 1.20.1
Sat, 05/04/2024 - 01:18 (edited)

I tried to make it as simple as possible, it does require to lock the code.

  1. Create your default or custom 3d armor
  2. Modify the desired settings
  3. Save
  4. Now lock the code
  5. Copy the following and paste it right before the last "}" in the code

 

    

   @Override
   public boolean canElytraFly(ItemStack stack, net.minecraft.world.entity.LivingEntity entity) {
      return true;
   }

   @Override
   public boolean elytraFlightTick(ItemStack stack, net.minecraft.world.entity.LivingEntity entity, int flightTicks) {
      if (!entity.level.isClientSide) {
         int nextFlightTick = flightTicks + 1;
         if (nextFlightTick % 10 == 0) {
            if (nextFlightTick % 20 == 0) {
               stack.hurtAndBreak(1, entity, e -> e.broadcastBreakEvent(net.minecraft.world.entity.EquipmentSlot.CHEST));
            }
            entity.gameEvent(net.minecraft.world.level.gameevent.GameEvent.ELYTRA_FREE_FALL);
         }
      }
      return true;
   }

=============SPECIAL NOTE================

    If needed set stack.hurtAndBreak from 1 (default value - breakable) to 0 (unbreakable)

=============SPECIAL NOTE================

 

Congratulations, now your armor (chestplate) will act just like an elytra ... and still have armor properties.

If you still have doubts, watch the following ...

NOTE: Apologies for the image hosting issues, one of my server admins decided to rearrange the content in it causing mapping issues.

Please ... (right click and save for future reference)

Results ...

Take off

Landing

With some creativity you could add a tick to the chestplate ... adding an additional chestplate that will switch while in air for a winged model, making it cool and more enjoyable to watch.

 

I would gladly like to see screenshots of your creations.

Have fun

Edited by __SK__ on Sat, 05/04/2024 - 01:18
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@Visa - This is how I did it…
Tue, 10/03/2023 - 09:21

@Visa - This is how I did it. Just look at the //ENABLE ELYTRA FLYING


public class TemplateArmor
extends GeoArmorItem
implements IAnimatable {
private AnimationFactory factory = new AnimationFactory(this);

private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP =
(new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>())
.put(ModArmorMaterials.CYBORG_RED, new MobEffectInstance(MobEffects.REGENERATION, 200, 0, false, false)).build();


public TemplateArmor(final ArmorMaterial material, final EquipmentSlot slot, final Item.Properties settings) {
super(material, slot, settings);
this.factory = new AnimationFactory((IAnimatable)this);
}

public void registerControllers(final AnimationData data) {
data.addAnimationController(new AnimationController((IAnimatable)this, "controller", 10.0f, this::predicate));
}

public AnimationFactory getFactory() {
return this.factory;
}

private <P extends IAnimatable> PlayState predicate(AnimationEvent<P> event) {
LivingEntity livingEntity = (LivingEntity)event.getExtraDataOfType(LivingEntity.class).get(0);
if (livingEntity.isFallFlying()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle1", Boolean.valueOf(true)));
return PlayState.CONTINUE;
}
if (livingEntity.isBlocking()) {
if (livingEntity.getMainHandItem().getItem() == ModItems.CYBORG_SHIELD.get()) {
//if (livingEntity.m_21206_().m_41720_() == ModItems.CYBORG_SHIELD.get()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle4", Boolean.valueOf(true)));
return PlayState.CONTINUE;
}
if (livingEntity.getOffhandItem().getItem() == ModItems.CYBORG_SHIELD.get()) {
//if (livingEntity.m_21205_().m_41720_() == ModItems.CYBORG_SHIELD.get()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle4", Boolean.valueOf(true)));
return PlayState.CONTINUE;
}
}
if (livingEntity.isCrouching()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle3", Boolean.valueOf(true)));
return PlayState.CONTINUE;
}
if (livingEntity.isSprinting()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle2", Boolean.valueOf(true)));
return PlayState.CONTINUE;
}
if (livingEntity.isFreezing()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle2", Boolean.valueOf(true)));
return PlayState.CONTINUE;
}
if (livingEntity.isOnFire()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle2", Boolean.valueOf(true)));
return PlayState.CONTINUE;
}
if (livingEntity.isInPowderSnow) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle2", Boolean.valueOf(true)));
return PlayState.CONTINUE;
}
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle", Boolean.valueOf(true)));
return PlayState.CONTINUE;
}


@Override
public void onArmorTick(ItemStack stack, Level world, Player player) {
if(!world.isClientSide()) {
if(hasFullSuitOfArmorOn(player)) {
evaluateArmorEffects(player);
} else if (!hasFullSuitOfArmorOn(player)) {
player.getAbilities().flying = false;
player.getAbilities().mayfly = false;
//player.getAbilities().flying = elytraFlightTick(stack, player, 1);
player.onUpdateAbilities();
}
}
}

private void evaluateArmorEffects(Player player) {
for (Map.Entry<ArmorMaterial, MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()) {
ArmorMaterial mapArmorMaterial = entry.getKey();
MobEffectInstance mapStatusEffect = entry.getValue();

if(hasCorrectArmorOn(mapArmorMaterial, player)) {
addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect);
}
}
}

private void addStatusEffectForMaterial(Player player, ArmorMaterial mapArmorMaterial,
MobEffectInstance mapStatusEffect) {
boolean hasPlayerEffect = player.hasEffect(mapStatusEffect.getEffect());

if(hasCorrectArmorOn(mapArmorMaterial, player) && !hasPlayerEffect) {
player.addEffect(new MobEffectInstance(mapStatusEffect.getEffect(),
mapStatusEffect.getDuration(), mapStatusEffect.getAmplifier(), mapStatusEffect.isAmbient(), mapStatusEffect.isVisible()));

}
if(hasFullSuitOfArmorOn(player) && !player.getAbilities().mayfly) {
player.getAbilities().mayfly = false;
player.onUpdateAbilities();
}
}

private boolean hasFullSuitOfArmorOn(Player player) {
ItemStack boots = player.getInventory().getArmor(0);
ItemStack leggings = player.getInventory().getArmor(1);
ItemStack breastplate = player.getInventory().getArmor(2);
ItemStack helmet = player.getInventory().getArmor(3);

return !helmet.isEmpty() && !breastplate.isEmpty()
&& !leggings.isEmpty() && !boots.isEmpty();
}

private boolean hasCorrectArmorOn(ArmorMaterial material, Player player) {
for (ItemStack armorStack: player.getInventory().armor) {
if(!(armorStack.getItem() instanceof ArmorItem)) {
return false;
}
}

ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem());
ArmorItem leggings = ((ArmorItem)player.getInventory().getArmor(1).getItem());
ArmorItem breastplate = ((ArmorItem)player.getInventory().getArmor(2).getItem());
ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem());

return helmet.getMaterial() == material && breastplate.getMaterial() == material &&
leggings.getMaterial() == material && boots.getMaterial() == material;
}

//ENABLE ELYTRA FLYING

@Override
public boolean canElytraFly(ItemStack stack, LivingEntity entity) {
return true;
}

@Override
public boolean elytraFlightTick(ItemStack stack, LivingEntity entity, int flightTicks)
{
if (!entity.level.isClientSide && (flightTicks + 1) % 20 == 0) {
//set stack.hurtAndBreak from 1 (default value - breakable) to 0 (unbreakable)
stack.hurtAndBreak(0, entity, e -> e.broadcastBreakEvent(net.minecraft.world.entity.EquipmentSlot.CHEST));
}
return true;
}

protected boolean onGround;
public void setOnGround(boolean p_20181_) {
this.onGround = p_20181_;
}

public boolean isOnGround() {
return this.onGround;
}
}
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@Max10tails - I never had an…
Tue, 10/03/2023 - 09:23

@Max10tails - I never had an issue playing in a server, usually the mod has to be in the server and in the client.

Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
could you add a tutorial on…
Tue, 10/03/2023 - 23:55

could you add a tutorial on how to get this to work so it has wings when in air

Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
does this work with 3d modle…
Wed, 10/04/2023 - 00:08

does this work with 3d modle armor?

Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yes ... That is the entire…
Wed, 10/04/2023 - 18:47

Yes ... That is the entire code for a Geckolib 3d armor, including how to enable the elytra flying, and how to trigger the armor animations with:

  • fall flying
  • blocking with shield on right or left hand - good for armors with wings
  • crouching
  • sprinting
  • freezing
  • on fire
  • in powder snow
  • idle

The code is the entire tutorial, you only need to: 

  • create your own custom animations 
  • rename them to your preference 
  • test it.

It also has a regeneration effect (or you could assign a different or custom effect) while wearing the full set.  Or just remove it.

Joined Jul 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Does work for 1.19.4?…
Wed, 10/25/2023 - 15:45

Does work for 1.19.4? Because the armor doesnt compile correctly. 

Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@ valencian That code is for…
Wed, 10/25/2023 - 22:20

@ valencian

That code is for a Geckolib armor. Just generate the code with MCreator and then add at the bottom ... 



    //ENABLE ELYTRA FLYING

    @Override
    public boolean canElytraFly(ItemStack stack, LivingEntity entity) {
        return true;
    }

    @Override
    public boolean elytraFlightTick(ItemStack stack, LivingEntity entity, int flightTicks)
    {
        if (!entity.level.isClientSide && (flightTicks + 1) % 20 == 0) {
            //set stack.hurtAndBreak from 1 (default value - breakable) to 0 (unbreakable)
            stack.hurtAndBreak(0, entity, e -> e.broadcastBreakEvent(net.minecraft.world.entity.EquipmentSlot.CHEST));
        }
        return true;
    }

    protected boolean onGround;
    public void setOnGround(boolean p_20181_) {
        this.onGround = p_20181_;
    }

    public boolean isOnGround() {
        return this.onGround;
    }

If you decide to copy/paste it, then you will need to figure out what is causing the error in your project.

Maybe the class name, or the animations I added based on a custom shield on hand ... not sure.

Joined Jul 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh, I forgot to say that i…
Fri, 10/27/2023 - 00:20

Oh, I forgot to say that i figured out the issue, anyways thanks!

Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
error: cannot find symbol
Mon, 12/04/2023 - 19:05
error: cannot find symbol
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
error: cannot find symbol  
Mon, 12/04/2023 - 19:06

error: cannot find symbol

 

Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
https://www.mediafire.com…
Mon, 12/04/2023 - 19:15
https://www.mediafire.com/view/60o9x4n4lxoo1zk/Bildschirmfoto_2023-12-04_um_20.13.31.png/file
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Did you just posted MCreator…
Wed, 12/06/2023 - 07:39

Did you just posted MCreator 2013.3 ...? I think it was for 1.6

Which MCreator version are you using? Post a screenshot of the version

For which Minecraft version is the armor for?

Please show the entire code (not just the error) in order to possibly help you better.

Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok, so possibly you had a…
Wed, 12/06/2023 - 08:00

Ok, so possibly you had a typo with the version ...

 

I just double-checked the code and found a slight change for 2023.3. 

It had a change from:

.level 

to:

.level()

Updated code:

	//ENABLE ELYTRA FLYING

    @Override
    public boolean canElytraFly(ItemStack stack, LivingEntity entity) {
        return true;
    }

    @Override
    public boolean elytraFlightTick(ItemStack stack, LivingEntity entity, int flightTicks)
    {
        if (!entity.level().isClientSide && (flightTicks + 1) % 20 == 0) {
            //set stack.hurtAndBreak from 1 (default value - breakable) to 0 (unbreakable)
            stack.hurtAndBreak(0, entity, e -> e.broadcastBreakEvent(net.minecraft.world.entity.EquipmentSlot.CHEST));
        }
        return true;
    }

    protected boolean onGround;
    public void setOnGround(boolean p_20181_) {
        this.onGround = p_20181_;
    }

    public boolean isOnGround() {
        return this.onGround;
    }

 

Also, double check the imports (at the top fo the code):

import net.minecraft.world.entity.LivingEntity;//MIGHT BE REQUIRED