Jump to content

Slabs placement issues


SirOsirian

Recommended Posts

Hello, i'm trying to make 16 slabs using metadata, they work fine up to the 8th, after that i get a problem on placement, when i click to place it on the ground it places the top slab and then if i try to complete it by putting another slab under it it won't work, but if i put it on the top of the upper slab it'll turn into a double slab. Also having problems with the dropped item, again, up to 8th metadata block it works just fine but then it goes back to the start (0-7 meta drops 0-7 meta 8-15 meta drops 0-7 meta).

 

Code:

Recipes, registry and etc:

 

coloredStoneSlab = new coloredStoneSlab(coloredStoneSlabID, false).setCreativeTab(bExpansion.bExpansionTab)

        .setHardness(2.0F).setStepSound(Block.soundStoneFootstep);

        coloredStoneDoubleSlab = new coloredStoneSlab(coloredStoneDoubleSlabID, true).setCreativeTab(bExpansion.bExpansionTab)

        .setHardness(2.0F).setStepSound(Block.soundStoneFootstep);

 

GameRegistry.registerBlock(coloredStoneSlab, coloredItemStoneSlab.class);

        for (int iy = 0; iy<16 ; iy++){

        ItemStack coloredStoneSlabStack = new ItemStack(bExpansion.coloredStoneSlab, 6, iy);

        ItemStack singleColoredStoneSlabStack = new ItemStack(bExpansion.coloredStoneSlab, 1, iy);

        ItemStack dyeStack = new ItemStack(Item.dyePowder, 1, 15-iy);

        ItemStack coloredStoneStack = new ItemStack(bExpansion.coloredStone, 1, iy);

        ItemStack stoneSlabStack = new ItemStack(Block.stoneSingleSlab, 1, 0);

       

        GameRegistry.addRecipe(coloredStoneSlabStack, "xxx",

        'x', coloredStoneStack);

        GameRegistry.addShapelessRecipe(singleColoredStoneSlabStack, stoneSlabStack, dyeStack);

        LanguageRegistry.addName(coloredStoneSlabStack, coloredStoneSlabNames[coloredStoneSlabStack.getItemDamage()]);

        }

 

 

slab.java:

 

public coloredStoneSlab(int par1, boolean slabtype)

    {

        super(par1, slabtype, Material.rock);

        this.setRequiresSelfNotify();//MultiBlock

        this.setLightOpacity(0);//Fixes most of the Halfslab lightning bugs

        setBlockName("coloredStoneSlab");

       

    }

 

/*

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

  */

 

@Override

public String getTextureFile () {

return CommonProxy.BLOCK_PNG;

}

 

/*

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

  */

@Override

public int getBlockTextureFromSideAndMetadata(int side, int metadata) {

 

switch(side){

default:

return 64 + (metadata);

 

case 1:

return 80 + (metadata);

 

case 0:

return 80 + (metadata);

}

}

 

 

/*

  * Drops the right metadata

  */

public int idDropped(int par1, Random par2Random, int par3)

    {

 

        return bExpansion.coloredStoneSlabID;

 

    }

 

@Override

public int damageDropped(int metadata)

    {

 

return metadata & 7;

 

    }

 

