Multi-Block Structure Detection

Discussion in 'Plugin Development' started by danik159, Jul 21, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    danik159

    I tried to do that when Player stands on this golden block in Multi-Block Structure it will give his a message, here is the code, but It didn't work, no errors ,nothing.
    https://pastebin.com/ef5gkdUn
    do you have any ideas how to fix it?

    Structure:
    https://imgur.com/a/vTLz5YA
    https://imgur.com/a/NbsT0K0

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 21, 2019
  2. Offline

    CraftCreeper6

    @danik159
    First of all, rather than checking every single block, why not check if they are stood on a gold block first, that would make more sense, and use many many less API calls.
    Second, could you not create a 3 dimensional array and cross check the blocks instead, seems so much easier and cleaner imo.

    Does the plugin load?
     
  3. Offline

    danik159

    1. I checked. ( Block block2 = block.getRelative(0, -1, 0); , block2.getType() == Material.GOLD_BLOCK)
    2.yes It loads

    th
    the problem is that if I use only 1 check it works fine, but if I add one more the plugin stops working.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 21, 2019
  4. Offline

    CraftCreeper6

    @danik159
    You're checking, correct, but you're initialising unnecessary variables.

    If the block beneath you is a dirt block then you've just initialised 16 variables for no reason, it's a waste of memory.

    Do:

    Code:
    block = blockAtPlayersFeet;
    
    if (block.type == Material.GOLD_BLOCK)
    {
          block1 = …
          block2 = …
          if (block1 && block2...)
          {
          }
    }
    What version are you running?
     
  5. Offline

    danik159

    1.12.2
     
  6. Offline

    CraftCreeper6

    @danik159

    Can you Bukkit.broadcastMessage(), block.getType().name() for each of the blocks and send me the result. In order of the blocks preferably.
     
  7. Offline

    danik159

    okey, wait a min

    Idk why it sent it twice.
    https://imgur.com/a/ju2OIKZ

    I found the problem, Block block13 = block.getRelative(-1, 0, 1);// end rod in this line the code should show end rode, but It shows stairs, and I dont know why

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 21, 2019
  8. Offline

    CraftCreeper6

    @danik159
    Block6 and Block14 have the same location
     
  9. Offline

    danik159

    Last edited by a moderator: Jul 21, 2019
  10. Offline

    CraftCreeper6

    @danik159
    Update the pastebin incase others have a similar problem.
     
  11. Offline

    danik159

  12. Offline

    CraftCreeper6

    @danik159
    I coded this, it's in an unfamiliar format for you, and very rudimentary, but it works, here are the coordinates that I used.

    Code:
    this.multiblock.add(new BlockType(0,0,0, Material.GOLD_BLOCK));
            this.multiblock.add(new BlockType(1,0,0, Material.QUARTZ_STAIRS));
            this.multiblock.add(new BlockType(-1,0,0, Material.QUARTZ_STAIRS));
            this.multiblock.add(new BlockType(0,0,1, Material.QUARTZ_STAIRS));
            this.multiblock.add(new BlockType(0,0,-1, Material.QUARTZ_STAIRS));
            this.multiblock.add(new BlockType(1,0,1, Material.END_ROD));
            this.multiblock.add(new BlockType(1,0,-1, Material.END_ROD));
            this.multiblock.add(new BlockType(-1,0,1, Material.END_ROD));
            this.multiblock.add(new BlockType(-1,0,-1, Material.END_ROD));
            this.multiblock.add(new BlockType(1,1,1, Material.END_ROD));
            this.multiblock.add(new BlockType(1,1,-1, Material.END_ROD));
            this.multiblock.add(new BlockType(-1,1,1, Material.END_ROD));
            this.multiblock.add(new BlockType(-1,1,-1, Material.END_ROD));
            this.multiblock.add(new BlockType(1,2,1, Material.SEA_LANTERN));
            this.multiblock.add(new BlockType(1,2,-1, Material.SEA_LANTERN));
            this.multiblock.add(new BlockType(-1,2,1, Material.SEA_LANTERN));
            this.multiblock.add(new BlockType(-1,2,-1, Material.SEA_LANTERN));
     
  13. Offline

    danik159

    what I should do with this?, and answer why I have different answeres, 1 answer in console, and 1 answer in chat
     
  14. Offline

    CraftCreeper6

    @danik159
    I cross checked all the coordinates, they are all correct. There's no explanation as to why you're getting that result. It's pretty much impossible to get that result.
     
  15. Offline

    danik159

  16. Offline

    CraftCreeper6

    @danik159

    The event could be getting called more than once, add a cooldown to prevent multiple messages.
     
  17. Offline

    danik159

    I dont think this is going to help, because it send the second message exactly when the first.
     
    Last edited: Jul 21, 2019
  18. Offline

    CraftCreeper6

    @danik159
    I suppose you could add the gold block to a list when the player clicks it, if it's in the list, then don't send a message?
     
  19. Offline

    danik159

    what?, I am new to Java programming, soo maybe you can explain?
     
  20. Offline

    CraftCreeper6

    @danik159
    I'll try my best, but considering you don't know Java very well it may be best to learn first, before diving into Bukkit.

    Nonetheless,

    A List is something that you can use to store objects, it's like a shopping list. Say this is your shopping list:

    - Eggs
    - Bread
    - Lettuce
    - Chocolate

    That would be a list.

    In Java, a list looks something like this:
    Code:
    List<Object> shoppingList = new ArrayList<Object>();
    If you wanted to say, get the first item on the list; it might seem like common sense to do:
    Code:
    shoppingList#get(1);
    But that's wrong, see Java counts from zero, so to get the first element you use;
    Code:
    shoppingList#get(0);
    That code would return "Eggs".

    In your case, you want to add gold blocks, so the best way to do this is;

    Code:
    List<Location> alreadyClickedHere = new ArrayList<Location>();
    Then, loop through everything in the list
    Code:
    for (Location loc in alreadyClickedHere)
    Check if the location of the block that the player clicked is equal to loc, if it is, return; if it's not, keep going.

    Add the location to the alreadyClickedHere list.

    That should be all you need really.
     
  21. Offline

    danik159

    but then I wont use the code again?, I dont need it, I want that every (for example) 5 minutes You will can use the block
     
  22. Offline

    CraftCreeper6

    After 5 minutes, remove the block from the list again.

    Sent from my LYA-L09 using Tapatalk
     
  23. Offline

    danik159

    even the cooldown sends the message twice.

    ahhh, now my cooldown is broken XD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 21, 2019
  24. Offline

    CraftCreeper6

  25. Offline

    danik159

  26. Offline

    CraftCreeper6

    @danik159
    Move the hashmap out of the PlayerInteractEvent.
     
  27. Offline

    danik159

    thanks, but I dont know why it send the message twice, listen can you check if you have the same error or my mouse jsut broke

    okey, I fixed it, just changed from right click to left click

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 21, 2019
Thread Status:
Not open for further replies.

Share This Page