Posted February 2, 20205 yr I'd like to create a block which can be placed only in a village. Is there a way to find out whether the given coordinates/BlockPos is inside a village or not? This is my current code (not so much): @Override public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { if (!world.isRemote()) { } } (The uploaded file contains the code above.) EventSubscriber.java Edited February 2, 20205 yr by FiveShipHUN
February 2, 20205 yr Author Thanks the help! Here's the code @Override public void onBlockPlacedBy(World world, BlockPos pos1, BlockState state, LivingEntity placer, ItemStack stack) { if (!world.isRemote()) { ServerWorld w = world.getServer().getWorld(placer.dimension); BlockPos pos2 = w.findNearestStructure("Village", pos1, 100, false); if (pos2 == null) { destroyIt(world, pos1, state, placer, stack); return; } double i = pos1.getX() - pos2.getX(); double j = pos1.getZ() - pos2.getZ(); double d = MathHelper.sqrt((float) (i * i + j * j)); if (d > 100) { destroyIt(world, pos1, state, placer, stack); return; } } } private void destroyIt(World world, BlockPos pos1, BlockState state, LivingEntity placer, ItemStack stack) { if(placer instanceof PlayerEntity) { world.destroyBlock(pos1, !((PlayerEntity) placer).isCreative()); ((PlayerEntity) placer) .sendMessage(new TranslationTextComponent("block.cae.colony_table.placedInWrongPlace")); } } Edited February 2, 20205 yr by FiveShipHUN
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.