Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.