Jump to content

Recommended Posts

Posted

Hello everyone!

 

I want to create a beam consisting out of several entities in a row. But, for some reason I don't understand, the first entity of the row is moved to 0:0:0 after some time, but only on client side! I debugged a bit and found out that a packet of the class S15PacketEntityRelMove is received and moves the entity to 0:0:0. A bit weird is, that after some time the original position is restored, but the entity still isn't rendered.

The entity's position is never set to 0 from server side. It is even set to the owner's position every tick (which is not 0:0:0!).

 

Any ideas how this could happen? And how I can fix it?

 

Is it a problem that the entity is inside it's owner?

Posted

OK:

 

Spawn:

this.controlledEntity = new EntityMagicBeam(this.getWorld(), this);
this.controlledEntity.setMainMagic(MAX_BEAM_LENGTH, ElementUtil.getMainElement(Arrays.asList(this.getMagicData().getElements())));
this.getWorld().spawnEntityInWorld(this.controlledEntity);

 

Every tick after this:

this.controlledEntity.setBeamDirection(this.getEntity().getLookVec());
this.controlledEntity.setPosition(this.getEntity().posX, this.getEntity().posY + this.getEntity().getEyeHeight() - 0.25, this.getEntity().posZ);
this.getEntity().addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5));

if (this.callCount >= MAX_BEAM_TIME)
this.controlledEntity.setDead();

(this.getEntity() returns the owner here)

 

Entity class itself:

 

public class EntityMagicBeam extends Entity implements IMagicTransmitter, IEntityAdditionalSpawnData {

protected TaskGeneratedBeam controllingTask;
protected boolean isMainMagicEntity;
protected int childNumber;
protected int maxChildCount;
protected EntityMagicBeam child;
protected EntityMagicBeam parent;
protected Vec3 beamDirection;
protected Element mainElement;

public EntityMagicBeam(World worldIn) {
	super(worldIn);
	this.setSize(0.75f, 0.75f);
}

public EntityMagicBeam(World worldIn, TaskGeneratedBeam task) {
	this(worldIn);
	this.controllingTask = task;
}

public void setMainMagic(int maxChildCount, Element mainElement) {
	this.isMainMagicEntity = true;
	this.childNumber = 0;
	this.maxChildCount = maxChildCount;
	this.parent = null;
	this.mainElement = mainElement;
}

public void setBeamDirection(Vec3 direction) {
	this.beamDirection = direction;
	this.dataWatcher.updateObject(20, new Rotations((float) direction.xCoord, (float) direction.yCoord, (float) direction.zCoord));
}

@Override
public void onUpdate() {
	super.onUpdate();
	if (!this.worldObj.isRemote) {
		if (!this.isMainMagicEntity && (this.parent == null || this.parent.isDead)) {
			this.setDead();
			return;
		}
		if (!this.isDead && this.childNumber < this.maxChildCount && (this.child == null || this.child.isDead)) {
			this.child = new EntityMagicBeam(this.worldObj, this.controllingTask);
			this.child.childNumber = this.childNumber + 1;
			this.child.maxChildCount = this.maxChildCount;
			this.child.mainElement = this.mainElement;
			this.child.parent = this;
			this.updateChildPosition();
			this.dataWatcher.updateObject(21, new Integer(this.child.getEntityId()));
			this.worldObj.spawnEntityInWorld(this.child);
		}
	}
	if (this.isBurning())
		this.extinguish();

	if (this.child != null && !this.worldObj.isRemote) {
		this.updateChildPosition();
	} else if (this.worldObj.isRemote) {
		this.child = (EntityMagicBeam) this.worldObj.getEntityByID(this.dataWatcher.getWatchableObjectInt(21));
	}

	if (this.worldObj.isRemote) {
		Rotations r = this.dataWatcher.getWatchableObjectRotations(20);
		this.beamDirection = new Vec3(r.getX(), r.getY(), r.getZ());
	}

	Log.info_("I'm here (%s) at %s,%s,%s", this.getEntityId(), this.posX, this.posY, this.posZ);
}

protected void updateChildPosition() {
	if (this.beamDirection != null) {
		if (!this.worldObj.isRemote)
			this.child.setBeamDirection(this.beamDirection);
		this.child.setPosition(this.posX + this.beamDirection.xCoord * 0.5, this.posY + this.beamDirection.yCoord * 0.5, this.posZ + this.beamDirection.zCoord * 0.5);
	}
}

@Override
public void setDead() {
	super.setDead();
	if (this.child != null)
		this.child.setDead();
}

@Override
public MagicData getMagicData() {
	return this.controllingTask.getMagicData();
}

@Override
public EntityLivingBase getOwner() {
	return this.controllingTask.getEntity();
}

@Override
public void abortMagic() {
	this.controllingTask.abort();
}

public Vec3 getBeamDirection() {
	return this.beamDirection;
}

public Element getMainElement() {
	return this.mainElement;
}

@Override
public boolean writeToNBTOptional(NBTTagCompound tagCompund) {
	return false;
}

@Override
protected void readEntityFromNBT(NBTTagCompound tagCompund) {
}

@Override
protected void writeEntityToNBT(NBTTagCompound tagCompound) {
}

@Override
protected void entityInit() {
	this.dataWatcher.addObject(20, new Rotations(0, 0, 0));
	this.dataWatcher.addObject(21, new Integer(0));
}

@Override
public void writeSpawnData(ByteBuf buffer) {
	buffer.writeByte(this.mainElement.getID());
}

@Override
public void readSpawnData(ByteBuf buffer) {
	byte b = buffer.readByte();
	if (b < 16 && b > 0)
		this.mainElement = Element.values()[b];
}
}

 

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.