Jump to content

Saving entity problems


Recommended Posts

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) {

public boolean canBePushed()
        return false;

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);

protected void readEntityFromNBT(NBTTagCompound var1) {
	if (this.worldObj.isRemote == true) {
		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"));

protected void writeEntityToNBT(NBTTagCompound var1) {
	if (this.worldObj.isRemote == true) {
		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);

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.

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.