Jump to content

(MC 1.4.2) Custom Top-Slab not showing correctly


Recommended Posts

Posted

Hello All,

 

I am currently making a mod which adds a couple of new blocks with nice textures to Minecraft, and everything was pretty easy to do until I added halfslabs for the custom Blocks.

 

The slabs show correctly in their "normal" bottom position and as double-slabs aswell, however when I place a top-slab the texture does not show.

 

Here is a screenshot:

topslab.png

 

 

Here is the code of the slab class:

 

public class BlockConcreteSlab extends BlockHalfSlab  {

public BlockConcreteSlab(int par1, boolean slabtype)
    {
        super(par1, slabtype, Material.rock);
        this.setCreativeTab(CreativeTabs.tabBlock);
        this.setRequiresSelfNotify();//MultiBlock
        this.setLightOpacity(0);//Fixes most of the Halfslab lightning bugs
        
    }

/*
 * The path to the texture file set as a string in CommonProxy
 */

public String getTextureFile(){
	return CommonProxyMoreBlockz.TexturesPNG;
}

/*
 * The Texture of the Metadata Block starts at 0 and goes up to the value of the current Metadata
 */

public int getBlockTextureFromSideAndMetadata(int side, int metadata) {
	return 0 + metadata;
}


/**
* Returns the ID of the items to drop on destruction.
*/
public int idDropped(int par1, Random par2Random, int par3)
{
return MoreBlockz.blockconcretesingleslab.blockID;
}

/*
 * Drops the right metadata
 */

public int damageDropped(int metadata)
    {
        return metadata;
    }

/*
 * Makes HalfSlabs DoubleSlabs if they have the same BlockID and Metadata as the one you try to place down.
 */

public void onBlockPlacedBy(World par1World, int x, int y, int z, EntityLiving par5EntityLiving){

	if(par1World.getBlockId(x, y - 1, z) == MoreBlockz.blockconcretesingleslab.blockID){

		int metadata = par1World.getBlockMetadata(x, y, z) & 7;

		if(par1World.getBlockMetadata(x, y-1, z) == metadata ){

			par1World.setBlockWithNotify(x, y, z, 0);	//sets the block below to 0
			par1World.setBlockAndMetadataWithNotify(x, y - 1, z, MoreBlockz.blockconcretedoubleslab.blockID, metadata);
				//makes the slab a double-slab of the same metadata type
		} 
	}		

}


/**
* Returns an item stack containing a single instance of the current block type. 'par1' is the block's subtype/damage
* and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
*/
protected ItemStack createStackedBlock(int par1)
{
return new ItemStack(MoreBlockz.blockconcretesingleslab.blockID, 2, par1 & 7);
}

/*
 * Needs to be there because of BlockHalfSlab.class, is not used
 */
@Override
public String getFullSlabName(int var1) {
	// TODO Auto-generated method stub
	return null;
}



@SideOnly(Side.CLIENT)

    /**
     * Takes a block ID, returns true if it's the same as the ID for a stone or wooden single slab.
     */
    private static boolean isBlockSingleSlab(int par0)
    {
        return par0 == MoreBlockz.blockconcretesingleslab.blockID;
    }




/*
 * Single Slabs are shown in creative, but not double ones
 */
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) {
 	if (par1 != MoreBlockz.blockconcretedoubleslab.blockID){
 		for (int var4=0; var4<8;++var4) { //change number after 4< for more metadata blocks
 			par3List.add(new ItemStack(par1, 1, var4));
 		}
 	}
}




}

 

 

 

It's probably a pretty simple fix, but I can't figure it out.

 

Thanks,

Max

 

Posted

The problem I see is the metadata-based texture:

public int getBlockTextureFromSideAndMetadata(int side, int metadata) {
return 0 + metadata;
}

 

Because the position of the half slap (lower / upper half) is also stored in metadata. Look how the original half slab code does things and try to adapt it.

 

 

EDIT: try this method:

public int getBlockTextureFromSideAndMetadata(int side, int metadata) {
return 0 + (metadata & 7);
}

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

The problem I see is the metadata-based texture:

public int getBlockTextureFromSideAndMetadata(int side, int metadata) {
return 0 + metadata;
}

 

Because the position of the half slap (lower / upper half) is also stored in metadata. Look how the original half slab code does things and try to adapt it.

 

 

EDIT: try this method:

public int getBlockTextureFromSideAndMetadata(int side, int metadata) {
return 0 + (metadata & 7);
}

 

 

THANK YOU, that fixed the problem!  ;D

And it makes perfect sense, too  :-[

Thank you so much again  :)

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.