Help with detecting items in an area

Discussion in 'Plugin Development' started by nateracecar5, Jun 14, 2014.

?

Do you think this mod will be good?

  1. Yes

    100.0%
  2. No

    0 vote(s)
    0.0%
  3. It depends on the quality

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. Offline

    nateracecar5

    We all have heard of the witchery mod right? Well, in this mod you have chalk, and you make circles to do circle magic. You put items in the circle, and when you click on the center rune, it will activate the rite.

    What I'm trying to do is build an "altar" and you drop items on the altar to perform a sacrifice. That sacrifice will give you a book which appears on the altar. The "book" is a spell which you can perform and it will do cool things. I know how to do the spell part, but I don't know where to start with the item detection. I also want the player to do a command, and any altar within 10 blocks will activate. I don't know how to do that either.

    This is what the altar will look like, not that it will matter. I want the altar to detect when the correct items are on the netherrack, or within 2 blocks from it. The altar will and can be made anywhere in the world, so that is my problem. Also, the catch is that the altar has to be built exactly as specified. Any minor difference will cause the altar to damage the user when performing a sacrifice. Any help will be appreciated. :)

    [​IMG]
     
  2. Offline

    xTigerRebornx

    nateracecar5 Some possibilities
    1: Use World#getEntities(), loop through, and use Entity#distanceSquared() (to avoid using sqrt()) to check if they are x-squared away from your 'click' location.
    2: Temporarily spawn an Entity (something like a bat will work well), make it invisible, then use Entity#getNearbyEntities() to get the nearby entities and check from the collection returned, then remove the bat once you are done using it.
     
  3. Offline

    nateracecar5

    That might work. I have an idea about what you mean for the 1st possibility, but no idea what you mean for the 2nd. Could you give me an example for the first example, then if you can, and example for the 2nd? Thanks!
    xTigerRebornx
     
  4. Offline

    Garris0n

    xTigerRebornx That second one seems rather pointless and awkward, just looping through would work fine.

    @OP Loop through each entity. Use entity.getLocation().distanceSquared(someOtherLocation) to get the distance (squared) from that entity to the other location. The simplest way to do this would be to use Collections.min(), providing it with a comparator that checks the distances (squared).
     
  5. Offline

    nateracecar5

    Garris0n Okay, that makes sense I guess. One question though. I haven't ever manipulated entities before, and don't know what entity.getLocation().distanceSquared(someOtherLocatoin) does. I know for a fact that entity has to be defined as a variable. I'm guessing you would define it as "Entity entity = <the entity>;". What would be the entity? And what would be "someOtherLocation"? Just some random location? And I don't know what this Collections.min() thing is. The docs page was very hard to read.

    In other words: I am still VERY confused...
    Also, I need to test if the items are within 2 blocks of the altar, which I'm guessing means testing for a structure around the selected entities.

    Maybe it would be easier to test for the items in a chest, with a sign that says "[Altar]" on the front.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  6. Offline

    nateracecar5

Thread Status:
Not open for further replies.

Share This Page