Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Is there a way to use Datawatchers in a Tile Entity, I think my variable might not be loaded clientside on world load.

  • 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.

  • Author

If it matters the variable could actually be anything but a float would lessen the amount of programming I have to do

  • Author

could someone refence me to a vanilla example of this, I can't figure out how to search through the forgesrc library.

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.

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

  • 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");
}
}

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.

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

  • Author

Good call! (note, Brandon put tagCompound instead of nbttagcompound if anyone copies) Thank yous for EVERYONE!!!!

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.