Jump to content

Recommended Posts

Posted

Hi everybody! I've noticed a curious thing while making a custom slab. I can't place redstone or torches on top of it if placing the slab in the upper half part of a block.

 

Here is my BlockHalfSlab class:

package mod.mineworld.blocks.mod_ores;

import java.util.List;
import java.util.Random;

import mod.mineworld.MineWorld;
import mod.mineworld.mod_ores;
import mod.mineworld.mod_tabs;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;



public class BlockHalfSlab extends BlockOreSlab
{
    public static final String[] slab_names = new String[] {"ruby", "sapphire", "copper", "bronze", "silver", "aluminium", "whiteMarble", "pinkMarble"};
    @SideOnly(Side.CLIENT)
    private IIcon icon;

    public BlockHalfSlab(boolean par1)
    {
        super(par1, Material.rock);
        this.setCreativeTab(mod_tabs.tabOreBlock);
    }

    /**
     * Gets the block's texture. Args: side, meta
     */
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int par1, int par2)
    {
        int k = par2 & 7;

        if (this.isDoubleSlab && (par2 &  != 0)
        {
            par1 = 1;
        }

        return k == 0 ? (par1 != 1 && par1 != 0 ? mod_ores.block_ruby.getBlockTextureFromSide(par1) : 
        	mod_ores.block_ruby.getBlockTextureFromSide(par1)) : 
        		(k == 1 ? mod_ores.block_sapphire.getBlockTextureFromSide(par1) : 
        			(k == 2 ? mod_ores.block_copper.getBlockTextureFromSide(par1) : 
        				(k == 3 ? mod_ores.block_bronze.getBlockTextureFromSide(par1) : 
        					(k == 4 ? mod_ores.block_silver.getBlockTextureFromSide(par1) : 
        						(k == 5 ? mod_ores.block_aluminium.getIcon(par1, 0) : 
        							(k == 6 ? mod_ores.ore_marble.getBlockTextureFromSide(1) :  
        								this.blockIcon))))));
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister par1)
    {
        this.blockIcon = par1.registerIcon(MineWorld.MODID + ":mod_ores/" + "oreMarble_pink");
        this.icon = par1.registerIcon(MineWorld.MODID + ":mod_ores/" + "oreMarble_pink");
    }

    public Item getItemDropped(int par1, Random par2, int par3)
    {
        return Item.getItemFromBlock(mod_ores.ore_single_slab);
    }

    /**
     * Returns an item stack containing a single instance of the current block type. 'i' 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(Item.getItemFromBlock(mod_ores.ore_single_slab), 2, par1 & 7);
    }

    public String getFullSlabName(int par1)
    {
        if (par1 < 0 || par1 >= slab_names.length)
        {
            par1 = 0;
        }

        return super.getUnlocalizedName() + "." + slab_names[par1];
    }

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item par1, CreativeTabs par2, List par3)
    {
        if (par1 != Item.getItemFromBlock(mod_ores.ore_double_slab))
        {
            for (int i = 0; i <= 7; ++i)
            {
                    par3.add(new ItemStack(par1, 1, i));
            }
        }
    }
    
    
}

 

The BlockOreSlab class:

package mod.mineworld.blocks.mod_ores;

import java.util.List;
import java.util.Random;

import mod.mineworld.mod_ores;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Facing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;



public abstract class BlockOreSlab extends Block
{
    protected final boolean isDoubleSlab;
    private static boolean power = false;
    private static int power_level;
    private static int metadata;

    public BlockOreSlab(boolean par1, Material par2)
    {
        super(par2);
        this.isDoubleSlab = par1;

        if (par1)
        {
            this.opaque = true;
        }
        else
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
        }

        this.setLightOpacity(0);
    }

    /**
     * Updates the blocks bounds based on its current state. Args: world, x, y, z
     */
    public void setBlockBoundsBasedOnState(IBlockAccess par1, int par2, int par3, int par4)
    {
        if (this.isDoubleSlab)
        {
            this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
        }
        else
        {
            boolean flag = (par1.getBlockMetadata(par2, par3, par4) &  != 0;

            if (flag)
            {
                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);
            }
        }
    }

    /**
     * Sets the block's bounds for rendering it as an item
     */
    public void setBlockBoundsForItemRender()
    {
        if (this.isDoubleSlab)
        {
            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);
        }
    }

    /**
     * Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the
     * mask.) Parameters: World, X, Y, Z, mask, list, colliding entity
     */
    public void addCollisionBoxesToList(World par1, int par2, int par3, int par4, AxisAlignedBB par5, List par6, Entity par7)
    {
        this.setBlockBoundsBasedOnState(par1, par2, par3, par4);
        super.addCollisionBoxesToList(par1, par2, par3, par4, par5, par6, par7);
    }

    /**
     * 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.isDoubleSlab;
    }

    /**
     * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
     */
    public int onBlockPlaced(World par1, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
    {
        metadata = par9;
    	return this.isDoubleSlab ? par9 : (par5 != 0 && (par5 == 1 || (double)par7 <= 0.5D) ? par9 : par9 | ;
    }

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

    /**
     * Determines the damage on the item the block drops. Used in cloth and wood.
     */
    public int damageDropped(int par1)
    {
        return par1 & 7;
    }

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

    /**
     * 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
     */
    @SideOnly(Side.CLIENT)
    public boolean shouldSideBeRendered(IBlockAccess par1, int par2, int par3, int par4, int par5)
    {
        if (this.isDoubleSlab)
        {
            return super.shouldSideBeRendered(par1, par2, par3, par4, par5);
        }
        else if (par5 != 1 && par5 != 0 && !super.shouldSideBeRendered(par1, par2, par3, par4, par5))
        {
            return false;
        }
        else
        {
            int i1 = par2 + Facing.offsetsXForSide[Facing.oppositeSide[par5]];
            int j1 = par3 + Facing.offsetsYForSide[Facing.oppositeSide[par5]];
            int k1 = par4 + Facing.offsetsZForSide[Facing.oppositeSide[par5]];
            boolean flag = (par1.getBlockMetadata(i1, j1, k1) &  != 0;
            return flag ? (par5 == 0 ? true : (par5 == 1 && super.shouldSideBeRendered(par1, par2, par3, par4, par5) ? true : !isBlockSingleSlab(par1.getBlock(par2, par3, par4)) || (par1.getBlockMetadata(par2, par3, par4) &  == 0)) : (par5 == 1 ? true : (par5 == 0 && super.shouldSideBeRendered(par1, par2, par3, par4, par5) ? true : !isBlockSingleSlab(par1.getBlock(par2, par3, par4)) || (par1.getBlockMetadata(par2, par3, par4) &  != 0));
        }
    }

    @SideOnly(Side.CLIENT)
    private static boolean isBlockSingleSlab(Block par1)
    {
        return par1 == mod_ores.ore_single_slab;
    }

    public abstract String getFullSlabName(int var1);

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

    /**
     * Gets an item for the block being called on. Args: world, x, y, z
     */
    @SideOnly(Side.CLIENT)
    public Item getItem(World par1, int par2, int par3, int par4)
    {
    	return Item.getItemFromBlock(mod_ores.ore_single_slab);
    }
    
/**
     * Returns true if the block is emitting indirect/weak redstone power on the specified side. If isBlockNormalCube
     * returns true, standard redstone propagation rules will apply instead and this will not be called. Args: World, X,
     * Y, Z, side. Note that the side is reversed - eg it is 1 (up) when checking the bottom of the block.
     */

    @Override
    public int isProvidingWeakPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
    	if(par1IBlockAccess.getBlockMetadata(par2, par3, par4) == 2)
    		return 10;
    	else if(par1IBlockAccess.getBlockMetadata(par2, par3, par4) == 3)
    		return 5;
    	else
    		return 0;
    }
}

 

the ItemOreSlab class:

package mod.mineworld.blocks.mod_ores;

import mod.mineworld.mod_ores;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;



public class ItemOreSlab extends ItemBlock
{
    private final boolean isDoubleSlab;
    private final BlockOreSlab single_slab;
    private final BlockOreSlab double_slab;

    public ItemOreSlab(Block block)
    {
    	super(block);
    	this.single_slab = mod_ores.ore_single_slab;
    	this.double_slab = mod_ores.ore_double_slab;
    	this.isDoubleSlab = false;
    	this.setHasSubtypes(true);
    	
    }

    /**
     * Gets an icon index based on an item's damage value
     */
    @SideOnly(Side.CLIENT)
    public IIcon getIconFromDamage(int par1)
    {
        return Block.getBlockFromItem(this).getIcon(1, par1);
    }

    /**
     * Returns the metadata of the block which this Item (ItemBlock) can place
     */
    public int getMetadata(int par1)
    {
        return par1;
    }

    /**
     * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
     * different names based on their damage or NBT.
     */
    public String getUnlocalizedName(ItemStack par1ItemStack)
    {
        return this.single_slab.getFullSlabName(par1ItemStack.getItemDamage());
    }

    /**
     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
     */
    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    {
        if (this.isDoubleSlab)
        {
            return super.onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10);
        }
        else if (par1ItemStack.stackSize == 0)
        {
            return false;
        }
        else if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
        {
            return false;
        }
        else
        {
            Block block = par3World.getBlock(par4, par5, par6);
            int i1 = par3World.getBlockMetadata(par4, par5, par6);
            int j1 = i1 & 7;
            boolean flag = (i1 &  != 0;

            if ((par7 == 1 && !flag || par7 == 0 && flag) && block == this.single_slab && j1 == par1ItemStack.getItemDamage())
            {
                if (par3World.checkNoEntityCollision(this.double_slab.getCollisionBoundingBoxFromPool(par3World, par4, par5, par6)) && par3World.setBlock(par4, par5, par6, this.double_slab, j1, 3))
                {
                    par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), this.double_slab.stepSound.func_150496_b(), (this.double_slab.stepSound.getVolume() + 1.0F) / 2.0F, this.double_slab.stepSound.getPitch() * 0.8F);
                    --par1ItemStack.stackSize;
                }

                return true;
            }
            else
            {
                return this.isBlockDoubleSlab(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7) ? true : super.onItemUse(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10);
            }
        }
    }

    @SideOnly(Side.CLIENT)
    public boolean isBlockSingleSlab(World par1, int par2, int par3, int par4, int par5, EntityPlayer par6, ItemStack par7)
    {
        int i1 = par2;
        int j1 = par3;
        int k1 = par4;
        Block block = par1.getBlock(par2, par3, par4);
        int l1 = par1.getBlockMetadata(par2, par3, par4);
        int i2 = l1 & 7;
        boolean flag = (l1 &  != 0;

        if ((par5 == 1 && !flag || par5 == 0 && flag) && block == this.single_slab && i2 == par7.getItemDamage())
        {
            return true;
        }
        else
        {
            if (par5 == 0)
            {
                --par3;
            }

            if (par5 == 1)
            {
                ++par3;
            }

            if (par5 == 2)
            {
                --par4;
            }

            if (par5 == 3)
            {
                ++par4;
            }

            if (par5 == 4)
            {
                --par2;
            }

            if (par5 == 5)
            {
                ++par2;
            }

            Block block1 = par1.getBlock(par2, par3, par4);
            int j2 = par1.getBlockMetadata(par2, par3, par4);
            i2 = j2 & 7;
            return block1 == this.single_slab && i2 == par7.getItemDamage() ? true : super.func_150936_a(par1, i1, j1, k1, par5, par6, par7);
        }
    }

    private boolean isBlockDoubleSlab(ItemStack par1, EntityPlayer par2, World par3, int par4, int par5, int par6, int par7)
    {
        if (par7 == 0)
        {
            --par5;
        }

        if (par7 == 1)
        {
            ++par5;
        }

        if (par7 == 2)
        {
            --par6;
        }

        if (par7 == 3)
        {
            ++par6;
        }

        if (par7 == 4)
        {
            --par4;
        }

        if (par7 == 5)
        {
            ++par4;
        }

        Block block = par3.getBlock(par4, par5, par6);
        int i1 = par3.getBlockMetadata(par4, par5, par6);
        int j1 = i1 & 7;

        if (block == this.single_slab && j1 == par1.getItemDamage())
        {
            if (par3.checkNoEntityCollision(this.double_slab.getCollisionBoundingBoxFromPool(par3, par4, par5, par6)) && par3.setBlock(par4, par5, par6, this.double_slab, j1, 3))
            {
                par3.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), this.double_slab.stepSound.func_150496_b(), (this.double_slab.stepSound.getVolume() + 1.0F) / 2.0F, this.double_slab.stepSound.getPitch() * 0.8F);
                --par1.stackSize;
            }

            return true;
        }
        else
        {
            return false;
        }
    }
    
}

 

