Jump to content

Recommended Posts

Posted

I want that u can change the texture of the block by doing right-click with another Block.

 

public class VariableBlock extends BlockContainer implements ITileEntityProvider
{
@SideOnly(Side.CLIENT)
    private IIcon topIcon;

public VariableBlock() 
{
	super(Material.ground);
	this.setCreativeTab(CreativeTabs.tabBlock);
}

@Override 
public boolean isOpaqueCube()
{
	return false;
}

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float f1, float f2, float f3)
    {
	ItemStack stack = player.getCurrentEquippedItem();

	if(stack != null && Block.getBlockFromItem(stack.getItem()) != null)
	{
		Block block = Block.getBlockFromItem(stack.getItem());

		topIcon = block.getIcon(1, 0);
		blockIcon = block.getIcon(3, 0);

                       return true;
	}

	return false;
    }

@Override
public TileEntity createNewTileEntity(World var1, int var2)
{
	return new TileEntityVariableBlock();
}

@SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int meta)
    {
        return side == 1 ? this.topIcon : (side == 0 ? this.topIcon : this.blockIcon);
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister ir)
    {
        this.blockIcon = ir.registerIcon("furnace_side");
        this.topIcon = ir.registerIcon("furnace_top");
    }
}

 

With this code i can change the texture, but all change the texutre, not only one.

 

Second problem: The grass is gray.

Posted

With metadata i can only have 4 (?) different textures in one world.

 

And one mistake by myself:

I mean: You can click with a cobble on one of this blocks, at another with a sandstone , ...

              And then they look like the block.

 

3. Problem after reload they have the first texture

Posted

I'm done so far, but 2 Problems:

 

1. Some Texture are wrong like gray grass and the different wood has always the oak texture

 

2. After a reload the textures are away

 

public class VariableBlock extends BlockContainer implements ITileEntityProvider
{

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float f1, float f2, float f3)
    {
	ItemStack stack = player.getCurrentEquippedItem();
	TileEntityVariableBlock te = (TileEntityVariableBlock) world.getTileEntity(x, y, z);

	if(stack != null && Block.getBlockFromItem(stack.getItem()) != null)
	{
		te.setIconStack(stack);
		return true;
	}

	return false;
    }

@Override
public TileEntity createNewTileEntity(World var1, int var2)
{
	return new TileEntityVariableBlock();
}

@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess ba, int x, int y, int z, int side)
    {
	TileEntityVariableBlock te = (TileEntityVariableBlock) ba.getTileEntity(x, y, z);

	return (te != null && te.getIcon(side) != null) ? te.getIcon(side) : this.blockIcon;
    }

 

public class TileEntityVariableBlock extends TileEntity
{	
private ItemStack iconStack;

public void setIconStack(ItemStack stack)
{
	iconStack = stack;
}

public IIcon getIcon(int side)
{
	return iconStack != null ? Block.getBlockFromItem(iconStack.getItem()).getIcon(side, 0) : null;
}

@Override
public void readFromNBT(NBTTagCompound nbt)
{
	super.readFromNBT(nbt);
	iconStack = ItemStack.loadItemStackFromNBT(nbt);
}

@Override
public void writeToNBT(NBTTagCompound nbt)
{
	super.writeToNBT(nbt);
	iconStack.writeToNBT(nbt);
}
}

 

public static Block VariableBlock= new VariableBlock().setBlockName("VariableBlock");

@EventHandler
private void FMLInit(FMLInitializationEvent event)
{
          GameRegistry.registerBlock(VariableBlock, "VariableBlock");
          GameRegistry.registerTileEntity(TileEntityVariableBlock.class, "TileEntityVariableBlock");
}

Posted

I add this but:

It doesn't work with the reload

 

@Override
public Packet getDescriptionPacket()
    {
	S35PacketUpdateTileEntity packet = (S35PacketUpdateTileEntity) super.getDescriptionPacket();
	NBTTagCompound tag = packet != null ? packet.func_148857_g() : new NBTTagCompound();

	addInfoToNBT(tag);

	return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
    }

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
    {
	super.onDataPacket(net, pkt);
        NBTTagCompound tag = pkt.func_148857_g();
        loadInfoFromNBT(tag);
    }

 private void addInfoToNBT(NBTTagCompound tag) 
 {
	 if(iconStack != null)
	 iconStack.writeToNBT(tag);
 }

 private void loadInfoFromNBT(NBTTagCompound tag) 
 {
	 iconStack = ItemStack.loadItemStackFromNBT(tag);
 }

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.