Jump to content

1.12 Make block face the direction i'm facing


Artsicle

Recommended Posts

I know how to do this in 1.10 I think but 

    /*@Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
            ItemStack stack) {
        super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
    }*/

I'm not used to that method ^

I'm used to 

/*@Override
public IBlockState onBlockPlaced*/

but that's not in 1.12.

I tried doing 

super.onBlockPlacedBy(worldIn, pos, state.withProperty(FACING, placer.getHorizontalFacing()), placer, stack);

But that didnt work.

If anyone knows please reply.

Link to comment
Share on other sites

Thanks, I got it!

(For those who want to know, here is the code)

	@Override
	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
			float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
		return super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand).withProperty(FACING, placer.getHorizontalFacing());
	}

 

  • Like 2
Link to comment
Share on other sites

  • 5 months later...

It seems there are a number events/methods used when a block is placed:

 

canPlaceBlockOnSide

getStateForPlacement

onBlockPlacedBy

 

Are there any more? Are these always called in this order? I have a block where I want to remember the TE against which the block was placed - let's call it targetTE - (so it can act as an interface to that targetTE). I implemented canPlaceBlockOnSide to verify that the user actually clicked a TE and not a regular block; e.g. it returns false if you try to place the block against dirt but true if you place the block (shift-click) against a chest. I implemented getStateForPlacement to rotate my block the correct way to face the targetTE. I believe both methods are called before the block is actually placed. I also implemented neighborChanged to break (and drop) my block if the targetTE is removed.

 

Which method would be the best method to store the targetTE? onBlockPlacedBy doesn't provide the EnumFacing I need to find the block (and TE) the user clicked.

Should I store the targetTE or determine it every time I need it (using my blocks PropertyDirection) - which may be every tick?

 

I couldn't find any documentation on the order of events for placing a block - is there any?

Link to comment
Share on other sites

  • 5 months later...
On 9/25/2017 at 8:09 AM, Artsicle said:

Thanks, I got it!

(For those who want to know, here is the code)


	@Override
	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
			float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
		return super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand).withProperty(FACING, placer.getHorizontalFacing());
	}

 

"FACING" is not a thing

Link to comment
Share on other sites

57 minutes ago, Zeltron said:

"FACING" is not a thing

It is if your block has that property.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

1 hour ago, Zeltron said:

"FACING" is not a thing

Please no necroposting this thread is over a year old, make your own thread.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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