Posted November 4, 20187 yr 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!
November 4, 20187 yr 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.
November 5, 20187 yr Author 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.