Hello there. So I've been all over the internet trying to find a way to rotate blocks, I've gone up and down forums, watched videos and still can't manage to get it to work. I think I'm closest I've gotten right now but my game still keeps crashing. I was wondering if I could get any help. Thanks!
Here's my block class
package com.anything_atall.moreswordsmod.blocks;
import com.anything_atall.moreswordsmod.Main;
import com.anything_atall.moreswordsmod.init.ModBlocks;
import com.anything_atall.moreswordsmod.init.ModItems;
import com.anything_atall.moreswordsmod.util.IHasModel;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class StarTrekReliantPainting extends BlockBase implements IHasModel
{
public static final AxisAlignedBB CANDY_CANE = new AxisAlignedBB(0.4375D, 0.0D, 0.0625D, 0.5625D, 1.0D, 0.9375D);
public static final AxisAlignedBB CANDY_CANE_WE = new AxisAlignedBB(0.0625D, 0.0D, 0.4375D, 0.9375D, 1.0D, 0.5625D);
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); {
this.setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
}
public StarTrekReliantPainting(String name)
{
super(name, Material.ANVIL);
setCreativeTab(Main.tabCreativeTabStartrek);
}
@Override
public IBlockState getStateFromMeta(int meta)
{
EnumFacing facing = EnumFacing.getFront(meta);
if(facing.getAxis()==EnumFacing.Axis.Y)
{
facing=EnumFacing.NORTH;
}
return getDefaultState().withProperty(FACING, facing);
}
@Override
public int getMetaFromState(IBlockState state)
{
return ((EnumFacing) state.getValue(FACING)).getIndex();
}
@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[]{FACING});
}
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos,EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
private boolean canBlockStay(World worldIn, BlockPos pos)
{
return worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos, EnumFacing.UP);
}
@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) ? this.canBlockStay(worldIn, pos) : false;
}
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
if(!this.canBlockStay(worldIn, pos))
{
worldIn.setBlockToAir(pos);
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(ModBlocks.STARTREK_RELAINT_PAINTING));
}
}
@Override
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
@Override
public boolean isFullBlock(IBlockState state)
{
return false;
}
@Override
public boolean isFullCube(IBlockState state)
{
return false;
}
@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
switch(((EnumFacing)state.getValue(FACING)))
{
case SOUTH:
default:
return CANDY_CANE;
case NORTH:
return CANDY_CANE;
case EAST:
return CANDY_CANE_WE;
case WEST:
return CANDY_CANE_WE;
}
}
}
Hello there. So I've been all over the internet trying to find a way to rotate blocks, I've gone up and down forums, watched videos and still can't manage to get it to work. I think I'm closest I've gotten right now but my game still keeps crashing. I was wondering if I could get any help. Thanks!
Here's my block class
And heres my blockstate
I should also note that I'm a beginner at Java so if you could explain in depth that'd be great!