Spawning an item with no velocity

Discussion in 'Plugin Development' started by Rixterz, Jun 14, 2016.

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

    Rixterz

    Hi

    I'd like to spawn an item in an exact location and have it stay there. The issue is that world#dropItem or world#dropItemNaturally spawn the item with a velocity. My code does get the item in the right place, but after you've seen it with its natural velocity

    Code:
    Item item = main.overworld.dropItem(loc, new ItemStack(mat));
           
            item.setVelocity(new Vector(0, 0, 0));
           
            item.teleport(loc);
    Is there any way to spawn it and have it sit perfectly on a block?
     
  2. Offline

    Zombie_Striker

    @Rixterz
    With armourstands, you can set their "noGravity" NBT tag to "true" to keep the armourstand floating. Try seeing if items have that tag, and if so, set it to true.
     
  3. Offline

    Rixterz

    That still doesn't remove the velocity.

    I wish there was a way to declare an item, set its velocity to 0 and gravity to false, before it actually appears. I tried spawning an itemstack of air, setting velocity to 0 and then setting the itemstack type back to whatever it should be, but it wont let you drop air. Barrier blocks don't work either as they have the error icon
     
    Last edited: Jun 14, 2016
  4. Offline

    Zombie_Striker

    @Rixterz
    Yes it does. the "noGravity" tag affects velocity and gravity (since they are calculated together)
     
  5. Offline

    Rixterz

    Using ItemStack#dropItem and then setting the gravity to false just makes it continue moving forever in the direction it was moving in as it was dropped.

    I found a command which spawns the item like I want it to, but you can't set a pickup delay on ItemStacks, you can't convert ItemStacks to Items, and you can't set their custom name either.

    Code:
    //summon Item ~ ~0.5 ~ {Item:{id:minecraft:stone,Count:1},Riding:{id:ArmorStand,Marker:1,Invisible:1,NoGravity:1}}
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 15, 2016
  6. Offline

    I Al Istannen

    @Rixterz
    You need to add o.5 to the x and z coordinate to center it on the block.
    It works for me with this:
    World#dropItem(location#clone()#add(0.5, 0, 0.5), <and so on>
    Item#setVelocity(new Vector());
    Item#setPickupDelay(Integer.MAX_VALUE);

    The item sits still in the middle of the block.
     
  7. Offline

    Rixterz

    You can still see it with its initial velocity for a short while after it's dropped
     
  8. Offline

    I Al Istannen

    @Rixterz
    Well, this is the exact code I used in one of my projects and it works without a single problem.
    Code:
    displayItem = chestLocation.getWorld().dropItem(chestLocation.clone().add(0.5, 1, 0.5), getItem());
    displayItem.setVelocity(new Vector());
    displayItem.setPickupDelay(Integer.MAX_VALUE);
    
    But if it only bounces for a short while and then is at the right location, you can probably neglegt it. Maybe a client server issue.
     
  9. Offline

    Rixterz

    With that code, does it just appear completely out of nowhere, on the block, and stay still? That's what I need, unfortunately there's no spawn() for items
     
  10. Offline

    I Al Istannen

    @Rixterz
    Here is a small gif of the plugin I use it in:
    item spawn.gif
     
    Last edited: Jun 19, 2016
    bennie3211 likes this.
Thread Status:
Not open for further replies.

Share This Page