Hello I was wondering if anyone might know why I am getting 2 walls showing up in Minecraft when my system.out.println say only one of each block is getting created.
public class MBM_Blocks {
public static final List<Block> blocks = new ArrayList<Block>();
public static final void preinit() {
// Blocks
ModInfo.blockBlueScreen = registerBlock("blockBlueScreen", new ChromakeyBlock(Material.CLAY));
ModInfo.blockGreenScreen = registerBlock("blockGreenScreen", new ChromakeyBlock(Material.CLAY));
//Stairs
ModInfo.blockBlueScreenStairs = registerBlock("blockBlueScreenStairs", new ChromakeyStairs());
ModInfo.blockGreenScreenStairs = registerBlock("blockGreenScreenStairs", new ChromakeyStairs());
ModInfo.blockObsidianStairs = registerBlock("blockObsidianStairs", new ObsidianStairs());
for(int ci = 0; ci < ModInfo.MAX; ci++){
String block_name = ModInfo.woolColours[ci] + "Stairs";
ModInfo.blockWoolenStairs[ci] = registerBlock(block_name, new WoolenStairs());
System.out.println(" Creating Wool Stairs [ " + ModInfo.blockWoolenStairs[ci] + " ]");
}
//Walls
ModInfo.blockBlueScreenWall = registerBlock("blockBlueScreenWall", new WoolenWalls(Blocks.CLAY));
ModInfo.blockGreenScreenWall = registerBlock("blockGreenScreenWall", new WoolenWalls(Blocks.CLAY));
ModInfo.blockObsidianWall = registerBlock("blockObsidianWall", new WoolenWalls(Blocks.OBSIDIAN));
for(int ci = 0; ci < ModInfo.MAX; ci++){
String block_name = ModInfo.woolColours[ci] + "Wall";
ModInfo.blockWoolenWalls[ci] = registerBlock(block_name, new WoolenWalls(Blocks.WOOL));
System.out.println(" Creating Wool Wall [ " + ModInfo.blockWoolenWalls[ci] + " ]");
}
}
public static final void registerRenders() { }
private static final Block registerBlock(String n, Block {
ResourceLocation r = new ResourceLocation(ModInfo.MODID, n);
b.setUnlocalizedName(n);
b.setRegistryName(r);
b.setCreativeTab(MBM_Tabs.tabMissingBlocks);
GameRegistry.register(b);
MBM_Items.registerItem(new ItemBlock(b), n);
blocks.add(b);
return b;
}
}
and here is the class for my walls:
public class WoolenWalls extends BlockWall {
public WoolenWalls(Block {
super(b);
this.useNeighborBrightness = true;
this.setSoundType(SoundType.CLOTH);
this.setHardness(0.8F).setResistance(4.0F);
}
public boolean canPlaceTorchOnTop(IBlockState state, IBlockAccess world, BlockPos pos) {
if (state.isSideSolid(world, pos, EnumFacing.UP)) {
return true;
}
return this instanceof WoolenWalls;
}
public boolean isFullCube(IBlockState state) {
return false;
}
public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
return false;
}
public boolean isOpaqueCube(IBlockState state) {
return false;
}
private boolean canConnectTo(IBlockAccess worldIn, BlockPos pos) {
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
//*******_STILL NOT WORKING RIGHT_********
if (((block instanceof BlockFenceGate)) || (block == Blocks.COBBLESTONE_WALL) || (block == ModInfo.blockWoolColoredWhiteWall) || ( block == ModInfo.blockWoolColoredYellowWall)) {
return true;
}
return true;
}
}
the walls are the only block showing up twice here is a screenshot in Minecraft of what it is doing. All the block does not have .json files yet but the first one I finished was white and you can see in the image what I am talking about.
EDITED the image was shrunk down for some reason so here is a link to the image
I noticed that when i place my blocks next to each other it renders all sides even though some of the sides have blocks that covers them.
I tried this and it works as long as all the blocks are slabs, if I make them double slabs they draw all the sides again or if I place a full block next to them they draw all the sides again.
Note, for ItemStacks, they use the parameters like so...
Item item, int stackSize, int metadata
//Or
Block block, int stackSize, int metadata
Thanks! I found out I needed to change my statement around a little for it to work with metadata blocks. this is what I ended up with for those that would like to know.
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 0), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 0)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 1), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 1)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 2), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 2)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 3), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 3)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 4), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 4)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 5), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 5)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 6), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 6)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 7), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 7)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab2, 6, 8), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 8)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab2, 6, 9), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 9)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab2, 6, 10), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 10)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab2, 6, 11), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 11)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab2, 6, 12), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 12)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab2, 6, 13), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 13)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab2, 6, 14), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 14)});
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab2, 6, 15), new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 15)});
I changed:
new Object[] {"###", '#', Blocks.stained_glass}); to new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 15)}); // Black where the 15 is that is the metadata variable.
Hi I just started out with modding my self. if you do a search on youtube for scratchforfun, or letsmodreboot by palimar you can get some good video tutorials. also http://www.minecraftforge.net/wiki/Tutorials has some good tutorial also.
Why people just can't look up the code in the vanilla's source? I always look it up if I don't know what it is.
If you extend a class with an other for example Block your class will be able to override the Block's methods.
Some people are new to minecraft modding and do not understand what each method actually does. I do not see why people have to write grip posts instead of writing something that will actually help some one out. it just as easy to post something usefull as it is to post a useless topic like this reply or your last post
Hi could someone help me figure this out? I have a class that creates stained glass half slabs and double slabs. I am just trying to register the recipes for the half slabs. Here is my block class for them.
BlockMBStainedGlassSlabs.java
// Code Based off of https://github.com/Glitchfiend/BiomesOPlenty
// Render Code based off of Minecraft ideal given by mathew_653
package missingblocks.common.blocks;
import java.util.List;
import java.util.Random;
import missingblocks.api.content.MBCBlocks;
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.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class BlockMBStainedGlassSlabs extends BlockSlab{
public static enum StainedGlassSlabCategory{
SGLASS1, SGLASS2;
}
private static final String[] sGlassTypes = new String[] {"glass_white", "glass_orange", "glass_magenta", "glass_light_blue", "glass_yellow",
"glass_lime", "glass_pink", "glass_gray", "glass_silver", "glass_cyan", "glass_purple", "glass_blue", "glass_brown", "glass_green", "glass_red", "glass_black"};
private IIcon[] textures;
private final StainedGlassSlabCategory category;
public BlockMBStainedGlassSlabs(boolean isDoubleSlab, Material material, StainedGlassSlabCategory cat){
super(isDoubleSlab, material);
category = cat;
this.setHardness(0.3F);
this.setResistance(1.5F);
this.setHarvestLevel("", 0);
this.setStepSound(Block.soundTypeGlass);
this.useNeighborBrightness = true;
if (!isDoubleSlab){
this.setCreativeTab(CreativeTabs.tabBlock);
}
}
@Override
public void registerBlockIcons(IIconRegister iconRegister){
textures = new IIcon[sGlassTypes.length];
for (int i = 0; i < sGlassTypes.length; ++i){
textures[i] = iconRegister.registerIcon("minecraft:"+ sGlassTypes[i]);
}
}
@Override
public IIcon getIcon(int side, int meta){
return textures[getGlassType(meta)];
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void getSubBlocks(Item block, CreativeTabs creativeTabs, List list){
int max = 0;
if (category == StainedGlassSlabCategory.SGLASS1) {
max = 8;
}
else if (category == StainedGlassSlabCategory.SGLASS2) {
max = 8;
}
for (int i = 0; i < max; ++i) {
list.add(new ItemStack(block, 1, i));
}
}
@Override
public String func_150002_b(int meta){
if (category == StainedGlassSlabCategory.SGLASS1){
return (new StringBuilder()).append(sGlassTypes[getGlassType(meta)]).append("Slab").toString();
}
else if (category == StainedGlassSlabCategory.SGLASS2){
return (new StringBuilder()).append(sGlassTypes[getGlassType(meta)]).append("Slab").toString();
}
else {
return null;
}
}
@Override
public int damageDropped(int meta){
return meta & 7;
}
protected boolean canSilkHarvest(){
return true;
}
@Override
public Item getItemDropped(int metadata, Random random, int fortune){
if (field_150004_a){
if (this == MBCBlocks.glassStainedDoubleSlab1)
return Item.getItemFromBlock(MBCBlocks.glassStainedSingleSlab1);
else
return Item.getItemFromBlock(MBCBlocks.glassStainedSingleSlab2);
}
else
return Item.getItemFromBlock(this);
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z){
Block block = !field_150004_a ? this : (this == MBCBlocks.glassStainedDoubleSlab1 ? MBCBlocks.glassStainedSingleSlab1 : (this == MBCBlocks.glassStainedDoubleSlab2 ? MBCBlocks.glassStainedSingleSlab2 : MBCBlocks.stoneSingleSlab));
return new ItemStack(block, 1, world.getBlockMetadata(x, y, z));
}
@Override
protected ItemStack createStackedBlock(int meta){
if (this == MBCBlocks.glassStainedDoubleSlab1){
return new ItemStack(MBCBlocks.glassStainedSingleSlab1, 2, meta);
} else if (this == MBCBlocks.glassStainedDoubleSlab2){
return new ItemStack(MBCBlocks.glassStainedSingleSlab2, 2, meta);
} else if (this == MBCBlocks.glassStainedSingleSlab1){
return new ItemStack(MBCBlocks.glassStainedSingleSlab1, 1, meta);
} else if (this == MBCBlocks.glassStainedSingleSlab2){
return new ItemStack(MBCBlocks.glassStainedSingleSlab2, 1, meta);
} else
// return new ItemStack(this, 2, meta);
return null;
}
public int getRenderBlockPass(){
return 1;
}
private int getGlassType(int meta){
meta = getTypeFromMeta(meta) + category.ordinal() * 8;
if (meta < sGlassTypes.length)
return meta;
return 0;
}
private static int getTypeFromMeta(int meta){
return meta & 7;
}
public boolean isOpaqueCube(){
return false;
}
public boolean renderAsNormalBlock(){
return false;
}
public int quantityDropped(Random p_149745_1_){
return 0;
}
}
Here is my custom Itemblock class
// Code Based off of https://github.com/Glitchfiend/BiomesOPlenty
package missingblocks.common.itemblocks;
import missingblocks.common.blocks.BlockMBStainedGlassSlabs;
import net.minecraft.block.Block;
import net.minecraft.item.ItemSlab;
import net.minecraft.item.ItemStack;
public class ItemBlockMBStainedGlassSlabs extends ItemSlab{
public ItemBlockMBStainedGlassSlabs(Block block, BlockMBStainedGlassSlabs singleSlab, BlockMBStainedGlassSlabs doubleSlab){
super(block, singleSlab, doubleSlab, block == doubleSlab);
}
@Override
public int getMetadata(int meta){
return meta & 7;
}
@Override
public String getUnlocalizedName(ItemStack itemStack){
BlockMBStainedGlassSlabs slab = (BlockMBStainedGlassSlabs)Block.getBlockFromItem(itemStack.getItem());
return super.getUnlocalizedName() + "." + (new StringBuilder()).append(slab.func_150002_b(itemStack.getItemDamage())).toString();
}
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
}
and this is how I am calling / registering the blocks.
I need to figure out how to call each color so I can add a line like this to the crafting class
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 0), new Object[] {"###", '#', Blocks.stained_glass});
if i just do that it does not matter what color of glass blocks I have it will only produce white slabs. because of the 6, 0 the 0 being the meta data. I tried something like this but it does not work either
if (BlockMBStainedGlassSlabs.getBlockFromName("tile.glassStainedSingleSlab1.glass_whiteSlab.name") != null)
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 0), new Object[] {"###", '#', Blocks.stained_glass});
else
GameRegistry.addRecipe(new ItemStack(MBCBlocks.glassStainedSingleSlab1, 6, 3), new Object[] {"###", '#', Blocks.stained_glass});
it always comes up as blue slabs because the getBlockName is either false I do not know how to call the meta or name I think a select case statement would be better than a bunch of if else statements.
If anyone could help me here it would be very appreciated.
Hey, Ive created these half slabs but for some reason the half slabs dont stack on top of each other. can someone help me? i would really appreciate it, sincerely killerjdog51.
package com.chocolatemod.block;
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.ItemStack;
import net.minecraft.world.World;
public class BlockWhiteChocolateSmallBrickSlab extends BlockSlab
{
public static final String[] woodType = { "smallwhitechocolatebricks" };
public BlockWhiteChocolateSmallBrickSlab(int par1, boolean par2)
{
super(par2, Material.rock);
}
public void registerIcons(IIconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("killerjdog51:chocolatebrick_white_small");
}
public Block idDropped(int par1, Random par2Random, int par3)
{
return Blocks.smallwhitechocolatebricksingle;
}
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
{
if(par1World.getBlock(par2, par3 - 1, par4) == Blocks.smallwhitechocolatebricksingle)
{
par1World.setBlock(par2, par3, par4, null, 0, par4);
par1World.setBlock(par2, par3 - 1, par4, Blocks.smallwhitechocolatebrickdouble);
}
if(par1World.getBlock(par2, par3 + 1, par4) == Blocks.smallwhitechocolatebricksingle)
{
par1World.setBlock(par2, par3, par4, null, 0, par4);
par1World.setBlock(par2, par3 + 1, par4, Blocks.smallwhitechocolatebrickdouble);
}
}
protected ItemStack createStackedBlock(int par1)
{
return new ItemStack(Blocks.smallwhitechocolatebricksingle, 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 par1, CreativeTabs par2CreativeTabs, List par3List)
{
if (par1 != Blocks.smallwhitechocolatebrickdouble)
{
par3List.add(new ItemStack(par1, 1, 0));
}
}
@Override
public String func_150002_b(int var1) {
// TODO Auto-generated method stub
return null;
}
}
I had the same problem I could not get them to stack either and I searched the forums and found some code that a guys said you need something like it but when I went to stack the slabs it crashed minecraft people told me I was not initializing a field, but would not explain how I was not initializing it. and ever since I voiced my opinion about them just saying one or 2 word examples but not explaining why they say that no one has answered any of my posts since. But anyway if you download this:
and look through there code you can see how they made their slabs stack. most of the 1.7 mods that gives you new slabs they don't stack either. But to save you some time if you check out my post here you can see the classes you need to make the slabs stack.
public boolean renderAsNormalBlock() {
return false;
}
Thanks I added the code you suggested and it took care of the bug that let you see through the world. But I am still having problems with the slabs and double slabs rendering the textures right. Here is an image of the problem.
as you can see on the left is the texture of the full block and the 2 on the right is the slab and double slab not rendering the texture right. the resource pack here is datacraft64 for 1.7.10. if I use the default textures the slab and double slabs show up as clear glass with colored highlights as in this image.
as you can see the stained glass textures on the left and it not rendering right on the right
Maybe, but I think that would just create a new class that is different, but would not override the old one.
However I have found the solution online, you can override existing events (which is what I wanted) via the Forge Event Bus system (for anyone who's interested click here.)
But thanks for the replies anyway
- PrinceCJC
Is it not exactly what Beamfield told you to to do? override the existing methods/events as you called them
Hello. Would anyone know why my glass slabs are not rendering right?
any ideals on how to fix these:
Known Bugs:
1 Textures not rendering right, it's ugly and opaque depending on texture pack being used.
2 When placed as a double slab on the ground you can see through the world. 3 When double slabs are broken with silk touch pick it gives 2 double slabs instead of 2 single slabs and when a half slab is broken with silk touch it gives 2 half slabs instead of 1 half slab..
4 When broken by hand or any tool it gives back 2 single slabs instead of just destroying the block.
Screenshot of the problem.
EDIT: How come the image does not show up but you can right click and say open image in new tab?
I think I need to somehow call something like Blocks.glass in my arguments but I do not know how to incorporate it into the class I added the parameters but it did not seem to work I guess I needed to cal the parameters some place else also.
/*
* Known Bugs:
* Textures not rendering right, it's ugly and opaque depending on texture pack being used.
* When placed as a double slab on the ground you can see through the world.
* When broken with silk touch it gives 2 double slabs instead of 2 single slabs.
* When broken by hand or any tool it gives back 2 single slabs instead of just destroying the block.
*/
0
Bump No one has any advice for me on this? So no one can help me with this issue?
0
Hello I was wondering if anyone might know why I am getting 2 walls showing up in Minecraft when my system.out.println say only one of each block is getting created.
and here is the class for my walls:
the walls are the only block showing up twice here is a screenshot in Minecraft of what it is doing. All the block does not have .json files yet but the first one I finished was white and you can see in the image what I am talking about.
EDITED the image was shrunk down for some reason so here is a link to the image
Duplicate Blocks
any help would be greatly appreciated
Thanks In Advanced
0
Awesome job folks! this was one of the mods that i bought minecraft for I am glad to see if have been updated. Thank you.
0
I tried this and it works as long as all the blocks are slabs, if I make them double slabs they draw all the sides again or if I place a full block next to them they draw all the sides again.
0
Thanks! I found out I needed to change my statement around a little for it to work with metadata blocks. this is what I ended up with for those that would like to know.
new Object[] {"###", '#', Blocks.stained_glass}); to new Object[] {"###", '#', new ItemStack(Blocks.stained_glass, 1, 15)}); // Black where the 15 is that is the metadata variable.
0
0
Some people are new to minecraft modding and do not understand what each method actually does. I do not see why people have to write grip posts instead of writing something that will actually help some one out. it just as easy to post something usefull as it is to post a useless topic like this reply or your last post
0
BlockMBStainedGlassSlabs.java
Here is my custom Itemblock class
if i just do that it does not matter what color of glass blocks I have it will only produce white slabs. because of the 6, 0 the 0 being the meta data. I tried something like this but it does not work either
it always comes up as blue slabs because the getBlockName is either false I do not know how to call the meta or name I think a select case statement would be better than a bunch of if else statements.
If anyone could help me here it would be very appreciated.
0
I added this when I was having the same problems
0
to this
and fixed bug 4 by adding
0
0
I had the same problem I could not get them to stack either and I searched the forums and found some code that a guys said you need something like it but when I went to stack the slabs it crashed minecraft people told me I was not initializing a field, but would not explain how I was not initializing it. and ever since I voiced my opinion about them just saying one or 2 word examples but not explaining why they say that no one has answered any of my posts since. But anyway if you download this:
https://github.com/Glitchfiend/BiomesOPlenty
and look through there code you can see how they made their slabs stack. most of the 1.7 mods that gives you new slabs they don't stack either. But to save you some time if you check out my post here you can see the classes you need to make the slabs stack.
http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2217140-blocks-not-rendering-right
0
Thanks I added the code you suggested and it took care of the bug that let you see through the world. But I am still having problems with the slabs and double slabs rendering the textures right. Here is an image of the problem.
0
Is it not exactly what Beamfield told you to to do? override the existing methods/events as you called them
0
any ideals on how to fix these:
Known Bugs:
1
Textures not rendering right, it's ugly and opaque depending on texture pack being used.2
When placed as a double slab on the ground you can see through the world.3 When double slabs are broken with silk touch pick it gives 2 double slabs instead of 2 single slabs and when a half slab is broken with silk touch it gives 2 half slabs instead of 1 half slab..4
When broken by hand or any tool it gives back 2 single slabs instead of just destroying the block.Screenshot of the problem.
EDIT: How come the image does not show up but you can right click and say open image in new tab?
I think I need to somehow call something like Blocks.glass in my arguments but I do not know how to incorporate it into the class I added the parameters but it did not seem to work I guess I needed to cal the parameters some place else also.
here is the code I am using ATM.
BlockMBStainedGlassSlabs.java
/*
* Known Bugs:
* Textures not rendering right, it's ugly and opaque depending on texture pack being used.
* When placed as a double slab on the ground you can see through the world.
* When broken with silk touch it gives 2 double slabs instead of 2 single slabs.
* When broken by hand or any tool it gives back 2 single slabs instead of just destroying the block.
*/
package missingblocks.common.blocks;
import java.util.List;
import java.util.Random;
import missingblocks.api.content.MBCBlocks;
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.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class BlockMBStainedGlassSlabs extends BlockSlab{
public static enum StainedGlassSlabCategory{
SGLASS1, SGLASS2;
}
private static final String[] sGlassTypes = new String[] {"glass_white", "glass_orange", "glass_magenta", "glass_light_blue", "glass_yellow",
"glass_lime", "glass_pink", "glass_gray", "glass_silver", "glass_cyan", "glass_purple", "glass_blue", "glass_brown", "glass_green", "glass_red", "glass_black"};
private IIcon[] textures;
private final StainedGlassSlabCategory category;
public BlockMBStainedGlassSlabs(boolean isDoubleSlab, Material material, StainedGlassSlabCategory cat){
super(isDoubleSlab, material);
category = cat;
this.setHardness(0.3F);
this.setResistance(1.5F);
this.setHarvestLevel("", 0);
this.setStepSound(Block.soundTypeGlass);
this.useNeighborBrightness = true;
if (!isDoubleSlab){
this.setCreativeTab(CreativeTabs.tabBlock);
}
}
@Override
public void registerBlockIcons(IIconRegister iconRegister){
textures = new IIcon[sGlassTypes.length];
for (int i = 0; i < sGlassTypes.length; ++i){
textures = iconRegister.registerIcon("minecraft:"+ sGlassTypes);
}
}
@Override
public IIcon getIcon(int side, int meta){
return textures[getGlassType(meta)];
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void getSubBlocks(Item block, CreativeTabs creativeTabs, List list){
int max = 0;
if (category == StainedGlassSlabCategory.SGLASS1) {
max = 8;
}
else if (category == StainedGlassSlabCategory.SGLASS2) {
max = 8;
}
for (int i = 0; i < max; ++i) {
list.add(new ItemStack(block, 1, i));
}
}
@Override
public String func_150002_b(int meta){
if (category == StainedGlassSlabCategory.SGLASS1){
return (new StringBuilder()).append(sGlassTypes[getGlassType(meta)]).append("Slab").toString();
}
else if (category == StainedGlassSlabCategory.SGLASS2){
return (new StringBuilder()).append(sGlassTypes[getGlassType(meta)]).append("Slab").toString();
}
else {
return null;
}
}
@Override
public int damageDropped(int meta){
return meta & 7;
}
@Override
public Item getItemDropped(int metadata, Random random, int fortune){
if (field_150004_a){
if (this == MBCBlocks.glassStainedDoubleSlab1)
return Item.getItemFromBlock(MBCBlocks.glassStainedSingleSlab1);
else
return Item.getItemFromBlock(MBCBlocks.glassStainedSingleSlab2);
}
else
return Item.getItemFromBlock(this);
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z){
Block block = !field_150004_a ? this : (this == MBCBlocks.glassStainedDoubleSlab1 ? MBCBlocks.glassStainedSingleSlab1 : (this == MBCBlocks.glassStainedDoubleSlab2 ? MBCBlocks.glassStainedSingleSlab2 : MBCBlocks.stoneSingleSlab));
return new ItemStack(block, 1, world.getBlockMetadata(x, y, z));
}
@Override
protected ItemStack createStackedBlock(int meta){
return new ItemStack(this, 2, meta);
}
private int getGlassType(int meta){
meta = getTypeFromMeta(meta) + category.ordinal() * 8;
if (meta < sGlassTypes.length)
return meta;
return 0;
}
private static int getTypeFromMeta(int meta){
return meta & 7;
}
}