Jump to content

Recommended Posts

Posted

My entity is not saved, lot loaded, or the controller variable doesn't get set correctly. Any ideas would help. (Not a rendering problem, console doesn't output anything when I start the world)

 

package com.DEBmods.modularships;

import net.minecraft.entity.DataWatcher;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;

public class EntityShipBlock extends Entity{
public EntityShipControl controller;
public int Xoff;
public int Yoff;
public int Zoff;
public String axisF;
public float rotationRoll;

public EntityShipBlock(World par1World) {
	super(par1World);
}

public boolean canBePushed()
    {
        return false;
    }

@Override
protected void entityInit() {
	DataWatcher dw = this.getDataWatcher();
	dw.addObject(4, 0);
	dw.addObject(5, 0);
	dw.addObject(6, 0);
	dw.addObject(7, "x");
	dw.addObject(8, this.rotationRoll);
	AxisAlignedBB.getBoundingBox(-0.5d, -0.5d, -0.5d, 0.5d, 0.5d, 0.5d);
}

@Override
protected void readEntityFromNBT(NBTTagCompound var1) {
	if (this.worldObj.isRemote == true) {
		super.readFromNBT(var1);
		this.Xoff = var1.getInteger("Xoff");
		this.Yoff = var1.getInteger("Yoff");
		this.Zoff = var1.getInteger("Zoff");
		this.axisF = var1.getString("axisF");
		this.rotationRoll = var1.getFloat("rotationRoll");

		if (this.worldObj.getEntityByID(var1.getInteger("controller")) instanceof EntityShipControl) {
			this.controller = (EntityShipControl) this.worldObj.getEntityByID(var1.getInteger("controller"));
		}
	}
}

@Override
protected void writeEntityToNBT(NBTTagCompound var1) {
	if (this.worldObj.isRemote == true) {
		super.writeToNBT(var1);
		var1.setInteger("Xoff", this.Xoff);
		var1.setInteger("Yoff", this.Yoff);
		var1.setInteger("Zoff", this.Zoff);
		var1.setString("axisF", this.axisF);
		var1.setFloat("rotationRoll", this.rotationRoll);
		var1.setInteger("controller", controller.getEntityId());
	}
}

//STUFF FOR onUpdate ONLY!!!
public void onUpdate() {
	//Updates variables from the DataWatcher
	DataWatcher dw = this.getDataWatcher();
	if (dw.getWatchableObjectInt(4) + dw.getWatchableObjectInt(5) + dw.getWatchableObjectInt(6) + dw.getWatchableObjectFloat( != 0) {
		this.Xoff = dw.getWatchableObjectInt(4);
		this.Yoff = dw.getWatchableObjectInt(5);
		this.Zoff = dw.getWatchableObjectInt(6);
		this.axisF = dw.getWatchableObjectString(7);
	}
	this.rotationRoll = dw.getWatchableObjectFloat(;

	//Updates rotation and position
	if (controller != null) {
		this.setPosition(controller.posX, controller.posY, controller.posZ);
	}

	System.out.println(this.posX + " " + this.posY + " " + this.posZ);

	//Updates the DataWatcher from variables
	if (this.Xoff + this.Yoff + this.Zoff != 0) {
		dw.updateObject(4, this.Xoff);
		dw.updateObject(5, this.Yoff);
		dw.updateObject(6, this.Zoff);
		dw.updateObject(7, this.axisF);
	}

	dw.updateObject(8, this.rotationRoll);
}
}

Posted

I'm getting:

[05:53:49] [server thread/INFO] [FML]: Applying holder lookups

[05:53:49] [server thread/INFO] [FML]: Holder lookups applied

on world save. I don't remember seeing it before.

Posted

I think it might be that they aren't saving properly, I'm spawning them with

 

if (world.isRemote == something) {

world.spawnEntityInWorld(shipcontrolentity);

}

 

which should I use to make sure it's on the server?

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.