Make an entity shoot arrows / Apply effects on Hit

Started by MagyTheMage on

Topic category: Help with MCreator software

Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Make an entity shoot arrows / Apply effects on Hit
Thu, 03/26/2020 - 05:58 (edited)

Hello, i had a question on two separate topics, however both are based on the same mob, so i decided to make em both in one;

 

First, how do i make my entity shoot actual arrows? Or other projectiles of any kind? I know that you can select for them to shoot it in item form,  but its not what i need, id like them to shoot a real arrow, the one you'd get from firing bow, is this possible? Ive though several different ways but im not sure if any would work

 

- Commands; spawning an entity;arrow going in a direction with a certain speed COULD work, but im not sure how to even do such a thing

 

- Source code editting; Theoretically if i change the projectile type in the code itself, would this be possible? 

- Make an entity actually use a bow?: i have no idea how to make this work, but if the entity actually usez their bow then the can probably shoot arrows

 

Onto the other question, how do i make a procedure that makes a mob do a effect.on something that it hits? I know "Entity attacked" is a thing, but that refers to "When an entity is attacked" and not when "Entity attacks" and i see no "when entity deals damage" or "when entity attacks" 

 

There is also no easy way to apply a selector, outside of commands, all blocks have a " do X to provided entity" and i cant find a way to tell it "Provided entity = attacker" to properly apply a potion effect even using what i know i have "Entity attacked"

 

Could anyone lend me a hand?

Edited by MagyTheMage on Thu, 03/26/2020 - 05:58
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
For your first question: It…
Thu, 03/26/2020 - 09:38

For your first question: It does shoot actual arrows it just textures them

For the second question: you will have to use custom code

Create a bow with the affects you want it to have

Set your entity to be a ranged entity.

Go into the code of the bow and copy code that looks like this (for the player only)

@Override
		public void onCollideWithPlayer(PlayerEntity entity) {
			super.onCollideWithPlayer(entity);
			int x = (int) this.posX;
			int y = (int) this.posY;
			int z = (int) this.posZ;
			World world = this.world;
			{
				java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
				$_dependencies.put("x", x);
				$_dependencies.put("y", y);
				$_dependencies.put("z", z);
				$_dependencies.put("world", world);
				MCreatorTnTBowBulletHitsBlock.executeProcedure($_dependencies);
			}
		}

Copy that and go into the code of your entity.

You will see something like:

public void attackEntityWithRangedAttack(LivingEntity target, float flval) {
			ArrowCustomEntity entityarrow = new ArrowCustomEntity(arrow, this, this.world);
			double d0 = target.posY + (double) target.getEyeHeight() - 1.1;
			double d1 = target.posX - this.posX;
			double d3 = target.posZ - this.posZ;
			entityarrow.shoot(d1, d0 - entityarrow.posY + (double) MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F, d3, 1.6F, 12.0F);
			world.addEntity(entityarrow);
		}

Go onto the last line where the } is and hit enter about 3 times to move it downward.

 

paste what you copied from the bow code

Lock the item.

 

This should work, but I am not certain

 

Thanks,

Shadow

Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well. i tried what you said…
Thu, 03/26/2020 - 15:13

Well. i tried what you said and McCreator shows compilation errors

this is what my code looks like rn

 

        public void attackEntityWithRangedAttack(EntityLivingBase target, float flval) {
            EntityArrowCustom entityarrow = new EntityArrowCustom(this.world, this);
            double d0 = target.posY + (double) target.getEyeHeight() - 1.1;
            double d1 = target.posX - this.posX;
            double d3 = target.posZ - this.posZ;
            entityarrow.shoot(d1, d0 - entityarrow.posY + (double) MathHelper.sqrt(d1 * d1 + d3 * d3) * 0.2F, d3, 1.6F, 12.0F);
            this.world.spawnEntity(entityarrow);
        
        @Override
        protected void arrowHit(EntityLivingBase entity) {
            super.arrowHit(entity);
            entity.setArrowCountInEntity(entity.getArrowCountInEntity() - 1);
            int x = (int) this.posX;
            int y = (int) this.posY;
            int z = (int) this.posZ;
            World world = this.world;
            {
                java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
                $_dependencies.put("entity", entity);
                MCreatorTestBulletHitsLivingEntity.executeProcedure($_dependencies);
            }
        }
 

Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I think i saw a Tutorial try…
Thu, 03/26/2020 - 20:03

I think i saw a Tutorial try to search in youtube

Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i dont see any tutorial,  …
Sat, 03/28/2020 - 02:30

i dont see any tutorial,

 

and im in fact confused by the lack of a "when entity deals damage" procedure, 

 

i dont know if i have an old version or something but i saw some tutorails that have these options, did they remove it??