Posted June 20, 201411 yr Is there a way to use Datawatchers in a Tile Entity, I think my variable might not be loaded clientside on world load.
June 20, 201411 yr Author just a float, it gets set after Tile Entity creation and should stay the same until the Tile Entity is deleted. The variable does get set client side on creation but not on world load.
June 20, 201411 yr Author If it matters the variable could actually be anything but a float would lessen the amount of programming I have to do
June 22, 201411 yr Author How do I set it's NBT, there is a function that uses nbt but it does not have a proper name.
June 22, 201411 yr Author could someone refence me to a vanilla example of this, I can't figure out how to search through the forgesrc library.
June 22, 201411 yr I would assume that the furnace would be a good place to look for it. Oops.. Scratch that. The furnace doesn't use it. We all stuff up sometimes... But I seem to be at the bottom of that pot.
June 25, 201411 yr Author 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)
June 25, 201411 yr Author 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"); } }
June 25, 201411 yr notice how you have fancy pants writeToNbt and readFromNbt methods. You supply them a tag compound and they will write data to the compound, or take the data and read it. Use them.
June 25, 201411 yr 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
June 25, 201411 yr Author Good call! (note, Brandon put tagCompound instead of nbttagcompound if anyone copies) Thank yous for EVERYONE!!!!
June 25, 201411 yr oops i just copied that from one of my classes I am the author of Draconic Evolution
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.