Jump to content

[1.14.4] [SOLVED] Changing the attack time of a IRangedAttackMob entity + Rendering Problem


Cerandior

Recommended Posts

I have created a monster that is quite like a skeleton, except that it has some special abilities.
I wanted him to have a "frenzy mode" so that if his hp drops below 20%, it starts shooting arrows crazy fast.

 

As far as I am aware, the attack time of a ranged mob is handled by the maxAttackTime (40 in this case) value of this goal:
 

this.goalSelector.addGoal(1, new RangedAttackGoal(this, (double)0.3F, 40, 20.0F));


Is it possible to change this value after the goal has been registered? I tried re-applying the goal on the livingTick method once the health had dropped, but it had no effect.
 

Edited by Cerandior
Link to comment
Share on other sites

I looked at the vanilla Skeleton entity and I got something to work, but I can't seem to make it shoot as fast as I want to.
Even if I set the attackCooldown to 0 there is still a significant pause between attacks.

This is what I tried: https://github.com/Cerandior/VanillaExtended/blob/master/src/main/java/teabx/vanillaextended/entities/SkeletonKing.java

 

Is there a way to make the guy shoot a little faster? Also, I am not sure if this is the most efficient way since I am adding a new goal to the entity every tick.

Thank you.

Link to comment
Share on other sites

2 hours ago, Cerandior said:

Also, I am not sure if this is the most efficient way since I am adding a new goal to the entity every tick.

Probably not the best option ya know.

2 hours ago, Cerandior said:

Is there a way to make the guy shoot a little faster?

Taking a little peaksie into RangedBowAttackGoal it seems to wait for the bow to be ready to fire just like how the player does you can see this on line 129-130. So your option is to either extend RangedBowAttackGoal/Goal(parent class) and implement your own cooldown of sorts. OR create your own bow for the skeleton to use that has it's own cooldown set to a lower value. I like this option because it gives a drop for the SkeletonKing to drop.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

16 hours ago, Animefan8888 said:

Probably not the best option ya know.

Taking a little peaksie into RangedBowAttackGoal it seems to wait for the bow to be ready to fire just like how the player does you can see this on line 129-130. So your option is to either extend RangedBowAttackGoal/Goal(parent class) and implement your own cooldown of sorts. OR create your own bow for the skeleton to use that has it's own cooldown set to a lower value. I like this option because it gives a drop for the SkeletonKing to drop.

Thank you for your answer.
I should have looked a little more before wasting other people's time (sorry).
I tried creating the custom bow and made my entity equip it in his main hand, but unfortunately the entity is no longer able to shoot arrows. I am almost certain it has to do with the goal.

I saw this piece of code:

public boolean shouldExecute() {
   return this.entity.getAttackTarget() == null ? false : this.isBowInMainhand();
}

 

And isBowInMainHand():

protected boolean isBowInMainhand() {
   net.minecraft.item.ItemStack main = this.entity.getHeldItemMainhand();
   net.minecraft.item.ItemStack off  = this.entity.getHeldItemOffhand();
   return main.getItem() instanceof BowItem || off.getItem() instanceof BowItem;
}

 

It is hard-coded to execute the goal only if the entity is carrying an instance of BowItem in his hand. However my custom bow does not extend BowItem because I wanted to add some custom behaviors to it.

Is my only option here to create my own EntityGoal extending RangedBowAttackGoal and overriding shouldExecute to work for my custom bow?

Thank you again.

Edited by Cerandior
Link to comment
Share on other sites

Ok, I did what I said above and it is working now.
I am also having trouble with something else. I tried to make the SkeletonKing a little bigger than the other skeletons.
I tried doing this using the scale variable in the render method of the Model class, and the model is indeed scaled correctly. But the entity size does not correspond to that of the model so his feet go below the ground.

I tried looking for something related to size or height and width, but I did not find anything. Is there a way to change my entity's bounding box?

Link to comment
Share on other sites

3 hours ago, Cerandior said:

However my custom bow does not extend BowItem because I wanted to add some custom behaviors to it.

Why not make it extend BowItem anyways? You can just override the methods and give it your own behavior. Then everyone will know it is a bow.

 

45 minutes ago, Cerandior said:

but I did not find anything. Is there a way to change my entity's bounding box?

Of course there is. You can change the boundingBox field in the entities class.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

21 minutes ago, Animefan8888 said:

Of course there is. You can change the boundingBox field in the entities class.

 

There is a setBoundingBox method with an AxisAllignedBB as a parameter.
I tried doing something with AxisAllignedBB.grow, but now when I spawn my entity in the world it immediately despawns.

Edited by Cerandior
Link to comment
Share on other sites

1 minute ago, Cerandior said:

immediately despawns.

Set through the code in the debugger.

 

2 minutes ago, Cerandior said:

AxisAllignedBB.grow

Try creating a new AxisAlignedBB

 

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

17 minutes ago, Animefan8888 said:

Try creating a new AxisAlignedBB

I tried it using getBoundingBox() and returning a new AxisAlignedBB, but it still despawns my entity.

 

    @Override
    public AxisAlignedBB getBoundingBox() {
        return new AxisAlignedBB(0.9, 2.985, 0.9, 0.9, 2.985, 0.9);
    }

 

Any idea why .setSize is no longer there in 1.14? It was convenient and it has been available in the past versions of forge.

 

EDIT:

Found this in MobEntity Class:

public boolean canSpawn(IWorld worldIn, SpawnReason spawnReasonIn) {
   return this.getBlockPathWeight(new BlockPos(this.posX, this.getBoundingBox().minY, this.posZ), worldIn) >= 0.0F;
}

It is probably blocking my entity for spawning because the bounding box is entering the block below (?). Can there be an offset applied for this?

Edited by Cerandior
Link to comment
Share on other sites

Ok, getting somewhere.

The bounding box can be changed by using getSize().scale

@Override
public EntitySize getSize(Pose poseIn) {
    return super.getSize(poseIn).scale(1.5F);
}

Checked in-game and the bounding box's size is correct, however my Entity's legs are still below ground. The entire model needs to be offset by my scaling amount in the Y direction. How can I do this?

Link to comment
Share on other sites

The closest thing that I have found about offset is:
 

@Override
public double getYOffset() { return super.getYOffset(); }

 

I am not quite sure what that does though, but it doesn't fix my problem. Tried several values but my entity still got his feet inside the ground.

 

EDIT: Solved by manually adding offset to each element of my model, wish there was another way to offset the whole thing in a certain direction but oh well.

Edited by Cerandior
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.