Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package games.coob.laserturrets.task;
- import games.coob.laserturrets.model.TurretData;
- import games.coob.laserturrets.model.TurretRegistry;
- import games.coob.laserturrets.util.EntityUtil;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.entity.LivingEntity;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- import org.mineacademy.fo.remain.CompMaterial;
- import org.mineacademy.fo.remain.CompParticle;
- public class FlameTask extends BukkitRunnable {
- @Override
- public void run() {
- final TurretRegistry turretRegistry = TurretRegistry.getInstance();
- for (final TurretData turretData : turretRegistry.getFlameTurrets()) {
- final Location location = turretData.getLocation();
- final Block block = location.getBlock();
- final int level = turretData.getCurrentLevel();
- final int range = turretRegistry.getTurretRange(block, level);
- final LivingEntity nearestEntity = EntityUtil.findNearestEntityNonBlacklisted(location, range, LivingEntity.class, block);
- if (nearestEntity == null)
- continue;
- final Location flameLocation = location.clone().add(0.5, 1.2, 0.5);
- final Location targetLocation = nearestEntity.getLocation().add(0, 1.6, 0);
- final Vector vector = targetLocation.subtract(flameLocation).toVector().normalize();
- final double distance = location.distance(nearestEntity.getLocation());
- System.out.println("Distance: " + distance);
- vector.add(new Vector(0, 0.1, 0));
- final double accuracy = 0.08;
- vector.add(new Vector(Math.random() * accuracy - (accuracy / 2), Math.random() * accuracy - (accuracy / 2), Math.random() * accuracy - (accuracy / 2)));
- for (double waypoint = 1; waypoint < distance; waypoint += 0.5) {
- vector.add(new Vector(0, -0.01, 0));
- flameLocation.add(vector);
- CompParticle.FLAME.spawn(flameLocation);
- }
- }
- }
- private void shootFlames(final LivingEntity target, final Block turretBlock, final int length) {
- final Location turretLocation = turretBlock.getLocation();
- final Location targetLocation = target.getLocation().add(-0.5, 1, -0.5);
- // vector.add(new Vector(Math.random() * accuracy - (accuracy / 2), Math.random() * accuracy - (accuracy / 2), Math.random() * accuracy - (accuracy / 2)));
- final Location flameLocation = turretLocation.clone();
- flameLocation.setY(turretLocation.getY() + 1.2);
- flameLocation.setX(turretLocation.getX() + 0.5);
- flameLocation.setZ(turretLocation.getZ() + 0.5);
- final double dX = flameLocation.getX() - targetLocation.getX();
- final double dY = flameLocation.getY() - targetLocation.getY();
- final double dZ = flameLocation.getZ() - targetLocation.getZ();
- final double yaw = Math.atan2(dZ, dX);
- final double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
- final double X = Math.sin(pitch) * Math.cos(yaw);
- final double Y = Math.sin(pitch) * Math.sin(yaw);
- final double Z = Math.cos(pitch);
- final Vector vector = new Vector(X, Y, Z);
- for (double waypoint = 1; waypoint < length; waypoint += 0.5) {
- flameLocation.add(vector);
- CompParticle.FLAME.spawn(flameLocation);
- /*final int randomInt = RandomUtil.nextInt(100);
- if (randomInt < 6)
- setFireToBlock(flameLocation.getBlock());*/
- }
- }
- private Vector createVectorBetweenLocations(final Location fromLocation, final Location toLocation) {
- final double dX = fromLocation.getX() - toLocation.getX();
- final double dY = fromLocation.getY() - toLocation.getY();
- final double dZ = fromLocation.getZ() - toLocation.getZ();
- final double yaw = Math.atan2(dZ, dX);
- final double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
- final double X = Math.sin(pitch) * Math.cos(yaw);
- final double Y = Math.sin(pitch) * Math.sin(yaw);
- final double Z = Math.cos(pitch);
- return new Vector(X, Z, Y);
- }
- private Vector vectorOffset(double yaw, double pitch) {
- final int variation = 10; //Variation in degrees
- final int var2 = variation * 2; //Used later for randomization
- final double variationYaw = ((Math.random() * variation) - var2); //Vary by between 10 and -10 degrees
- final double variationPitch = ((Math.random() * variation) - var2);
- yaw += variationYaw;
- pitch += variationPitch;
- final double X = Math.sin(Math.toRadians(pitch));
- final double Y = Math.sin(Math.toRadians(yaw));
- final double Z = Math.cos(Math.toRadians(yaw));
- /*final double X = Math.sin(pitch) * Math.cos(yaw);
- final double Y = Math.sin(pitch) * Math.sin(yaw);
- final double Z = Math.cos(pitch);*/
- return new Vector(X, Y, Z);
- }
- private void test() {
- /*final int length = 50; // show twenty blocks ahead
- final Location laserLocation = location.clone();
- laserLocation.setY(location.getY() + 1.2);
- laserLocation.setX(location.getX() + 0.5);
- laserLocation.setZ(location.getZ() + 0.5);
- final double dX = laserLocation.getX() - nearestEntity.getLocation().getX();
- final double dY = laserLocation.getY() - nearestEntity.getLocation().getY();
- final double dZ = laserLocation.getZ() - nearestEntity.getLocation().getZ();
- final double yaw = Math.atan2(dZ, dX);
- final double pitch = Math.atan2(Math.sqrt(dZ * dZ + dX * dX), dY) + Math.PI;
- final double X = Math.sin(pitch) * Math.cos(yaw);
- final double Y = Math.sin(pitch) * Math.sin(yaw);
- final double Z = Math.cos(pitch);
- final Vector vector = new Vector(X, Z, Y);
- for (double waypoint = 1; waypoint < length; waypoint += 0.5) {
- laserLocation.add(vector);
- CompParticle.REDSTONE.spawn(laserLocation);
- }*/
- }
- private void setFireToBlock(final Block block) {
- if (!CompMaterial.isAir(block)) {
- final Block blockUp = block.getRelative(BlockFace.UP);
- if (CompMaterial.isAir(blockUp) && blockUp.getRelative(BlockFace.DOWN).getType().isSolid())
- blockUp.setType(Material.FIRE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement