Jump to content

Recommended Posts

Posted (edited)

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 by FiveShipHUN
Posted (edited)

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

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.