Making floating Item

Discussion in 'Spigot Plugin Development' started by danichef, Apr 17, 2017.

  1. Hello, I'm trying to make flying items, I'm doing it with armor stands since I can't figure out other way to do it with items. But its wierd having an item floating in the midle of noething. Hres code:
    Code (Text):
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event){
            Action action = event.getAction();
        if (action == Action.RIGHT_CLICK_BLOCK) {
            Player player = event.getPlayer();
            Location loc = player.getLocation();
            loc.setDirection(loc.getDirection());
            ArmorStand stand = player.getLocation().getWorld().spawn(loc, ArmorStand.class);
            stand.setBasePlate(false);  
            stand.setVisible(false);
            stand.setGravity(false);
            ItemStack head = new ItemStack(Material.FISHING_ROD, 1);
            stand.setHelmet(head);
            }
        }
    Is there a way to make it so its ontop of the block below? Or is there a better way?

    Thanks for your time!
     
  2. Try dropping an item using world.dropitem() and then set the returned Item's(not ItemStack) gravity to false.
    Code (Text):
    Theitemvar.setGravity(false);
     
  3. Just spawn the item as entity ( world.dropItem(...) )
    Then just spawn your armorstand and set the item as passenger on the armorstand
     
  4. Why 2 entities when u can just set the gravity of the item to false........
     
  5. Oh that exists now? Lol okay i was thinking about the 1.8 Version but good to know that it is now available
     
  6. Ive tryed the ( world.dropItem(...) ) and it spawns 2 entities and you can pick them. Also its at the same hight.
    Heres new code
    Code (Text):
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event){
            Action action = event.getAction();
        if (action == Action.RIGHT_CLICK_BLOCK) {
            Player player = event.getPlayer();
            Location loc = player.getLocation();
            loc.setDirection(loc.getDirection());
            ArmorStand stand = player.getLocation().getWorld().spawn(loc, ArmorStand.class);
            stand.setBasePlate(false);  
            stand.setVisible(false);
            stand.setGravity(false);
            ItemStack i = new ItemStack(Material.FISHING_ROD, 1);
            Item item = loc.getWorld().dropItem(loc, i);
            stand.setPassenger(item);
            }
        }
     
    #6 danichef, Apr 18, 2017
    Last edited: Apr 18, 2017
  7. Make sure you're setting it so you can't pick them up -
    Code (Text):
    item.setPickupDelay(Integer.MAX_VALUE);
    Also, you don't need two entities to do this. After you drop the one you want to float, just set the gravity to false along with the pickup delay.
     
  8. @Lord_Pyrak And so that its doesent psawn it double?
     
  9. No, I mean that you don't need to mount it to an armor stand
     
  10. @Lord_Pyrak Then how do I do it? + How to I make that it doesent turn around?
     
  11. The event fires so quickly, that sometimes itll fire two, even three times, even though you think you only clicked once. After the event, create a half second (10 ticks) or around there cooldown, to ensure that the event is not fired more than once
     
  12. I'm not too sure, I've never worked with spawning items. I'd assume your best bet is to do something with an armor stand. I've never worked with armor stands though, so :p