Thanks in advice for all who will help me :D

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted

I think i was misunderstaned :/ I know that you can't place redstone on slabs, but if they ure upside down you can. Here is an image to explain what i'm saying:

 

mb74bc.png

 

As you can see i can place redstone on the top side of Stone Slab but i can't on the top side of my custom slab :/

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted

This is not a bug. You cant place redstone over vanilla slabs either  ;D

Not true you can place renstone on a top slab (slab that is placed in the top half of the block space)

Im not sure how vanilla dose it but you may be able to make it work by overriding "isSideSolid" and returning true if side = up and the block is the top slab version.

I am the author of Draconic Evolution

Posted

This is not a bug. You cant place redstone over vanilla slabs either  ;D

You can if it's the top slab.

 

You tried overriding BlockSlab to see if that works? Not tested it though.

Posted

Solved: i've overrided the method isSideSolid in my BlockOreSlab class :D

For all to know, Minecraft use this method in the Block class:

public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side)
    {
        int meta = world.getBlockMetadata(x, y, z);

        if (this instanceof BlockSlab)
        {
            return (((meta &  == 8 && (side == UP)) || func_149730_j());
        }
        else if (this instanceof BlockFarmland)
        {
            return (side != DOWN && side != UP);
        }
        else if (this instanceof BlockStairs)
        {
            boolean flipped = ((meta & 4) != 0);
            return ((meta & 3) + side.ordinal() == 5) || (side == UP && flipped);
        }
        else if (this instanceof BlockSnow)
        {
            return (meta & 7) == 7;
        }
        else if (this instanceof BlockHopper && side == UP)
        {
            return true;
        }
        else if (this instanceof BlockCompressedPowered)
        {
            return true;
        }
        return isNormalCube(world, x, y, z);
    }

as you can see the first lines are for the slabs, so it is how it works :D

Thanks for helped me :D

Don't blame me if i always ask for your help. I just want to learn to be better :)

Posted

I've done this classes many times ago, when i don't know anything, so i just copy&paste classes. I know is an error, but for the moment i think to solve this bug and them (when i will update to 1.7.10) i will clear many lines of code ;)

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.