I've been working on a mod for a bit and I've made a custom slab but it won't seem to place on the top of a block and only the bottom unlike a normal slab.
if (soundType == "gravel") {
setStepSound(soundTypeGravel);
} else if (soundType == "stone") {
setStepSound(soundTypeStone);
} else if (soundType == "wool") {
setStepSound(soundTypeCloth);
} else if (soundType == "glass") {
setStepSound(soundTypeGlass);
} else if (soundType == "grass") {
setStepSound(soundTypeGrass);
} else if (soundType == "anvil") {
setStepSound(soundTypeAnvil);
} else if (soundType == "ladder") {
setStepSound(soundTypeLadder);
} else if (soundType == "metal") {
setStepSound(soundTypeMetal);
} else if (soundType == "piston") {
setStepSound(soundTypePiston);
} else if (soundType == "wood") {
setStepSound(soundTypeWood);
} else if (soundType == "sand") {
setStepSound(soundTypeSand);
} else if (soundType == "snow") {
setStepSound(soundTypeSnow);
} else {
}
}
@Override
public boolean isOpaqueCube() {
return false;
}
@SideOnly(Side.CLIENT)
public Item getItem(World wrld, int x, int y, int z) {
return Item
.getItemFromBlock(SimplyPathsBlocks.blockFastestMovingSlabPath);
}
/**
* Gets the block's texture. Args: side, meta
*/
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {
if (meta == 0 && side == 1)
return pathTop0;
if (meta == 1 && side == 1)
return pathTop1;
if (meta == 2 && side == 1)
return pathTop2;
if (meta == 3 && side == 1)
return pathTop3;
return blockIcon;
}
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z,
Entity entity) {
Entity p = entity;
if (world.getBlockMetadata(x, y, z) == 0) {
p.motionZ += -0.65F;
if (p.motionZ < -0.65F) {
p.motionZ = -0.65F;
}
} else if (world.getBlockMetadata(x, y, z) == 1) {
p.motionX += 0.65F;
if (p.motionX > 0.65F) {
p.motionX = 0.65F;
}
} else if (world.getBlockMetadata(x, y, z) == 2) {
p.motionZ += 0.65F;
if (p.motionZ > 0.65F) {
p.motionZ = 0.65F;
}
} else if (world.getBlockMetadata(x, y, z) == 3) {
p.motionX += -0.65F;
if (p.motionX < -0.65F) {
p.motionX = -0.65F;
}
}
}
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4,
EntityLivingBase par5EntityLiving, ItemStack par6ItemStack) {
int l = MathHelper
.floor_double((double) (par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
}
@Override
public String func_150002_b(int var1) {
return super.getUnlocalizedName();
}
/**
* Updates the blocks bounds based on its current state. Args: world, x, y,
* z
*/
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_,
int p_149719_2_, int p_149719_3_, int p_149719_4_) {
if (this.field_150004_a) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
} else {
boolean flag = (p_149719_1_.getBlockMetadata(p_149719_2_,
p_149719_3_, p_149719_4_) & 8) != 0;
/**
* Sets the block's bounds for rendering it as an item
*/
public void setBlockBoundsForItemRender() {
if (this.field_150004_a) {
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 p_149743_1_, int p_149743_2_,
int p_149743_3_, int p_149743_4_, AxisAlignedBB p_149743_5_,
List p_149743_6_, Entity p_149743_7_) {
this.setBlockBoundsBasedOnState(p_149743_1_, p_149743_2_, p_149743_3_,
p_149743_4_);
super.addCollisionBoxesToList(p_149743_1_, p_149743_2_, p_149743_3_,
p_149743_4_, p_149743_5_, p_149743_6_, p_149743_7_);
}
}
If any of you happen to have any idea why this is so, please help! Thanks!
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4,
EntityLivingBase par5EntityLiving, ItemStack par6ItemStack) {
int l = MathHelper
.floor_double((double) (par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
}
The vanilla BlockSlab placement code already uses metadata.
You should take the previous metadata into account.
And remove the code copied from BlockSlab. Inheritance is here to help you.
Here is my slab code:
package com.momnop.simplypaths.blocks;
import java.util.List;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import com.momnop.simplypaths.SimplyPathsCreativeTab;
import com.momnop.simplypaths.info.ModInfo;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockMovingFastestSlabPath extends BlockSlab {
@SideOnly(Side.CLIENT)
private IIcon pathTop0;
@SideOnly(Side.CLIENT)
private IIcon pathTop1;
@SideOnly(Side.CLIENT)
private IIcon pathTop2;
@SideOnly(Side.CLIENT)
private IIcon pathTop3;
public BlockMovingFastestSlabPath(Material material,
String unlocalizedName, String soundType, float hardness,
int harvestLevel, String toolType, boolean doubleSlab) {
super(doubleSlab, material);
setCreativeTab(SimplyPathsCreativeTab.INSTANCE);
setLightOpacity(255);
setHardness(hardness);
setHarvestLevel(toolType, harvestLevel);
setBlockName(unlocalizedName);
useNeighborBrightness = true;
if (soundType == "gravel") {
setStepSound(soundTypeGravel);
} else if (soundType == "stone") {
setStepSound(soundTypeStone);
} else if (soundType == "wool") {
setStepSound(soundTypeCloth);
} else if (soundType == "glass") {
setStepSound(soundTypeGlass);
} else if (soundType == "grass") {
setStepSound(soundTypeGrass);
} else if (soundType == "anvil") {
setStepSound(soundTypeAnvil);
} else if (soundType == "ladder") {
setStepSound(soundTypeLadder);
} else if (soundType == "metal") {
setStepSound(soundTypeMetal);
} else if (soundType == "piston") {
setStepSound(soundTypePiston);
} else if (soundType == "wood") {
setStepSound(soundTypeWood);
} else if (soundType == "sand") {
setStepSound(soundTypeSand);
} else if (soundType == "snow") {
setStepSound(soundTypeSnow);
} else {
}
}
@Override
public boolean isOpaqueCube() {
return false;
}
@SideOnly(Side.CLIENT)
public Item getItem(World wrld, int x, int y, int z) {
return Item
.getItemFromBlock(SimplyPathsBlocks.blockFastestMovingSlabPath);
}
/**
* Gets the block's texture. Args: side, meta
*/
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {
if (meta == 0 && side == 1)
return pathTop0;
if (meta == 1 && side == 1)
return pathTop1;
if (meta == 2 && side == 1)
return pathTop2;
if (meta == 3 && side == 1)
return pathTop3;
return blockIcon;
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister register) {
this.blockIcon = register.registerIcon("diamond_block");
this.pathTop0 = register.registerIcon(ModInfo.MODID + ":"
+ "conveyorPath" + "_top0");
this.pathTop1 = register.registerIcon(ModInfo.MODID + ":"
+ "conveyorPath" + "_top1");
this.pathTop2 = register.registerIcon(ModInfo.MODID + ":"
+ "conveyorPath" + "_top2");
this.pathTop3 = register.registerIcon(ModInfo.MODID + ":"
+ "conveyorPath" + "_top3");
}
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z,
Entity entity) {
Entity p = entity;
if (world.getBlockMetadata(x, y, z) == 0) {
p.motionZ += -0.65F;
if (p.motionZ < -0.65F) {
p.motionZ = -0.65F;
}
} else if (world.getBlockMetadata(x, y, z) == 1) {
p.motionX += 0.65F;
if (p.motionX > 0.65F) {
p.motionX = 0.65F;
}
} else if (world.getBlockMetadata(x, y, z) == 2) {
p.motionZ += 0.65F;
if (p.motionZ > 0.65F) {
p.motionZ = 0.65F;
}
} else if (world.getBlockMetadata(x, y, z) == 3) {
p.motionX += -0.65F;
if (p.motionX < -0.65F) {
p.motionX = -0.65F;
}
}
}
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4,
EntityLivingBase par5EntityLiving, ItemStack par6ItemStack) {
int l = MathHelper
.floor_double((double) (par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
}
@Override
public String func_150002_b(int var1) {
return super.getUnlocalizedName();
}
/**
* Updates the blocks bounds based on its current state. Args: world, x, y,
* z
*/
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_,
int p_149719_2_, int p_149719_3_, int p_149719_4_) {
if (this.field_150004_a) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
} else {
boolean flag = (p_149719_1_.getBlockMetadata(p_149719_2_,
p_149719_3_, p_149719_4_) & 8) != 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.field_150004_a) {
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 p_149743_1_, int p_149743_2_,
int p_149743_3_, int p_149743_4_, AxisAlignedBB p_149743_5_,
List p_149743_6_, Entity p_149743_7_) {
this.setBlockBoundsBasedOnState(p_149743_1_, p_149743_2_, p_149743_3_,
p_149743_4_);
super.addCollisionBoxesToList(p_149743_1_, p_149743_2_, p_149743_3_,
p_149743_4_, p_149743_5_, p_149743_6_, p_149743_7_);
}
}
If any of you happen to have any idea why this is so, please help! Thanks!
-TBA-
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4,
EntityLivingBase par5EntityLiving, ItemStack par6ItemStack) {
int l = MathHelper
.floor_double((double) (par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
}
The vanilla BlockSlab placement code already uses metadata.
You should take the previous metadata into account.
And remove the code copied from BlockSlab. Inheritance is here to help you.