How to check if a item is on ground.

Discussion in 'Plugin Development' started by MinerPiggeh, Mar 19, 2013.

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

    MinerPiggeh

    Hey Guys, the title says all what I need. The item type is Gold Nugget.
     
  2. Offline

    XbannisherX

    check the gold nugget's velocity, if its not moving its prob on the ground right?
     
  3. MinerPiggeh
    Do you want to know if an item entity is standing still OR check if such item exists as dropped item entity ?
     
  4. Offline

    XbannisherX

    I think he wants to know if an item has been thrown on the ground...?
     
  5. Offline

    MinerPiggeh

    So if ("item".getVelocity().equals("item".getVelocity().zero())){ ? Now the code doesn't check if the item is on the ground.
     
  6. Offline

    Netizen

  7. Offline

    MinerPiggeh

    Digi I want to know if the item hit te ground.
     
  8. MinerPiggeh
    Well, if you want to know *when* it hit the ground, like an event, you need to constantly check it with a repeating task each tick that checks if the item has Y velocity less than 0.1 or more than -0.1 (not X and Z velocity because it might slide) then trigger a method and cancel the event.

    But if you just need to know if the item is currently resting I guess you can use getVelocity().equals(new Vector(0,0,0)); but it's not 100% accurate to what you see in-game since the entity still has slight amount of velocity when it stops, that's why I said above to chekc if less than 0.1 and more than -0.1.
     
  9. Offline

    XbannisherX

    MinerPiggeh you want to know if an item is touching the ground yes?
     
  10. Offline

    MinerPiggeh

    Doesn't that create huge lagg?

    I want to know the moment when the item hits te ground.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  11. MinerPiggeh
    Huge lag, no, some lag if you monitor alot of items at the same time.
    You could use each 2 or more ticks if you don't really care about exact time.

    What is your actual goal ?
     
  12. Offline

    MinerPiggeh

    Digi To make a molotov
     
  13. Offline

    XbannisherX

    MinerPiggeh
    This is how i would do it:
    1.Check how long it takes for when an item hits the ground with a timer
    2.after a itemdropevent->let a delayed task with your measured time(1) remove your drop and put fire on the ground.
     
  14. Offline

    MinerPiggeh

    OK my idea is to create a Schedular and then get nearby entity's check if the entity is a dropped item then check if the dropped item is a gold nugget (Which i don't know how.) and then check if the dropped item is on the ground. But how do you check if the dropped item is a golden nugget?

    And how do you check if the item is on the ground.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  15. Getting nearby entities would actually make that more complicated and laggy than it needs to be.

    You should instead create a class that extends BukkitRunnable and store the Item object in there then start it to run each 5 or 10 ticks because you don't need absolute accuracy on that.

    Then inside the run() check if item velocity's Y axis is 0 and if it is use cancel(), remove the entity and spawn fire or whatever.

    XbannisherX
    Your suggested prediction is inaccurate, think about various block levels, the player might even throw it off a cliff...
     
  16. Offline

    MinerPiggeh

    Digi OK now I have the code the only thing I need to know is how do i check if the block isn't air within the sphere? Because I want it to check if the block is air then if it is just not set the block to fire.
     
  17. block.getTypeId() != 0 ?
    You might want to check if it's long grass, flower and anything that's small enough to be destroyed by the fire instantly.
     
  18. Offline

    MinerPiggeh

    Digi I now have this:
    Code:
            new BukkitRunnable(){
                @Override
                public void run(){
                if (molotov.getVelocity().getY() == 0){
    if (molotov.getLocation().getBlock().getRelative(0, 0,0).getType() == Material.AIR || molotov.getLocation().getBlock().getRelative(0, 0,0).getType() == Material.LONG_GRASS){
                        molotov.getLocation().getBlock().getRelative(0, 0,0).setType(Material.FIRE);
                    }
                    // Rest of the code
                    molotov.getWorld().playSound(molotov.getLocation(), Sound.EXPLODE, 100F, molotov.getLocation().getPitch());
                    molotov.remove();
                }
                }
                }.runTaskTimer(this, 0L, 10L);
    But it keeps checking if the block is air and it keeps playing the sound which causes a lot of lagg how can I check it once because the molotov is removed but it keeps checking
     
  19. I told you already, use cancel() method.

    Why do you get relative to 0,0,0... that's the exact same block, why not just use getLocation().getBlock().getType() ?
    You should store the block and use a switch() for type instead:
    Code:
    Block block = molotov.getLocation().getBlock();
    
    switch(block.getType())
    {
        case AIR:
        case LONG_GRASS:
        case YELLOW_FLOWER:
        case RED_ROSE:
        {
            block.setType(Material.FIRE);
            break;
        }
    }
    And you should also use 10 for initial delay as well.

    ... and also, molotov.getLocation().getPitch() has nothing to do with sound pitch... the sound pitch specifies how fast the sound plays basically where location's pitch is an angle of view (pitch and yaw, sound familiar ?).
     
Thread Status:
Not open for further replies.

Share This Page