Jump to content

[1.6.4] Spawned entity not running onUpdate


lexwebb

Recommended Posts

So, I'm trying to use a custom entity to render lasers, i have entity variable syncing working using the datawatcher and my client seems receiving the necessary coordinates for its laser rendering, however my onUpdate never gets called for this entity, so none of my code ever gets hit. What am i doing wrong?

 

Entity is spawned from inside a TileEntity (My Laser)

if (!worldObj.isRemote){
laserBeam();
}

public void laserBeam(){

if(laserToList != null && laserToList.size() > 1){
	for(int j = 0; j < laserToList.size() - 1; j++){
		ForgeDirection or = laserToDirection.get(j);			

		System.out.println("spawningLaser");
		EntityBeam beam = new EntityBeam(worldObj, laserToList.get(0), laserToList.get(1));
		worldObj.spawnEntityInWorld(beam);
                	beam.updateDataServer();
                
                	laserToList.clear();
	}
}
}

 

The Entity

package opticraft.entitys;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.List;

import cpw.mods.fml.common.network.PacketDispatcher;
import opticraft.lib.ModInfo;
import opticraft.lib.Position;
import net.minecraft.entity.DataWatcher;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class EntityBeam extends Entity {

public List<Position> laserToList;
public World world;
public Position start, end;
private DataWatcher dw;

public EntityBeam(World par1World) {
	super(par1World);
	this.world = par1World;
}

public EntityBeam(World par1World, Position start, Position end) {
	super(par1World);
	this.start = start;
	this.end = end;

	this.dw = this.getDataWatcher();
	this.dw.addObject(8, 0);
	this.dw.addObject(9, 0);
	this.dw.addObject(10, 0);
	this.dw.addObject(11, 0);
	this.dw.addObject(12, 0);
	this.dw.addObject(13, 0);

	System.out.println("EntityBeamInitialised, start: " + start.toString() + " - " + end.toString());
}

@Override
public void onUpdate() {

	if (!worldObj.isRemote) {
		updateDataServer();
		System.out.println("UpdatedServer");
	}

	if (worldObj.isRemote) {
		updateDataClient();
		System.out.println("UpdatedClient");
	}

	if (this.ticksExisted > 5) {
		this.setDead();
	}

	boundingBox.minX = Math.min(start.x, end.x);
        	boundingBox.minY = Math.min(start.y, end.y);
    	    	boundingBox.minZ = Math.min(start.z, end.z);

   	  	boundingBox.maxX = Math.max(start.x, end.x);
    		boundingBox.maxY = Math.max(start.y, end.y);
        	boundingBox.maxZ = Math.max(start.z, end.z);

        	boundingBox.minX--;
        	boundingBox.minY--;
        	boundingBox.minZ--;

        	boundingBox.maxX++;
       	 	boundingBox.maxY++;
        	boundingBox.maxZ++;

        	super.onUpdate();
}

@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
	// TODO Auto-generated method stub

}

@Override
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
	// TODO Auto-generated method stub

}

protected void updateDataClient() {
	start.x = decodeDouble(dw.getWatchableObjectInt();
	start.y = decodeDouble(dw.getWatchableObjectInt(9));
	start.z = decodeDouble(dw.getWatchableObjectInt(10));
	end.x = decodeDouble(dw.getWatchableObjectInt(11));
	end.y = decodeDouble(dw.getWatchableObjectInt(12));
	end.z = decodeDouble(dw.getWatchableObjectInt(13));
}

protected void updateDataServer() {
	if (!worldObj.isRemote) {
		System.out.println("lolwut");
	}
	dw.updateObject(8, Integer.valueOf(encodeDouble(start.x)));
	dw.updateObject(9, Integer.valueOf(encodeDouble(start.y)));
	dw.updateObject(10, Integer.valueOf(encodeDouble(start.z)));
	dw.updateObject(11, Integer.valueOf(encodeDouble(end.x)));
	dw.updateObject(12, Integer.valueOf(encodeDouble(end.y)));
	dw.updateObject(13, Integer.valueOf(encodeDouble(end.z)));
}

protected int encodeDouble(double d) {
	return (int) (d * 8192);
}

protected double decodeDouble(int i) {
	return (i / 8192D);
}

@Override
protected void entityInit() {
	// TODO Auto-generated method stub

}

}

 

Main Mod Class

EntityRegistry.registerModEntity(EntityBeam.class, "EntityBeam", 23, this, 128, 1, false);

 

If there's any more code you need to see you can find it on my GitHub https://github.com/lexwebb/opticraft

 

 

Link to comment
Share on other sites

@diesieben07 When i tried using the inherited datawatcher i was getting NULL pointer exceptions thrown on the very first line i tried to use it. When debugging, i found that nothing was NULL, so i had no idea what was going on. I then decided to implement the datawatcher how i found in a tutorial which seemed to resolve the errors. I'll have a closer look at it.

 

Even still, the fact the the datawatcher may not work does not explain the fact that my entity does never update.

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.