Jump to content

Recommended Posts

Posted

So, here's the code for my projectile and part of the cannon code that launches the projectile.

public class Shot_2 extends Entity{

public Shot_2(World par1World) {
	super(par1World);
	this.setSize(0.125F, 0.125F);
	this.entityCollisionReduction = 0.5F;
}

@Override
public void onUpdate(){
	this.onEntityUpdate();
}

@Override
public void onEntityUpdate(){
	this.prevDistanceWalkedModified = this.distanceWalkedModified;
	this.prevPosX = this.posX;
	this.prevPosY = this.posY;
	this.prevPosZ = this.posZ;
	this.prevRotationPitch = this.rotationPitch;
	this.prevRotationYaw = this.rotationYaw;
	this.motionX *= 0.95;
	this.motionY *= 0.95;
	this.motionZ *= 0.95;

	if(this.posY < -64.0D){
		this.kill();
	}
	this.addVelocity(0, -0.004D, 0);
	this.doBlockCollisions();
	int i = MathHelper.floor_double(posX);
	int j = MathHelper.floor_double(posY);
	int k = MathHelper.floor_double(posZ);

	if(worldObj.getBlockId(i, j, k) > 0){
		worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 4.0F, true);
	}

	this.posX += this.motionX;
	this.posY += this.motionY;
	this.posZ += this.motionZ;
	this.setPosition(this.posX, this.posY, this.posZ);
}

public boolean canBeRidden(){
	return false;
}

@Override
protected void playStepSound(int par1, int par2, int par3, int par4){
}

@Override
public AxisAlignedBB getCollisionBox(Entity par1Entity){
	if(par1Entity != riddenByEntity && par1Entity.ridingEntity != this){
		return this.boundingBox;
	}
	return null;
}

@Override
public AxisAlignedBB getBoundingBox(){
	return this.boundingBox;
}

@Override
public boolean canBeCollidedWith(){
	return false;
}

@Override
public boolean canBePushed(){
	return false;
}

@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound){
}

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

public void onEntityUpdate(){
	...
	if(shoot){
		if(shooting == 0){
			if(worldObj.isRemote){
				for(byte i = 0; i < 23; i++){
					muzzlePos.onUpdate();
					worldObj.spawnParticle("explode", muzzlePos.getX(), muzzlePos.getY(), muzzlePos.getZ(), 0, 0, 0);
				}
			}
			worldObj.playSoundAtEntity(this, "row:howitzer_shot", 1.0F, 1.0F);

			Shot_2 shot = new Shot_2(worldObj);
			shot.setLocationAndAngles(...);
			shot.addVelocity(...);
			worldObj.spawnEntityInWorld(shot);
		}

	}
}

The problem is next — blocks are destroyed only in client world. After I save/load, all damaged blocks are restored. Any ideas how to fix this?

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted

You are spawning the entity in the world client-side.

No, i'm spawning it in both sides. I only spawn effects on client.

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted

You are spawning the entity in the world client-side.

No, i'm spawning it in both sides. I only spawn effects on client.

That's the point: don't spawn it on the client, that happens automatically. Same for explosions and destroying blocks - only do that on the server side or you will encounter these "ghost" blocks. The client is updated automatically when blocks are destroyed.

Posted

Idk what was this caused by, but after i re-wrote the code in another way, the problem disappeared.

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

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.

×
×
  • Create New...

Important Information

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