Jump to content

Recommended Posts

Posted

I want to make a tile entity that can only input/output on certain sides, but any time I use the EnumFacing's it does the facing in relation to the world. I'm not sure how to get say the "right  side" of a block I place, and the capability that goes with it. A lot of this probably comes from the fact I don't fully understand how the code that makes the block place facing the player works in the first place. If anyone could explain these things or link me somewhere that does it would be greatly appreciated.

 

This is the code I have that makes it place facing the player. If you guys could hint how I make this only do horizontal that would also be helpful. I haven't worked with vectors or anything like that so I'm not sure how any of that works.

public class StorageBlockBase extends BlockBase{

public static final PropertyDirection FACING = PropertyDirection.create("facing");

public StorageBlockBase(String name, Material material, float hardness, float resistance) 
{
	super(name, material, hardness, resistance);
	this.isBlockContainer=true;
	setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
}
public StorageBlockBase(String name)
{
	this(name, Material.IRON, 0.5f, 0.5f);
}

@Override
public boolean hasTileEntity(IBlockState state)
    {
        return true;
    }
//This should  be overridden in every actual block code.
@Override
public TileEntity createTileEntity(World world, IBlockState state)
    {
	return null;
    }

/////////BEGIN CODE TO MAKE IT FACE TOWARDS THE PLAYER WHEN PLACED/////////
@Override
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
        world.setBlockState(pos, state.withProperty(FACING, getFacingFromEntity(pos, placer)), 2);
    }

public static EnumFacing getFacingFromEntity(BlockPos clickedBlock, EntityLivingBase entity) {
        return EnumFacing.getFacingFromVector(
             (float) (entity.posX - clickedBlock.getX()),
             0,//(float) (entity.posY - clickedBlock.getY()),
             (float) (entity.posZ - clickedBlock.getZ()));
    }

@Override
    public IBlockState getStateFromMeta(int meta) {
        return getDefaultState().withProperty(FACING, EnumFacing.getFront(meta & 7));
    }

    @Override
    public int getMetaFromState(IBlockState state) {
        return state.getValue(FACING).getIndex();
    }

    @Override
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, FACING);
    }
    /////////END CODE TO MAKE IT FACE TOWARDS THE PLAYER WHEN PLACED/////////
}

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Posted

EnumFacing rightSide = world.getBlockState(pos).getValue(FACING).rotate(Axis.UP);

 

There you go.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.