Hi thereI
I'm new to mod creation and i'm having a problem.
I'm trying to create a chair who is facing the player when block is added.
I watched on Forge Anvil, furnace ... to success, and actualy my code work on client side, but not server side, the chair is replaced by the server when i place it.
Here is my code
public class zdermodBlockFacing extends Block {
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public boolean isOpaque = true;
public boolean isFacing = false;
@Override
public boolean isOpaqueCube(IBlockState iBlockState) {
return isOpaque;
}
public zdermodBlockFacing(String name, Material materialIn, float hardness, float resistance, int harvestLevel, String harvestType) {
super(materialIn);
setRegistryName(name).setUnlocalizedName(name);
setHardness(hardness);
setResistance(resistance);
setHarvestLevel(harvestType, harvestLevel);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
ModBlocks.INSTANCE.getBlocks().add(this);
setCreativeTab(mainClass.modtab);
// pickaxe ,axe, shovel
// 0 -> Pioche bois , 1-> Pierre, 2-> Fer, 3-> Diamant
}
@Override
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState();
}
@Override
public int getMetaFromState(IBlockState state) {
EnumFacing facing=state.getValue(FACING);
int meta=((EnumFacing)state.getValue(FACING)).getIndex();
return meta;
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] { FACING});
}
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
this.setDefaultFacing(worldIn, pos, state);
}
private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
IBlockState iblockstate = worldIn.getBlockState(pos.north());
IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
{
enumfacing = EnumFacing.SOUTH;
}
else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
{
enumfacing = EnumFacing.NORTH;
}
else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
{
enumfacing = EnumFacing.EAST;
}
else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
{
enumfacing = EnumFacing.WEST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
}
}
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
}
}
If someone can help me to understend what i missed this can be helpfull, i'm in love with minecraft modding forge is so powerfull !
PS: Sorry for my bad english i'm trying the best :)