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 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.

  • Author

I have checked out the BlockSlab class but I cant really make heads or tales of it.

Extending that class would be enough, simply override ordinary methods for getting and registering IIcons for textures, see BlockStoneSlab and BlockWoodSlab for how they're implemented in them.

  • Author

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.

  • Author

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;
}

}

 

  • Author

I've been trying to get the slab to work for almost 5 days. I'm sure it's something so small and stupid..

Any help would be appreciated.

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.

  • Author

ok I think I understand what you're saying but how do I go about doing that?

  • Author

ok I have it just unlocalizedName() and not super.

I add

public String blockName = unlocalizedName();

 

and func_150002_b return blockName

 

it still doesnt have texture and its now tile.null.name

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

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

 

@Override
public String func_150002_b(int par1) {
return getFullSlabName(par1);
}

 

  • Author

Still no texture and now name is tile.MySlab.blockMaySlab.name

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.

  • Author

right now for testing I am just using the minecraft stone texture and have it as

this.blockIcon = par1IconRegister.registerIcon("minecraft:stone");

 

still not working

  • Author

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;
}

 

  • Author

Yep. Well that was almost 7 days of hell. Can someone point me in the direction of the one who created slabs so I can punch them in the face? lol

[sOLVED]

 

Thanks imadnsn

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.