david476 Posted June 20, 2014 Posted June 20, 2014 Is there a way to use Datawatchers in a Tile Entity, I think my variable might not be loaded clientside on world load. Quote
david476 Posted June 20, 2014 Author Posted June 20, 2014 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. Quote
david476 Posted June 20, 2014 Author Posted June 20, 2014 If it matters the variable could actually be anything but a float would lessen the amount of programming I have to do Quote
david476 Posted June 22, 2014 Author Posted June 22, 2014 How do I set it's NBT, there is a function that uses nbt but it does not have a proper name. Quote
david476 Posted June 22, 2014 Author Posted June 22, 2014 could someone refence me to a vanilla example of this, I can't figure out how to search through the forgesrc library. Quote
Kwibble Posted June 22, 2014 Posted June 22, 2014 I would assume that the furnace would be a good place to look for it. Oops.. Scratch that. The furnace doesn't use it. Quote We all stuff up sometimes... But I seem to be at the bottom of that pot.
david476 Posted June 25, 2014 Author Posted June 25, 2014 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) Quote
david476 Posted June 25, 2014 Author Posted June 25, 2014 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"); } } Quote
Alix_The_Alicorn Posted June 25, 2014 Posted June 25, 2014 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. Quote
brandon3055 Posted June 25, 2014 Posted June 25, 2014 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 Quote I am the author of Draconic Evolution
david476 Posted June 25, 2014 Author Posted June 25, 2014 Good call! (note, Brandon put tagCompound instead of nbttagcompound if anyone copies) Thank yous for EVERYONE!!!! Quote
brandon3055 Posted June 25, 2014 Posted June 25, 2014 oops i just copied that from one of my classes Quote I am the author of Draconic Evolution
Recommended Posts
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.