Jump to content

[1.7.10] Custom slab help [SOLVED]


Crow

Recommended Posts

I am looking for some help with creating custom slabs for my mod. I have searched around and can only find tutorials and samples for 1.6 or earlier.

Does someone have a sample class I could take a look?

Yes, I am new to coding and modding and yes I do know the basics of java though my knowledge is a drop in the bucket of what I need to know.

I learn by doing. Taking code and ripping it apart to learn how everything works I just can't find anything for slabs.

 

I have the slab in the game and it works as a normal block. I need to know how to make it act as a slab, double slab ect...

Thanks in advanced.

Link to comment
Share on other sites

I have been messing with it for over 3 hours and still can't figure it out. I copied everything from the stone slab class, took out everything to do with multiple blocks, mines only one slab, and replaced everything referring to stone with my block and nothing. It's still in the creative inventory along with the double slab and still cant place another to make double.

Link to comment
Share on other sites

Ok, now I have the slab working as a slab. It stacks.

BUT now I have lost the texture and it is just showing up as .name in game.

 

Registry

blockMySlab = new MySlab(false, Material.rock).setBlockName("MySlab");
blockMySlabDouble = new MySlab(true, Material.rock).setBlockName("MySlabDouble");

GameRegistry.registerBlock(blockMySlab, ItemMySlab.class, "blockMySlab");
GameRegistry.registerBlock(blockMySlabDouble, ItemMySlab.class, "blockMySlabDouble");

 

ItemMySlab.class

package com.blackbirdgaming.MyMod.items;

import com.blackbirdgaming.MyMod.blocks.MyBlocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSlab;
public class ItemMySlab extends ItemSlab
{
    public ItemMySlab(Block block)
    {
    super(block, (BlockSlab)MyBlocks.blockMySlab, (BlockSlab)MyBlocks.blockMySlabDouble, false);
    this.setMaxDamage(0);
    this.setHasSubtypes(true);
    }
}

 

MySlab.class

package com.blackbirdgaming.MyMod.blocks.MySlab;

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

import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class MySlab extends BlockSlab
{
public static final String[] woodType = { "blockMySlab" };

public MySlab(boolean isDouble, Material mat)
{
super(isDouble, mat);
useNeighborBrightness = true;
}

public void registerIcons(IIconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("mm:myslab");
}

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
{
return Item.getItemFromBlock(MyBlocks.blockMySlab);
}

public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
{
if(par1World.getBlock(par2, par3 - 1, par4) == MyBlocks.blockMySlab)
{
par1World.setBlock(par2, par3 - 1, par4, MyBlocks.blockMySlabDouble);
}
if(par1World.getBlock(par2, par3 + 1, par4) == MyBlocks.blockMySlab)
{
par1World.setBlock(par2, par3 + 1, par4, MyBlocks.blockMySlabDouble);
}
}

protected ItemStack createStackedBlock(int par1)
{
return new ItemStack(MyBlocks.blockMySlab, 2, par1 & 7);
}

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

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

public void getSubBlocks(Block block, CreativeTabs par2CreativeTabs, List par3List)
{
if (block != MyBlocks.blockMySlabDouble)
{
par3List.add(new ItemStack(block, 1, 0));
}
}

@Override
public String func_150002_b(int p_150002_1_) {
// TODO Auto-generated method stub
return null;
}

}

 

Link to comment
Share on other sites

The first thing I found is that func_150002_b should return your getFullName function it got ".name" only because you're returning null, another note is that in your getFullName, it shouldn't use super.getUnlocalizedName(), but rather just getUnlocalizedName(), as if you use the former the ItemStack will get Minecraft's slabs name not your mod's ones.

Link to comment
Share on other sites

Now the name is correct (set up a lang file for a friendly name)

Make sure the texture is correct. Its name must all be lowercase (some systems have case-sensitive folders), and depending on your code, it must be assets/mm/myslab.png

It must also be 16x16 in size, like all block textures.

Link to comment
Share on other sites

ok I decided to try the code I was using for another solid block and it works perfect.

Don't know it works but it does. So I figure I wouldn't argue with it. lol

 

@SideOnly(Side.CLIENT)
protected IIcon blockIcon;

@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister p_149651_1_)
{
blockIcon = p_149651_1_.registerIcon(minecraft:stone);
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int p_149691_1_, int p_149691_2_)
{
return blockIcon;
}

 

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.