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

I can only make without losing metadata(for detect bounds) old style half-slabs. I want make vanilla like custom half slabs with metadata(x:0, x:1, etc...). So i need help!

Current code(doesn't work properly):

package mypackage;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Random;
import net.minecraft.block.*;
import net.minecraft.item.*;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Facing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockHalfSlabs extends BlockContainer
{
    private boolean isDoubleSlabs = false;
    private boolean isDownSlab = false;
    
    public BlockHalfSlabs(int par1, Material par2, boolean par3, int par4)
    {
        super(par1, par4, par2);
        this.setRequiresSelfNotify();
this.blockIndexInTexture = par4;
        this.setLightOpacity(0);
        this.isDoubleSlabs = par3;
        if (isDoubleSlabs)
        {
            opaqueCubeLookup[par1] = true;
        }
        else
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
        }
    }
    
    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int x, int y, int z)
    {
        if (this.isDoubleSlabs)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
        else
        {
        TileEntityHalfSlab t = (TileEntityHalfSlab) par1IBlockAccess.getBlockTileEntity(x, y, z);

            if (t.isDownSlab)
            {
                this.setBlockBounds(0.0F, 0.5F, 0.0F, 1.0F, 1.0F, 1.0F);
            }
            else
            {
                this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
            }
        }
    }
    
    public void setBlockBoundsForItemRender()
    {
        if (this.isDoubleSlabs)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
        else
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
        }
    } 
    
    public int getBlockTextureFromSide(int par1)
    {
        return this.getBlockTextureFromSideAndMetadata(par1, 0);
    }
     
    
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs tab, List subItems) {
	for (int ix = 0; ix < 16; ix++) {
		subItems.add(new ItemStack(this, 1, ix));
	}
}
            
    /**
     * if the specified block is in the given AABB, add its collision bounding box to the given list

    /**
     * Returns the block texture based on the side being looked at.  Args: side
     */
@Override
public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
	return this.blockIndexInTexture + metadata;
}

public String getTextureFile () {
        return ClientProxy.BLOCK_PNG;
}

    /**
     * Returns the quantity of items to drop on block destruction.
     */
@Override
public int damageDropped (int metadata) {
	return metadata;
}
        
    @Override
  public int onBlockPlaced(World par1World, int x, int y, int z, int par5, float par6, float par7, float par8, int par9)
    {
        if(par7 <= 0.5F) {
        isDownSlab = true;
        } else {
        isDownSlab = false;
        }
par1World.scheduleBlockUpdate(x, y, z, blockID, 1);
        System.out.println(isDownSlab);
        return par9;
    }
    
    public void updateTick(World par1World, int x, int y, int z, Random par5Random) {
    TileEntityHalfSlab t = (TileEntityHalfSlab) par1World.getBlockTileEntity(x, y, z);
    t.isDownSlab = this.isDownSlab;
    System.out.println(t.isDownSlab);
    }
    
    public void addCollidingBlockToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
    {
        this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
        super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    }

    /**
     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
    public boolean isOpaqueCube()
    {
        return this.isDoubleSlabs;
    }

    /**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
    public boolean renderAsNormalBlock()
    {
        return this.isDoubleSlabs;
    }

    @SideOnly(Side.CLIENT)

    /**
     * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
     * coordinates.  Args: blockAccess, x, y, z, side
     */
    public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        if (this.isDoubleSlabs)
        {
            return super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5);
        }
        else if (par5 != 1 && par5 != 0 && !super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5))
        {
            return false;
        }
        else
        {
            TileEntityHalfSlab t = (TileEntityHalfSlab) par1IBlockAccess.getBlockTileEntity(par2, par3, par4);
            return t.isDownSlab ? (par5 == 0 ? true : (par5 == 1 && super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5) ? true : !isBlockSingleSlab(par1IBlockAccess.getBlockId(par2, par3, par4)) || (par1IBlockAccess.getBlockMetadata(par2, par3, par4) &  == 0)) : (par5 == 1 ? true : (par5 == 0 && super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5) ? true : !isBlockSingleSlab(par1IBlockAccess.getBlockId(par2, par3, par4)) || (par1IBlockAccess.getBlockMetadata(par2, par3, par4) &  != 0));
        }
    }

    @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 == my_mod_file.blockLimestoneStoneHalfSlab.blockID || par0 == my_mod_file.blockLimestoneBrickHalfSlab.blockID;
    }

    /**
     * Get the block's damage value (for use with pick block).
     */
    public int getDamageValue(World par1World, int par2, int par3, int par4)
    {
        return super.getDamageValue(par1World, par2, par3, par4) & 7;
    }

    @SideOnly(Side.CLIENT)

    /**
     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
     */
    public int idPicked(World par1World, int par2, int par3, int par4)
    {
        return isBlockSingleSlab(this.blockID) ? this.blockID : (this.blockID == my_mod_file.blockLimestoneStoneHalfSlabDouble.blockID ? my_mod_file.blockLimestoneStoneHalfSlab.blockID : (this.blockID == my_mod_file.blockLimestoneBrickHalfSlabDouble.blockID ? my_mod_file.blockLimestoneBrickHalfSlab.blockID : my_mod_file.blockLimestoneBrickHalfSlab.blockID));
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random par1Random)
    {
        return this.isDoubleSlabs ? 2 : 1;
    }

    /**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
    
public boolean hasTileEntity(int metadata)
{
	return true;
}

public TileEntity createNewTileEntity(World par1World)
{
	try
	{
        return new TileEntityHalfSlab();
	}
	catch (Exception var3)
	{
        throw new RuntimeException(var3);
	}
}	
}

P.S. Sorry for ban eglish  :P

P.S.S. Thanks in advance! :)

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.