Posted May 23, 201510 yr 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? http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
May 23, 201510 yr Code would be nice, like the method you use to spawn the entity. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
May 23, 201510 yr Author 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]; } } http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
May 23, 201510 yr You have to set the position before you spawn it. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
May 23, 201510 yr Author Yes, this worked! Although I don't really understand why... http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
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.