Jump to content

How do i get the bigger entity boundingbox to work?


Drachenbauer

Recommended Posts

Hello

I have a problem with my inflateble entity:

With a method, that i found a the enderdragon, imade him bounce me away in the moment of inflating.

But if he is inflated, i can glitch through him...

If i press F3+B i see his bigger bounding-box, if he is inflated.

 

Here is my actual code for this behavior::

    @Override
    public void livingTick()
    {
        if (timeUntilDeflating > 0)
        {
            timeUntilDeflating--;
            
            if (timeUntilDeflating == 0)
            {
                isInflated = false;
                AxisAlignedBB aabb = this.getBoundingBox();
                this.setBoundingBox(new AxisAlignedBB(aabb.minX + 0.5d, aabb.minY, aabb.minZ + 0.5d, aabb.maxX - 0.5d, aabb.maxY - 1.0d, aabb.maxZ - 0.5d));
            }
        }
        else
        {
            super.livingTick();
        }
    }
    
    @Override
    public void onCollideWithPlayer(PlayerEntity entityIn)
    {
        if (timeUntilDeflating == 0)
        {
            timeUntilDeflating = 80;
            isInflated = true;
            AxisAlignedBB aabb = this.getBoundingBox();
            this.setBoundingBox(new AxisAlignedBB(aabb.minX - 0.5d, aabb.minY, aabb.minZ - 0.5d, aabb.maxX + 0.5d, aabb.maxY + 1.0d, aabb.maxZ + 0.5d));
            this.collideWithEntities(this.world.getEntitiesInAABBexcluding(this, this.getBoundingBox().grow(0.5D, 0.5D, 0.5D).offset(0.0D, 0.0D, 0.0D), null));
        }
    }
    
    private void collideWithEntities(List<Entity> entities)
    {
        double d0 = (getBoundingBox().minX + getBoundingBox().maxX) / 2.0D;
        double d1 = (getBoundingBox().minZ + getBoundingBox().maxZ) / 2.0D;
        
        for(Entity entity : entities)
        {
            if (entity instanceof LivingEntity)
            {
                double d2 = entity.getPosX() - d0;
                double d3 = entity.getPosZ() - d1;
                double d4 = d2 * d2 + d3 * d3;
                entity.addVelocity(d2 / d4 * 4.0D, (double)0.2F, d3 / d4 * 4.0D);
            }
        }
    }
}

My idea now is, tha something in super.livingTicks makes the boundingbox work.

How can i make him stay in his actual position and rotation, while inflates, but without stopping to use super.livingTicks?

 

Another question:

How nust i modify the last calculation here, that i bounce less far away from him (about the half distance is enough)?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

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