Jump to content

1.7+ Slab help needed.


rtester

Recommended Posts

This is driving me crazy I been racking my brains over this for like 3 days or so straight and nothing I do seems to work at all.  I have the slab texture, name, and middle click right. The slab will stack top slab - bottom slab. But will not place bottom slab- top slab to create a full block.  I been all over the parent classes I believe I almost have every method included in my class file and from what I did with the stairs class I probably have way too much code just to extend the blocks because my stairs only have like 10 lines of code max I believe but these slabs is getting way out of hand I believe. I add more methods that seem to do nothing at all to allow the slabs to stack.

 

here is my code for my

ObsidianSlab.java

 

package rtester.missingblocks.blocks.slabs.stone;

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

import rtester.missingblocks.blocks.ModBlocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.BlockStoneSlab;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Facing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class ObsidianSlab extends BlockSlab{

protected final boolean _isDoubleSlab;
public final static String name = "obsidianSlab";
public final static String name1 = "obsidianDblSlab";
public static final String[] slabName = new String[]{ name, name1 };
private static final String __OBFID = "CL_00000337"; // I d not know why we need this because i can't find it being referenced in any file.

public ObsidianSlab(boolean isDoubleSlab, Material blockMaterial) {
super(isDoubleSlab, blockMaterial);
this._isDoubleSlab = isDoubleSlab;
this.setStepSound(soundTypePiston);
this.setBlockTextureName("obsidian");
this.setHardness(50.0F);
this.setResistance(2000.0F);
this.setHarvestLevel("pickaxe", 3);
this.useNeighborBrightness = true;

if (isDoubleSlab){

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

this.setLightOpacity(255);
}

public int quantityDropped(Random rand){

return this._isDoubleSlab ? 2 : 1;
}

public boolean renderAsNormalBlock(){

return this._isDoubleSlab;
}

public int onBlockPlaced(World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata){

return this._isDoubleSlab ? metadata : (side != 0 && (side == 1 || (double)hitY <= 0.5D) ? metadata : metadata | ;
}

public void onBlockPlacedBy(World world, int par2, int par3, int par4, EntityLiving par5){

if(world.getBlock(par2, par3 - 1, par4) == ModBlocks.obsidianSlab){

world.setBlock(par2, par3 - 1, par4, ModBlocks.obsidianDblSlab);

}

if(world.getBlock(par2, par3 + 1, par4) == ModBlocks.obsidianSlab){

world.setBlock(par2, par3 + 1, par4, ModBlocks.obsidianDblSlab);

}
}

@Override
public ItemStack createStackedBlock(int idk){

return new ItemStack(Item.getItemFromBlock(ModBlocks.obsidianSlab), 2, idk & 7);
}

public String getFullSlabName(int i){

if ((i < 0) || (i >= slabName.length)){

i = 0;

}

return super.getUnlocalizedName() + "." + slabName[i];

}

@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side){

if (this._isDoubleSlab)
{
return super.shouldSideBeRendered(blockAccess, x, y, z, side);
}
else if (side != 1 && side != 0 && !super.shouldSideBeRendered(blockAccess, x, y, z, side))
{
return false;
}
else
{
int i1 = x + Facing.offsetsXForSide[Facing.oppositeSide[side]];
int j1 = y + Facing.offsetsYForSide[Facing.oppositeSide[side]];
int k1 = z + Facing.offsetsZForSide[Facing.oppositeSide[side]];
boolean flag = (blockAccess.getBlockMetadata(i1, j1, k1) &  != 0;

return flag ? (side == 0 ? true : (side == 1 && super.shouldSideBeRendered(blockAccess, x, y, z, side) ? true : !isBlockSingleSlab(blockAccess.getBlock(x, y, z)) || (blockAccess.getBlockMetadata(x, y, z) &  == 0)) : (side == 1 ? true : (side == 0 && super.shouldSideBeRendered(blockAccess, x, y, z, side) ? true : !isBlockSingleSlab(blockAccess.getBlock(x, y, z)) || (blockAccess.getBlockMetadata(x, y, z) &  != 0));
}
}

@SideOnly(Side.CLIENT)
public static boolean isBlockSingleSlab(Block b)
{
return b == ModBlocks.obsidianSlab;
}

@Override
@SideOnly(Side.CLIENT)
public Item getItem(World world, int idk1, int idk2, int idk3){

return isBlockSingleSlab(this) ? Item.getItemFromBlock(this) : (this == ModBlocks.obsidianDblSlab ? Item.getItemFromBlock(ModBlocks.obsidianSlab) : Item.getItemFromBlock(ModBlocks.obsidianSlab));

}

public void getSubBlocks(Block block, CreativeTabs cTabs, List list){

if (block != ModBlocks.obsidianDblSlab){

list.add(new ItemStack(block, 1, 0));
}
}

@Override
public String func_150002_b(int idk1){

return null;
}

}

 

 

and here is the code that calls the class in my

 

ModBlocks.java

 

//Stone Slabs
public static Block obsidianSlab;
public static Block obsidianDblSlab;



public static void init(){

// Stone Slabs
obsidianSlab = new ObsidianSlab(false, Material.rock).setBlockName(Constants.MODID + "_" + ObsidianSlab.name).setCreativeTab(CreativeTabs.tabBlock);
obsidianDblSlab = new ObsidianSlab(true, Material.rock).setBlockName(Constants.MODID + "_" + ObsidianSlab.name1).setCreativeTab(null);



//GameRegistry.registerBlock(this, name);
GameRegistry.registerBlock(obsidianSlab, ObsidianSlab.name);
GameRegistry.registerBlock(obsidianDblSlab, ObsidianSlab.name1);

}

 

 

All the tutorials I find on the net is only for 1.6 and they all state to get the blocks to show up as a full slab you need to put code like this in the post init method to get them to stack.

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {

Item.itemsList [ModBlocks.obsidianSlab.blockID] = (new ItemSlab(
ModBlocks.obsidianSlab.blockID - 256, (ObsidianSlab) ModBlocks.obsidianSlab,
(ObsidianSlab) ModBlocks.obsidianDblSlab, false)); 
}

 

But when I try to remove the part that says .blockID to like .Block it wont work since it is looking for an integer instead of a block. I can not find where the source for minecraft is doing the post init code for the slabs. So would anyone please help me figure this out.

Link to comment
Share on other sites

GameRegistry.registerBlock(myBlock, MyItemBlock.class, "foobar", <additional constructor arguments>)

 

It's really pretty self-explanatory.

 

I do not have an custom itemBlock class I was trying to do the slab in a single class called ObsidianSlabs like I all of my Stair blocks.  Do I need more than 1 class to get this to work in 1.7 because 1.6 I only needed 1 class.

 

this is what the blocks are doing the way I have them.

 

 

img

 

 

Link to comment
Share on other sites

You've always needed a custom ItemBlock class, in 1.6 and in 1.7.

I did not need one for my stair blocks but I have yet to write recipes for them also. as this is my first mod There is a lot to learn.

 

I think I might be getting closer to the solution to my problem with the slab if someone could help me out with this crash I am having. I know it placed a slab on top of the block just before it crashed because when I load the game back up I can see an outline of an invisible block. here is the files as I now have them.

 

 

 

Crash Report: http://pastebin.com/Xw6WRWBs

 

ModBloscksSlabs: http://pastebin.com/HFP9ELzv

 

ObsidianItemSlab: http://pastebin.com/ayMpvG5f

 

ObsidianSlab: http://pastebin.com/RQfE4LDL

 

 

 

 

Thanks for all the help you all have given me I am getting closer to solving the dilemma..

Link to comment
Share on other sites

You never initialize the "textureBlock" field.

 

I thought it was initialized I have it in the declares in the main method and being set in my slab setup in ModBlocksSlabs.java the obsidian texture is showing up on the block.

private boolean isDoubleSlab;
private int numSubBlocks;
private Block singleSlab;
private Block textureBlock;
private int textureStartCounter;
public final static String name = "obsidianSlab";
public final static String name1 = "obsidianDblSlab";
public static final String[] slabName = new String[]{ name, name1 };

public ObsidianSlab(boolean _isDoubleSlab, Material _blockMaterial, int _numSubBlocks, Block _singleSlab, Block _textureBlock, int _textureStartCounter) {

	super(_isDoubleSlab, _blockMaterial);

	this.setHardness(50.0F);
	this.setResistance(2000.0F);
	this.setHarvestLevel("pickaxe", 3);
	this.setStepSound(soundTypePiston);
	this.useNeighborBrightness = true;
	this.setLightOpacity(255);

	if(_isDoubleSlab){

		this.setCreativeTab(CreativeTabs.tabBlock);
		//this.setBlockName(Constants.MODID + "_" + ObsidianSlab.name1);
		//this.setCreativeTab(null);
	  
		} else{

			//this.setBlockName(Constants.MODID + "_" + ObsidianSlab.name);
			this.setCreativeTab(CreativeTabs.tabBlock);
		  	this.isDoubleSlab = _isDoubleSlab;
		  	this.numSubBlocks = _numSubBlocks;
		  	this.singleSlab = _singleSlab;
		  	this.textureBlock = _textureBlock;
		  	this.textureStartCounter = _textureStartCounter;
		  	
	}

}

The name is showing up as tile.obsidianBlock instead of tile.missingblock the example code I got this code from show for it to be written this way.

 

in the customitemSlab file

this.singleSlab = (BlockSlab) MyModName.mySlabSingle; //Here you have to set your single slab
this.doubleSlab = (BlockSlab) MyModName.mySlabDouble; //And here your double slab

 

but i could not resolve (BlockSlab) missingblock.mySlabSingle the only way I could get it to resolve was

this.singleSlab = (BlockSlab) ModBlocksSlabs.obsidianSlab; //Here you have to set your single slab
this.doubleSlab = (BlockSlab)ModBlocksSlabs.obsidianDblSlab; //And here your double slab

or

this.singleSlab = (obsidianSlab) ModBlocksSlabs.obsidianSlab; //Here you have to set your single slab
this.doubleSlab = (obsidianSlab) ModBlocksSlabs.obsidianDblSlab; //And here your double slab

 

but either way the name is messed up when you mouse over it and when it goes to place it on top of the lower slab the game crashes. could you tell me how to fix this as you can see I am trying to research it try different things and nothing still seems not to work and I am getting very frustrated that all i see to get is  cryptic answers. you said I did not initialize the textureBlock but did you look at the code files?

if i did not initialize it right why don't tell me where I went wrong in initializing it.  Do not get me wrong I really appreciate the time people takes and post on this but as I stated I am a beginner modding programmer and you guys answer like I am a seasoned modding programmer. I also have a learning disablilty and I am trying my best to do this all on my own but I really need help on this.

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.