/*

  * 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) == bExpansion.coloredStoneSlabID){

 

  int metadata = par1World.getBlockMetadata(x, y - 1, z);

 

  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, bExpansion.coloredStoneDoubleSlabID, 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(bExpansion.coloredStoneSlab, 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 == bExpansion.coloredStoneSlab.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 != bExpansion.coloredStoneDoubleSlab.blockID){

    for (int z=0; z<16; z++) { //change number after 4< for more metadata blocks

    par3List.add(new ItemStack(par1, 1, z));

    }

}

}

 

 

slabItemBlock.java (since i'm using metadata i think i need to render the item for the inventory separately):

 

private final static String[] subNames = {

"white", "orange",  "magenta", "lightBlue", "yellow", "lightGreen",

"pink", "darkGrey", "lightGrey", "cyan", "purple", "blue", "brown",

"green", "red", "black"

};

 

 

public coloredItemStoneSlab(int par1) {

super(par1);

setHasSubtypes(true);

setItemName("coloredStoneSlab");

// TODO Auto-generated constructor stub

}

 

@Override

public int getMetadata (int damageValue) {

return damageValue;

}

 

 

@Override

public String getItemNameIS(ItemStack itemstack) {

return getItemName() + "." + subNames[itemstack.getItemDamage()];

}

 

Link to comment
Share on other sites

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

Try to remove this ... & 7 and return just metadata. I seriously can't see any reason to use bitwise AND here.

 

public void onBlockPlacedBy(World par1World, int x, int y, int z, EntityLiving par5EntityLiving){
         
        if (par1World.getBlockId(x, y - 1, z) == bExpansion.coloredStoneSlabID){
         
         int metadata = par1World.getBlockMetadata(x, y - 1, z);
         
         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, bExpansion.coloredStoneDoubleSlabID, metadata);
         
           //makes the slab a double-slab of the same metadata type
                  }   
              }
       
       }

 

You are able to place stuff on top and it works properly because of this method. However you are checking if there is a halfslab below. Try checking above direction too, or try to mimic what Vanilla minecraft does.

Link to comment
Share on other sites

Slabs use the 0x8 bit of metadata to store where the slab is upside down not.

Slabs can be either "right-side-up" or "upside-down"; this information is stored in the most significant metadata bit 0x8 as follows:

  • 0: Slab is right-side-up, occupying the bottom half of its voxel.
  • 1: Slab is upside-down, occupying the top half of its voxel.

 

The &7 is used to return the type of slab (stone, brick, etc.) and &8 returns the up or down position.

If you remove the bitwise AND you can use the full 16 bits to have 16 different slabs but you won't be able to place them upside down as with vanilla slabs.

A bit of a work around using another 'upside-down' slab block class and some placement handling could solve that (ie. if face placed on is bottom face of block, place upside-down slab id. Upside down slabs would drop 'right-side-up' slab id.)

 

 

And instead of this.setLightOpacity(0);

You can use this.useNeighborBrightness[id] = true; to fix the slab and stairs lighting

Link to comment
Share on other sites

Slabs use the 0x8 bit of metadata to store where the slab is upside down not.

Slabs can be either "right-side-up" or "upside-down"; this information is stored in the most significant metadata bit 0x8 as follows:

  • 0: Slab is right-side-up, occupying the bottom half of its voxel.
  • 1: Slab is upside-down, occupying the top half of its voxel.

 

The &7 is used to return the type of slab (stone, brick, etc.) and &8 returns the up or down position.

If you remove the bitwise AND you can use the full 16 bits to have 16 different slabs but you won't be able to place them upside down as with vanilla slabs.

A bit of a work around using another 'upside-down' slab block class and some placement handling could solve that (ie. if face placed on is bottom face of block, place upside-down slab id. Upside down slabs would drop 'right-side-up' slab id.)

 

 

And instead of this.setLightOpacity(0);

You can use this.useNeighborBrightness[id] = true; to fix the slab and stairs lighting

 

What if i do 2 classes with 8 slabs each, that would make they work fine right?

About your solution, if i had 2 slab classes i wouldn't be able to figure out if the player clicked on the up or down half of a normal block to place the slab, so the slabs would only work like vanilla if they were placed on the bottom face or the top face of the blocks, not on the sides, am I right?

 

I decided to split the 16 slabs in 2 classes, but i can't get the placement from top to bottom to work, any help?

Code:

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

		 int metadata = theWorld.getBlockMetadata(x, y, z);		 			
	  if (theWorld.getBlockId(x, y - 1, z) == bExpansion.coloredStoneSlabID2 && theWorld.getBlockMetadata(x, y - 1, z) == metadata){
		  
			  theWorld.setBlockWithNotify(x, y, z, 0); //sets the block below to 0

			  theWorld.setBlockAndMetadataWithNotify(x, y - 1, z, bExpansion.coloredStoneDoubleSlabID2, metadata & 7);
	    
	     //makes the slab a double-slab of the same metadata type
	   			
	  		} else {
	  			
	  				int metadata2 = theWorld.getBlockMetadata(x, y, z); 
	  
	  			if (theWorld.getBlockId(x, y + 1, z) == bExpansion.coloredStoneSlabID2 && theWorld.getBlockMetadata(x, y + 1, z) == metadata2){
	  				
	  				  theWorld.setBlockWithNotify(x,y, z, 0); //sets the block below to 0
	  				  theWorld.setBlockAndMetadataWithNotify(x, y + 1, z, bExpansion.coloredStoneDoubleSlabID2, metadata2 & 7);
	 		    
	 		     //makes the slab a double-slab of the same metadata type
	  				}
	  		}
	  
	 }

Edit: The code is actually working, but only if there's no block under it. Ideas?

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.

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.