Jump to content

Recommended Posts

Posted

Apologies for the super-n00b question — but despite looking at the docs and checking out a few sample mod, I haven't been able to figure out how to get a mod to automatically place a block (in particular a `BlockStandingSign`) at a given `BlockPos`.

 

Would anyone have an example somewhere, or could point me to the relevant part of the Forge docs?

 

Thanks in advance!

Posted

World#setBlockState. For the flags parameter description refer to the javadoc on the method. To get the IBlockState you can use Block#getDefaultState and then change the properties(if needed) of that state.

  • Thanks 1
Posted
23 hours ago, V0idWa1k3r said:

World#setBlockState. For the flags parameter description refer to the javadoc on the method. To get the IBlockState you can use Block#getDefaultState and then change the properties(if needed) of that state.

Thanks.  I was on the right path, but it seems I probably had messed up my `BlockPos` calculation.

 

For posterity, here is what I finally came up with, which seems to work ok:

                World overworld = server.getWorld(0);

                BlockPos blockPosition = overworld.getSpawnPoint();
                logger.info("World: " + overworld.getClass());

                BlockPos tmp = blockPosition;
                while (!overworld.isAirBlock(tmp)) {
                    tmp = tmp.up();
                }

                Block blockStandingSign = Blocks.STANDING_SIGN;
                overworld.setBlockState(tmp, blockStandingSign.getDefaultState()
                        .withProperty(BlockStandingSign.ROTATION, 0));

                TileEntity tileEntity = overworld.getTileEntity(tmp);
                if (tileEntity instanceof TileEntitySign) {
                    TileEntitySign tileEntitySign = (TileEntitySign) tileEntity;
                    tileEntitySign.signText[0] = new TextComponentString("tychobrailleur");
                }

 

Happy to hear suggestions/improvement if any.

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.