I saw some thread about vector manipulation and I was interested so I made a 'black hole.' Then I wrote a quick class so that you can create your own easily Here is a video of what I am talking about Class: Code: public class BlackHole { private JavaPlugin plugin; private Location loc; private int range; private float power; private List<EntityType> types; private boolean isEnabled; public BlackHole(JavaPlugin plugin, Location loc, int range, float power, List<EntityType> types) { this.plugin = plugin; this.loc = loc; this.range = range; this.power = power; this.types = types; this.isEnabled = true; this.control(); } private void control() { Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable() { public void run() { World world = loc.getWorld(); int squared = range * range; if(this.isEnabled()) { for(Entity e : world.getEntities()) { if(types == null || types.contains(e.getType())) { if(e.getLocation().distanceSquared(loc) <= squared) { Vector entityVector = new Vector(e.getLocation().getX(), e.getLocation().getY(), e.getLocation().getZ()); Vector blackholeVector = new Vector(loc.getX(), loc.getY(), loc.getZ()); e.setVelocity(blackholeVector.subtract(entityVector).multiply(power)); } } } } } }, 1, 1); } public void enable() { this.isEnabled = true; } public void disable() { this.isEnabled = false; } public void setLocation(Location loc) { this.loc = loc; } public void setRange(int range) { this.range = range; } public void setPower(float power) { this.power = power; } public void setTypes(List<EntityType> types) { this.types = types; } public float getPower() { return this.power; } public int getRange() { return this.range; } public Location getLocation() { return this.loc; } public boolean isEnabled() { return this.isEnabled; } } Example usage: Code: public class SpaceTest extends JavaPlugin implements Listener { private BlackHole blackhole; public void onEnable() { this.getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if(event.getAction() == Action.LEFT_CLICK_AIR) { if(blackhole == null) { List<EntityType> types = new ArrayList<EntityType>(); for(EntityType type : EntityType.values()) { if(type != EntityType.PLAYER) { types.add(type); } } blackhole = new BlackHole(this, player.getLocation(), 500, 0.05F, types); player.sendMessage(ChatColor.GOLD + "Created new black hole"); } else { if(blackhole.isEnabled()) { blackhole.disable(); player.sendMessage(ChatColor.GOLD + "Disabled the black hole"); } else { blackhole.enable(); player.sendMessage(ChatColor.GOLD + "Enabled the black hole"); } } } } } The space generator in the video was just there to make the black hole look cooler.
Was that recorded on my server? I thought I saw that! Sweet! Second: I see that you are smart with vectors. You have the force! Get it?
Whoa! That's really cool! You could optimize t a bit by using some NMS magic (the add entity to world method), but it looks fantastic! Good job. If you could add some swirly effects, that would be super cool:
@xTrollxDudex I have the perfect tutorial to use! http://bukkit.org/threads/creating-a-helix-3d-spiral-out-of-particles.314312/ I might in the morning, but I have to finish this space plugin for my server this week.
@Skionz you g0d. Only someone like you would freely give something like this out! Call me a kiss-ass if you want but this is just really cool. Great job!
I went to the blackhole, I died many times. There was a ball of tnt, shift was jetpack. It was a strange day for man kind. @Skionz get's that. I played on the server when he was testing it and it was crazy, good job on it Skionz.
You could divide the power by the distance to make it look smoother when they just get attracted. Also normalize the vector before multiplying, or entities will slow down the closer they are. Unless it is intended behaviour, but I think it would look better if you don't get pulled super fast when you just step in range. Also, you should use a EnumSet for a Set of EntityType.
Instead of setting the entities velocity directly towards the black hole you could also do something like this: Vector toHole = blackholeVector.subtract(entityVector); double distance = toHole.length(); entity.setVelocity(entity.getVelocity().add(toHole.multiply(power / (distance * distance)))); That way entities won't fly directly towards the black hole but only get pulled in step by step, potentially even flying in circles around the black hole, depending on the entities initial speed and the power of the black hole etc. Also the force towards the black hole depends on the distance between the black hole and the entity with this.
How can it crash the server? Just get a max blocks at same time to be attracted then when they are at the blackhole do it again?
Ah, I will try it later. I'm going to take a wild guess and say it crashed because I turned every block in the range into a falling block.
just have max of like 10 blocks and get those blocks from a random location in a range then attract it to the blackhole and delete those blocks and then do it agian
@Skionz Now when you go inside the black hole, will it plop you in a saved world backup from the past?
I really like it but have a few suggestions for optimizing. Cache the square of the range and check isEnabled() before entering the loop (right now it recalculates the range for each Entity and might loop uselessly if the blackhole isn't enabled).