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 .

    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.setMetadata("VisualEffect", new FixedMetadataValue(plugin, true));

                        floatable2 = entity.getWorld().dropItem(newLocation2, itemStack2);
                        floatable2.setMetadata("VisualEffect", new FixedMetadataValue(plugin, true));

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

                    } else {

                        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);

                        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.removeMetadata("VisualEffect", plugin);
                        floatable2.removeMetadata("VisualEffect", plugin);



            }, 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:

    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.