Solved Want to teleport item every tick

Discussion in 'Spigot Plugin Development' started by MagmaGuy, Apr 16, 2017.

  1. I can teleport items.

    I just can't do it every tick.
    IRC was a bit divided on whether or not some form of anticheat designed for players was kicking in to prevent me from successfully teleporting the items. As it currently stands, I can teleport them every ~20 ticks. Can someone verify that minecraft/spigot are silently stopping me from doing this? Is my code wrong?

    Here's the relevant code snippet https://hastebin.com/rirotesaha.cs .

    Code (Text):

    //Item effect
        private void itemEffect(Entity entity, double radiusHorizontal, double radiusVertical, double speedHorizontal, double offset, Material material1, Material material2) {

            PowerStanceMath powerStanceMath = new PowerStanceMath(plugin);

            processID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {

                Item floatable1;
                Item floatable2;

                ItemStack itemStack1 = new ItemStack(material1, 1);
                ItemStack itemStack2 = new ItemStack(material2, 1);

                Location oldLocation1, oldLocation2;

                public void run() {


                    List<Location> particleLocations = powerStanceMath.cylindricalPowerStance(entity, radiusHorizontal, radiusVertical, speedHorizontal, offset);
                    Location newLocation1 = particleLocations.get(0);
                    Location newLocation2 = particleLocations.get(1);

                    if (floatable1 == null && floatable2 == null) {

                        floatable1 = entity.getWorld().dropItem(newLocation1, itemStack1);
                        floatable1.setPickupDelay(Integer.MAX_VALUE);
                        floatable1.setMetadata("VisualEffect", new FixedMetadataValue(plugin, true));
                        floatable1.setVelocity(verticalVelocity);


                        floatable2 = entity.getWorld().dropItem(newLocation2, itemStack2);
                        floatable2.setPickupDelay(Integer.MAX_VALUE);
                        floatable2.setMetadata("VisualEffect", new FixedMetadataValue(plugin, true));
                        floatable2.setVelocity(verticalVelocity);


                        oldLocation1 = particleLocations.get(0);
                        oldLocation2 = particleLocations.get(1);

                    } else {

                        floatable1.teleport(oldLocation1);
                        floatable1.setGravity(false);
                        Vector vector1 = newLocation1.toVector().subtract(oldLocation1.toVector());
    //                    Vector finalVector1 = new Vector();
    //                    finalVector1.setX(vector1.getX() * 0.50);
    //                    finalVector1.setY(vector1.getY() * 0.50);
    //                    finalVector1.setZ(vector1.getZ() * 0.50);
    //                    floatable1.setVelocity(finalVector1);
                        oldLocation1 = particleLocations.get(0);


                        floatable2.teleport(oldLocation2);
                        floatable2.setGravity(false);
                        Vector vector2 = newLocation2.toVector().subtract(oldLocation2.toVector());
    //                    Vector finalVector2 = new Vector();
    //                    finalVector2.setX(vector2.getX() * 0.50);
    //                    finalVector2.setY(vector2.getY() * 0.50);
    //                    finalVector2.setZ(vector2.getZ() * 0.50);
    //                    floatable2.setVelocity(finalVector2);
                        oldLocation2 = particleLocations.get(1);

                        getLogger().info(oldLocation1 + "");

                    }

                    if (!entity.isValid()) {

                        floatable1.remove();
                        floatable2.remove();
                        floatable1.removeMetadata("VisualEffect", plugin);
                        floatable2.removeMetadata("VisualEffect", plugin);
                        Bukkit.getScheduler().cancelTask(processID);

                    }

                }

            }, 1L, 1L);

        }
     
    Regarding this code snippet: Logs show that a new position is generated every tick without any issues. The code just seems to skip over the teleport part 19/20 times.

    If minecraft/spigot are stopping me from doing this, is there a way I could bypass it? At this stage I'm considering spawning in a new item every tick, but having done that before I am aware that it's not amazing performance-wise.
     
  2. Teleporting takes time, and the visual update also suffers from ping and the time it takes to visually move on the client.
     
  3. I'm not sure what you mean by "teleporting takes time", 20 ticks doesn't sound like the proper amount of time for teleporting and also I can do far more elaborate visual tricks every tick and they display just fine. Evidence:

    https://gfycat.com/FragrantAromaticBuckeyebutterfly

    it creates new items every tick. As you can see, no major issues on the client side. It certainly doesn't just update once a second.
     
    • Like Like x 1
  4. In other words it was exactly what i said it was... :rolleyes:
    Good that you did the research, though.