Jump to content

TileEntity Datawatchers


david476

Recommended Posts

how do I pass or receive the nbttagcompound? so far I have:

 

public class TileEntityController extends TileEntity {
public float rotation;

@Override
public void writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
	nbt.setFloat("rotation", rotation);
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	rotation = nbt.getFloat("rotation");
}

@Override
public Packet getDescriptionPacket() {
	new NBTTagCompound().setFloat("rotation", rotation);
        return new S35PacketUpdateTileEntity();
    }

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {

}
}

 

(sorry, new to all this)

Link to comment
Share on other sites

Ok, figured it out! I was trying to use a method named the same thing but with different parameters. Finished code for people with the same problem:

 

package com.deb.debmodularships.tileentities;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class TileEntityController extends TileEntity {
public float rotation;

@Override
public void writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
	nbt.setFloat("rotation", rotation);
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	rotation = nbt.getFloat("rotation");
}

@Override
public Packet getDescriptionPacket() {
	NBTTagCompound nbttagcompound = new NBTTagCompound();
	nbttagcompound.setFloat("rotation", rotation);
        return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbttagcompound);
    }

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
	rotation = pkt.func_148857_g().getFloat("rotation");
}
}

Link to comment
Share on other sites

As Alix said you already have methods to read and write your nbt data so just change what you have to

package com.deb.debmodularships.tileentities;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class TileEntityController extends TileEntity {
public float rotation;

@Override
public void writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);
	nbt.setFloat("rotation", rotation);
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);
	rotation = nbt.getFloat("rotation");
}

@Override
public Packet getDescriptionPacket() {
	NBTTagCompound nbttagcompound = new NBTTagCompound();
	writeToNBT(nbttagcompound);
        return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbttagcompound);
    }

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
	readFromNBT(pkt.func_148857_g());
}
}

 

Edit: Fixed typo

 

I am the author of Draconic Evolution

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.