Jump to content

Recommended Posts

Posted

I really need to be able to make a simple pushable Entity.

Entity:

package com.eastonium.bionicle.kolhii;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import com.eastonium.bionicle.Bionicle;

public class EntityKolhiiBall extends Entity
{
public EntityKolhiiBall(World par1World) 
{
	super(par1World);
	this.isImmuneToFire = true;
	this.setSize(0.4F, 0.4F);
}

@Override
public AxisAlignedBB getCollisionBox(Entity par1Entity)
    {
        return par1Entity.boundingBox;
    }

    @Override
    public AxisAlignedBB getBoundingBox()
    {
        return this.boundingBox;
    }
    
    @Override
    public boolean canBePushed()
    {
        return true;
    }
    
    @Override
public void applyEntityCollision(Entity par1Entity)
{
	if (par1Entity.riddenByEntity != this && par1Entity.ridingEntity != this)
	{
		double d0 = par1Entity.posX - this.posX;
		double d1 = par1Entity.posZ - this.posZ;
		double d2 = MathHelper.abs_max(d0, d1);

		if (d2 >= 0.009999999776482582D)
		{
			d2 = (double)MathHelper.sqrt_double(d2);
			d0 /= d2;
			d1 /= d2;
			double d3 = 1.0D / d2;

			if (d3 > 1.0D)
			{
				d3 = 1.0D;
			}

			d0 *= d3;
			d1 *= d3;
			d0 *= 0.05000000074505806D;
			d1 *= 0.05000000074505806D;
			d0 *= (double)(1.0F - this.entityCollisionReduction);
			d1 *= (double)(1.0F - this.entityCollisionReduction);
			this.addVelocity(-1.4*par1Entity.motionX, 0.5D, -1.4*par1Entity.motionZ);
			//par1Entity.addVelocity(d0, 0.0D, d1);
		}
	}
}

@Override
public boolean attackEntityFrom(DamageSource par1DamageSource, float par2)
{
	if (this.isEntityInvulnerable())
	{
		return false;
	}
	else if (!this.worldObj.isRemote && !this.isDead)
	{
		this.setBeenAttacked();
		if (par1DamageSource.getEntity() instanceof EntityPlayer)
		{
			EntityPlayer player = (EntityPlayer)par1DamageSource.getEntity();
			if(!player.capabilities.isCreativeMode) this.func_145778_a(Bionicle.kolhiiBall, 1, 0.0F);
			this.setDead();
		}
		return true;
	}
	else
	{
		return true;
	}
}

    @Override
protected boolean canTriggerWalking()
{
	return false;
}

    @Override
public boolean canBeCollidedWith()
    {
        return !this.isDead;
    }

@Override
protected void entityInit() 
{}

@Override
protected void readEntityFromNBT(NBTTagCompound var1) 
{}

@Override
protected void writeEntityToNBT(NBTTagCompound var1)
{}
}

Posted

I can spawn it fine, and I can collide with it, but I can't push it.

 

Hmmm, it looks like you're doing most of the things that are required: setting can be pushed, can be collided, overriding the collision, etc.

 

I suggest that you add more debug console statements so you can trace the execution more closely.  For example, put a System.out.println() statement in the applyEntityCollision() method to confirm that that method is actually getting called.

 

Another thing is that while playing the game you can hit F3+B to show the bounding box for the entity.  This will help confirm where the bounding/collision box is because sometimes people create a model that isn't well aligned with the bounding box so they aren't actually colliding when they think they are.

 

Anyway, by putting some console messages in each of the critical parts of the code you will be able to track through your logic and should be able to find out what is going wrong.

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

Posted

So I did what you said and the only thing it fails to do is addVelocity(). I don't know what would be the problem.

 

What exactly do you mean?  Did you put a console message after this condition is tested?:

if (d2 >= 0.009999999776482582D)

 

Also, I'm not certain it is correct to multiply the motion by a negative number.  When something is pushed, doesn't it normally go in the same direction as the thing that pushed it?

 

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

Posted

Yes, I did test it after that if statement. I got the negative number from the EntityMinecart file, but I'll have to try it without the negative.

 

EDIT: still no luck with anything. oh, another thing, I can break the block from under it and it doesn't fall. :?

Posted

So what do the console messages tell you?  Basically, to debug something you need to trace every step to see if it is behaving as you expect.  For example, you can put a console message to print out the velocity before you modify it, an then again after you modify it.  Maybe you will notice an issue there.

 

For example, you're assuming that the player motionX and motionY are non-zero.  However it is possible (I'm not sure how the Minecraft code works) that if the player collides with the ball that the collision is processed by the player entity first and it might decide to stop (i.e. set motion to 0) and then by the time you add it it is already 0. 

 

You really need to check at that level of detail -- is the velocity really changing in that line of code?

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

Posted

so after some more testing, the player isn't moving when I print it out. So I deceided to just input numbers into the add Velocity, but strangely enough turned up not doing anything still. I wish i knew what was wrong :/

Posted

Well again usually in programming the problem is very specific mistake, like maybe you didn't call exactly the right method.  So you really need to check absolutely everything.  Like after you add velocity did the motion values change, and so forth.

 

If you're really stuck on this method, then I suggest you manage the movement yourself.  You can use your entity's update methods and move the entity how you want it.

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

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.