Toggle Gravity in Ranged Item Creation

Started by Lynical on Mon, 05/24/2021 - 19:32

Topic category: Feature requests and ideas for MCreator

Last seen on 11:26, 2. Jun 2021
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Toggle Gravity in Ranged Item Creation
Mon, 05/24/2021 - 19:32

As the topic states, I think there should be an option to choose if a ranged item will shoot its projectile with gravity or not. Currently, all items you shoot with a ranged item will shoot like an arrow from a bow. You can change the power to make it go super fast if you wanted to make it instant like a gun. However, for me, I have a fireball that I want to actually see move, but not get thrown with the arch like an arrow. I managed to work around this by going into my ranged items code and adding a simple line.

Looking in the lines below you can see "entityarrow.setNoGravity(true);" however is not there by default. I had to add it in and set it to true. I think mcreator should add an option when creating the ranged item that would simply flip this line to false or true. I don't think it would be a very hard thing to add seeing how there are plenty of other things in the same code block that do the same thing.

Adding this line let me shoot my fireball exactly how I wanted, the only problem you run into is that the projectile will eventually slow down and if you don't have a procedure to despawn it the projectile will end up getting stuck in the air. That could also be added as a sub-option when setting no gravity to true.

public static ArrowCustomEntity shoot(World world, LivingEntity entity, Random random, float power, double damage, int knockback) {
        ArrowCustomEntity entityarrow = new ArrowCustomEntity(arrow, entity, world);
        entityarrow.shoot(entity.getLookVec().x, entity.getLookVec().y, entity.getLookVec().z, power * 2, 0);
        entityarrow.setSilent(true);
        entityarrow.setIsCritical(false);
        entityarrow.setDamage(damage);
        entityarrow.setKnockbackStrength(knockback);
        entityarrow.setNoGravity(true);
        world.addEntity(entityarrow);