Jump to content

Recommended Posts

Posted

Hey there!

I made a block which should be rendered depending on a value in his TileEntity.

 

The problem is that it depends on default value from TileEntity's constructor. I checked and the value is properly saved and loaded.

 

Code from the block:

@SideOnly(Side.CLIENT)
public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5){
	return Block.blocksList[((TileEntityChainReactiveRock)par1IBlockAccess.getBlockTileEntity(par2, par3, par4)).textureID].getBlockTexture(par1IBlockAccess, par2, par3, par4, par5);
}

And from TileEntity:

 

package jantomedes.maptools.main;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityChainReactiveRock extends TileEntity{
int wait;
int textureID;
boolean spreadReaction;

//Entity entityToSpawn;
int idForBlock, metadataForBlock;
EnumChainReactionType type;

boolean shouldReactOnExp, shouldReactOnBreaking, 
shouldReactOnGettingPowered, shouldReactOnRightClick;

public TileEntityChainReactiveRock(){
	wait = 5;
	textureID = Block.oreLapis.blockID; //HERE, depending only on it
	type = EnumChainReactionType.breakBlock;
	idForBlock = Block.oreDiamond.blockID;
	metadataForBlock = 0;
	spreadReaction = true;
	shouldReactOnBreaking = true;
	shouldReactOnExp = true;
	shouldReactOnGettingPowered = true;
	shouldReactOnRightClick = false;
}

public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);
	this.wait = nbt.getInteger("wait");
	this.textureID = nbt.getInteger("texture id");
	this.spreadReaction = nbt.getBoolean("spreadReaction");

	this.type = EnumChainReactionType.breakBlock;
	if(nbt.getInteger("type") == 1){
		this.type = EnumChainReactionType.changeBlock;
	}if(nbt.getInteger("type") == 2){
		this.type = EnumChainReactionType.spawnFallingBlock;
	}

	this.idForBlock = nbt.getInteger("idForBlock");
	this.metadataForBlock = nbt.getInteger("metadataForBlock");

	/*if(nbt.getBoolean("notNullEntity")){
		entityToSpawn.readFromNBT(nbt);
	}*/

	this.shouldReactOnBreaking = nbt.getBoolean("shouldReactOnBreaking");
	this.shouldReactOnExp = nbt.getBoolean("shouldReactOnExp");
	this.shouldReactOnGettingPowered = nbt.getBoolean("shouldReactOnGettingPowered");
	this.shouldReactOnRightClick = nbt.getBoolean("shouldReactOnRightClick");
}

public void writeToNBT(NBTTagCompound nbt){
	super.writeToNBT(nbt);
	nbt.setInteger("wait", wait);
	nbt.setInteger("texture id", textureID);
	nbt.setBoolean("spreadReaction", spreadReaction);

	nbt.setInteger("type", 0);
	if(type==EnumChainReactionType.changeBlock){
		nbt.setInteger("type", 1);
	}if(type==EnumChainReactionType.spawnFallingBlock){
		nbt.setInteger("type", 2);
	}

	nbt.setInteger("idForBlock", idForBlock);
	nbt.setInteger("metadataForBlock", metadataForBlock);

	/*if(entityToSpawn!=null){
		entityToSpawn.writeToNBT(nbt);
		nbt.setBoolean("notNullEntity", true);
	}else{
		nbt.setBoolean("notNullEntity", false);
	}*/

	nbt.setBoolean("shouldReactOnBreaking", shouldReactOnBreaking);
	nbt.setBoolean("shouldReactOnExp", shouldReactOnExp);
	nbt.setBoolean("shouldReactOnGettingPowered", shouldReactOnGettingPowered);
	nbt.setBoolean("shouldReactOnRightClick", shouldReactOnRightClick);
}

public int getWait(){
	return this.wait;
}

public int getTextureID(){
	return this.textureID;
}

/*public void setToSpawnEntity(Entity e){
	this.type = EnumChainReactionType.spawnEntity;
	this.entityToSpawn = e;
}*/

public void setToChangeBlock(int id, int metadata){
	this.type = EnumChainReactionType.changeBlock;
	this.idForBlock = id;
	this.metadataForBlock = metadata;
}

public void setToFallingBlock(int id, int metadata){
	this.type = EnumChainReactionType.spawnFallingBlock;
	this.idForBlock = id;
	this.metadataForBlock = metadata;
}

}

 

 

I don't paste the whole code of block because there is so much of it and there is nothing about block's texture except what I pasted.

 

I think it could be something with IBlockAccess.

 

Regards. Jantomedes

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.