Jump to content

Making Entity Un-Pushable


Asweez

Recommended Posts

I want my entity to stay where it is no matter what collides with it or anything (besides gravity and moving by itself), however, setting #canBePushed to false doesn't do anything. How do I do this?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

Well it's not really that hard to accomplish, just override all methods containing collide and or push.

 

Any how, here is the fix:

 

// if your entity is an instance of entityliving, you can disable leashing as well.
@Override
public boolean allowLeashing() {
	return false;
}

// I think this is used when the player has attacked this entity, could be wrong.
@Override
public void onCollideWithPlayer(EntityPlayer entityIn) {}

// this actually allows for damaging the entity, when it get hit it knocks the entity back, 
// if you'd want to prevent that you have to override EnitityLivingBase#knockBack.
@Override
public boolean canBeCollidedWith() {
	return false;
}

// obviously we dont want this
@Override
public boolean canBePushed() {
	return false; 
}

// not any entity can collide. if you want projectiles to still be
// effective, you will have to handle those yourself
@Override
protected void collideWithEntity(Entity p_82167_1_) {}

// checks for any entity within a certain boundingbox, eg minecarts
@Override
protected void collideWithNearbyEntities() {}

Link to comment
Share on other sites

I have tried that, however that makes it so anything can walk through it. I want it to be solid so nothing can go through it and it won't move.

 

Nowhere in your thread have you asked for the above, anyway, entities derived from EntityLivingBase can be walked through. By looking at the boats class you can see you can't walk through a boat, rather you walk on top of it like a halfslab. Some collision method(s) in the Entity class does not allow another entity to walk through it, I don't have time to search for it right now, maybe when I get back and remember it I can update this post. But I'd suggest to look into anything related to colliding in the Entity class or better, check what methods are overriden in the EntityLivingBase class containing something relevant to colliding.

 

If you have not found anything, you could do something dirty using the collideWithNearByEntities method. Check for entities in your entity's AABB, if that entity is inside of the AABB 'teleport' it back 1 position in the entity's current position. Something like this could create a jittery effect when the player keeps colliding with your entity, but that's like I said a dirty solution.

Link to comment
Share on other sites

I also think that the collideWithEntity() method might be able to be used (also with canBeCollidedWith returning true) to adjust the position and keep it fixed and bounce the entity back. You could probably copy the code for how an entity collides with a block.

 

Another, different approach might be to create an invisible block at the same location.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I also think that the collideWithEntity() method might be able to be used (also with canBeCollidedWith returning true) to adjust the position and keep it fixed and bounce the entity back. You could probably copy the code for how an entity collides with a block.

 

Another, different approach might be to create an invisible block at the same location.

 

Yes I looked at that, however when the entity that collides with mine runs collideWithEntity(), that entity pushes back both itself and whatever it collided with. So even if I don't push my entity back, the other entity will.

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

Does the entity have to move (by itself)? If not, then maybe a TileEntity is a better approach.

 

Otherwise, you need to look at vanilla entities that resist pushing. Maybe minecart would be interesting. It looks like the applyEntityCollisions() is the method you need to look at.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.