Jump to content

[1.8] Custom Throwable not moving


MCRaichu

Recommended Posts

Hi,

I created a rocket (Throwabel) with custom renderer and everthing works fine. But the rendered rocket stays where it is spawned. The server side rocket actually moves and explodes on impact but the client side doesn't. I used to debugger to check and for some reason the fields motionX,motionY,.motionZ are not set on the client side. Therefore it doesn't move. Any idea what I'm doing wrong.

 

Register Entity and Renderer:

int entityID = EntityRegistry.findGlobalUniqueEntityId();
EntityRegistry.registerModEntity(NodRocket.class, Reference.MODID+".NodRocket", entityID, mod , 64, 20, false);
RenderingRegistry.registerEntityRenderingHandler(NodRocket.class, new NodRocketRenderer(Minecraft.getMinecraft().getRenderManager()));

 

Spawning the rocket:

if(aimed){
		if(!this.worldObj.isRemote){
			NodRocket projectile = new NodRocket(this.getWorld(), false, target);
			//EntitySnowball projectile = new EntitySnowball(this.worldObj);
			projectile.setPosition(sourceVec.xCoord,sourceVec.yCoord,sourceVec.zCoord);
			Vec3 d0 = targetVec.subtract(sourceVec);
			projectile.setThrowableHeading(d0.xCoord,d0.yCoord,d0.zCoord,0.6f,0.00f);  


			this.worldObj.spawnEntityInWorld(projectile);
		}
             }

 

 

The Rocket class itself

 

 

public class NodRocket extends EntityThrowable {

private boolean isHoming;
private Entity target;
public boolean hit = false;
public float speed = 1.0F;
public int arrowShake;
private float gravity = 0.00F;
private float damage = 6.0f;
private double radius = 3.0;

public NodRocket(World worldIn) {
	super(worldIn);
	this.target = null;
	isHoming = false;
	initNodRocket();
}

public NodRocket(World worldIn, EntityLivingBase entity) {
	super(worldIn,entity);
	this.target = null;
	isHoming = false;
	initNodRocket();
}

public NodRocket(World worldIn, double par1, double par2, double par3) {
	super(worldIn,par1,par2,par3);
	this.target = null;
	isHoming = false;
	initNodRocket();
}

public NodRocket(World worldIn, boolean isHoming, Entity target) {
	super(worldIn);
	this.target = target;
	this.isHoming = isHoming;
	initNodRocket();
}

private void initNodRocket(){
	this.renderDistanceWeight = 10.0D;
}

@Override
public void onEntityUpdate() {

	super.onEntityUpdate();

	if (ticksExisted >= 100) {
		this.setDead();
	}
	if (!worldObj.isRemote) {
		if (isHoming && target != null) {
			double d0 = target.posX - this.posX;
			double d1 = target.posY + (double) target.getEyeHeight() - this.posY;
			double d2 = target.posZ - this.posZ;

			this.setThrowableHeading(d0, d1, d2, speed, 0.0F);
			speed = speed + 0.06F;
		} else if (isHoming && target == null) {
			this.setDead();
		}
	}
}


@Override
protected void onImpact(MovingObjectPosition movingobjectposition) {
	if (this.ticksExisted <= 5) {
		return;
	}
	if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
		Block hitBlock = worldObj.getBlockState(movingobjectposition.getBlockPos()).getBlock();
		if (hitBlock != null && !hitBlock.getMaterial().isSolid() || worldObj.isAirBlock(movingobjectposition.getBlockPos())) {
			// Go through non solid block
			return;
		}
	}
	if (!worldObj.isRemote) {
		worldObj.createExplosion(null, posX, posY, posZ, 0.1F, true);
		AxisAlignedBB bb = AxisAlignedBB.fromBounds(this.posX, this.posY,this.posZ, this.posX + 1, this.posY + 1, this.posZ + 1);
		AxisAlignedBB axis = bb.expand(radius, radius, radius);
		List<EntityMob> targets = worldObj.getEntitiesWithinAABB(EntityMob.class, axis);

		for (EntityMob mob : targets) {
			mob.attackEntityFrom(new DamageSource("rocket"), damage);
			mob.hurtResistantTime = 0;
		}
	}
	this.setDead();
}

@Override
protected float getGravityVelocity() {
	return this.gravity;
}

    @Override
    public void onUpdate() {
    	super.onUpdate();
    	System.out.println("Motion: " + this.motionX + "," + this.motionY + "," + this.motionZ + ".");
    }
    
}

 

It doesn't work, I don't know why.

It works, I don't know why.

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.