Jump to content

[1.7.10] Change Stored Tile Entity Values on Right-Click


Recommended Posts

Hey there,


I am trying to do something very simply but am of course failing somewhat.


I want a block which, when placed, stored a double in the new TileEntity which is the angle at which the block was placed (using rotationYaw), and sets a boolean in the new TE to be true.


Then, when the block is subsequently right clicked, I want it to take the angle previously stored and the angle it was right-clicked at, and put them into a function, and get a new boolean. This new boolean is then stored in the TE, and the old angle stored is replaced by the new angle at which the block was clicked.


These are my current Block and TE classes:

public class BlockSimpleQuantum extends BlockContainer {

public BlockSimpleQuantum(boolean s) {
	spin = s;

public final boolean spin;

public TileEntity createNewTileEntity(World world, int par1) {
	return new TileEntitySimpleQuantum();

protected IIcon blockIcon;

public void registerBlockIcons(IIconRegister i) {
	blockIcon = i.registerIcon("nr:" + this.getUnlocalizedName().substring(5) + (this.spin ? "Up" : "Down"));

public IIcon getIcon(int p_149691_1_, int p_149691_2_) {
	return blockIcon;

public static void set(boolean s, World worldObj, int xCoord, int yCoord, int zCoord) {
	if(s) worldObj.setBlock(xCoord, yCoord, zCoord, NRBlocks.simpleQuantumUp);
	else worldObj.setBlock(xCoord, yCoord, zCoord, NRBlocks.simpleQuantumDown);

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
	if (!player.isSneaking()) {
		TileEntitySimpleQuantum t = (TileEntitySimpleQuantum) world.getTileEntity(x, y, z);
		if ((player != null) && (!world.isRemote)) {
			double newAngle = (double) player.rotationYaw;
			double p = Math.pow(Math.cos(((t.angle-newAngle)/2)*(Math.PI/180)), 2);
			double rand = new Random().nextDouble();

			if (p == 0) t.spin=false;
			else if (p >= rand) t.spin=true;
			else if (p < rand) t.spin=false;

			t.angle = newAngle;
		if (world.isRemote) player.addChatMessage(new ChatComponentText(EnumChatFormatting.WHITE + (t.angle + " " + t.spin)));
	return true;

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack itemstack) {
	double l = (double) entityLivingBase.rotationYaw;
	TileEntitySimpleQuantum t = (TileEntitySimpleQuantum) world.getTileEntity(x, y, z);
	t.angle = l;

	if (world.isRemote) ((ICommandSender) entityLivingBase).addChatMessage(new ChatComponentText(EnumChatFormatting.WHITE + (t.angle + " " + t.spin)));

public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess world, int x, int y, int z) {
	return false;

public class TileEntitySimpleQuantum extends TileEntity {

public double angle = 0;
public boolean spin = true;
public boolean spin1 = true;

public TileEntitySimpleQuantum() {

public void updateEntity() {
    	if (spin != spin1) {
    		spin1 = spin;
    		BlockSimpleQuantum.set(spin, this.worldObj, this.xCoord, this.yCoord, this.zCoord);

public void readFromNBT(NBTTagCompound nbt) {

 	this.angle = nbt.getDouble("angle");
  	this.spin = nbt.getBoolean("spin");
  	this.spin1 = nbt.getBoolean("spin1");

public void writeToNBT(NBTTagCompound nbt) {

  	nbt.setDouble("angle", this.angle);
 	nbt.setBoolean("spin", this.spin);
 	nbt.setBoolean("spin1", this.spin1);


Thanks for any help in advance ;)

Link to comment
Share on other sites

Wow, forgot a whole paragraph...


This is what happens in-game:

I place the block down and the correct angle and boolean values are read out.

However, the subsequent right-clicks are not working as intended.

If I right click, and the new boolean is printed in the chat to still be true, the angle printed to the chat does not change from the original, and the block's texture is still the 'true' one.

If the new boolean is false, then the angle goes to 0.0 in the chat, the block texture changes to the 'false' one, and clicks after that always print '0.0, true' to the chat, while the texture doesn't update correctly.

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.