ArmorStand moving around a middle block

Discussion in 'Plugin Development' started by AsyncProgrammer, Sep 7, 2019.

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

    AsyncProgrammer

    I am trying to make the armor stand rotate around the block, and not start rotating from it, which is what is happening.

    [​IMG]
    I trying to do anythig similiar to that
    But the max who i achieved is this why my armor stand doesnt rotate around the EnderChest.
    [​IMG]
    Full code:
    Fully Code (open)

    Code:
    package net.arcane.caixas.executor.commands;
    
    import com.google.common.collect.Lists;
    import net.arcane.caixas.Loader;
    import net.arcane.caixas.Skull;
    import org.apache.commons.lang.math.RandomUtils;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.ArmorStand;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.util.EulerAngle;
    import org.bukkit.util.Vector;
    
    import java.util.List;
    
    /**
    * Classe criada para o plugin - ArcaneChestShop
    *
    * @author Async. Obrigado por utiliza-lo.
    * @data 06/09/2019 - 22:28.
    */
    
    public class TesteCommand  {
    
        public String[] skulls = new String[]{"http://textures.minecraft.net/texture/c35ba393b8610b63ebee4c13c8358bc6c94a9dedc8e4d7d36b922257e65e8",
                "http://textures.minecraft.net/texture/2370ca47b6173ab58e6a8018486e2f8baa8397ab614ae2e696849196baa7c",
                "http://textures.minecraft.net/texture/c8d2901337361e191da33543a2927dfa011f5eb694e31d501bcca15281d4a",
                "http://textures.minecraft.net/texture/59d859d6baf33eccde997501a76e8b83c41aa6859b8e4fe1be2ac08cc04843"};
    
        public void execute(Player player, String[] args){
            for (int i = 0; i < 100; i++){
                player.sendMessage("");
            }
    
            List<Location> locations = Lists.newArrayList();
            player.getLocation().clone().add(0,-0.975, 0).getBlock().setType(Material.ENDER_CHEST);
    
            locations.add(player.getLocation().clone().add(0, -0.975, 0));
            Block block = player.getWorld().getBlockAt(locations.get(0));
           // ArmorStand sol = player.getWorld().spawn(player.getLocation().clone().add(0, -0.975, 00), ArmorStand.class); // spawna a ArmorStand
           // sol.setVisible(false); // coloca pra ela nao ficar visivel
           // sol.setGravity(false);
    
            ArmorStand terra = player.getWorld().spawn(player.getLocation().clone().add(1, -0.975, 0), ArmorStand.class); // spawna a ArmorStand
            terra.setHelmet(Skull.getCustomSkull(skulls[1])); // coloca uma cabeça nela
            terra.setVisible(true); // coloca pra ela nao ficar visivel
            terra.setGravity(false);
    
            final Location center = block.getLocation();
            final float radius = 1.40f;
            final float radPerSec = 3f;
            final float radPerTick = radPerSec / 20f;
    
            ArmorStand stand = player.getWorld().spawn(center, ArmorStand.class); // spawna a ArmorStand
            stand.setHelmet(Skull.getCustomSkull(skulls[1])); // coloca uma cabeça nela
            stand.setVisible(false); // coloca pra ela nao ficar visivel
            stand.setGravity(false);
    
            new BukkitRunnable() {
                int tick = 0;
                double y = 0.0;
                public void run() {
                    ++tick;
                    Location loc = getLocationAroundCircle(center, radius, radPerTick * tick);
                    System.out.println(loc);
                    stand.setVelocity(new Vector(0, 0, 0));
                    stand.teleport(loc);
                }
            }.runTaskTimer(Loader.getInstance(), 0L, 1L);
    
        }
    
    
    
        public Location getLocationAroundCircle(Location center, double radius, double angleInRadian) {
            double x = center.getX() - radius * Math.cos(angleInRadian);
            double y = center.getY() - radius * Math.sin(angleInRadian);
    
            Location loc = new Location(center.getWorld(), x, y, center.getZ());
            Vector difference = center.toVector().clone().subtract(loc.toVector()); // this sets the returned location's direction toward the center of the circle
            loc.setDirection(difference);
    
            return loc;
        }
    
        public Location getCenter(Location loc) {
            return new Location(loc.getWorld(),
                    getRelativeCoord(loc.getBlockX()),
                    getRelativeCoord(loc.getBlockY()),
                    getRelativeCoord(loc.getBlockZ()));
        }
    
        private double getRelativeCoord(int i) {
            double d = i;
            d = d < 0 ? d - .5 : d + .5;
            return d;
        }
    
    }
    
     
  2. Use your getCenter() method. But you'll have to make some adjustment: the "relative" coordinates should always be +.5 not negative and the y is probably not 0.5 because of the height of the armor stand. You'll have to play around a little to find the best offset
     
    Last edited: Sep 8, 2019
Thread Status:
Not open for further replies.

Share This Page