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

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

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.