mirror of
https://github.com/songoda/UltimateStacker.git
synced 2025-03-12 22:49:02 +01:00
Test boost
This commit is contained in:
parent
8789288f99
commit
9e38374cb1
@ -6,6 +6,7 @@ import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
@ -60,8 +61,10 @@ public class StackingTask extends BukkitRunnable {
|
||||
|
||||
// Loop through the entities.
|
||||
for (Entity entity : entities) {
|
||||
// Get entity location to pass around as its faster this way.
|
||||
Location location = entity.getLocation();
|
||||
// Check to see if entity is stackable.
|
||||
if (!isEntityStackable(entity)) continue;
|
||||
if (!isEntityStackable(entity, location)) continue;
|
||||
// Make sure our entity has not already been processed.
|
||||
// Skip it if it has been.
|
||||
if (this.processed.contains(entity.getUniqueId())) continue;
|
||||
@ -70,14 +73,14 @@ public class StackingTask extends BukkitRunnable {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
|
||||
// Process the entity.
|
||||
this.processEntity(livingEntity);
|
||||
this.processEntity(livingEntity, location);
|
||||
|
||||
}
|
||||
}
|
||||
processed.clear();
|
||||
}
|
||||
|
||||
private boolean isEntityStackable(Entity entity) {
|
||||
private boolean isEntityStackable(Entity entity, Location location) {
|
||||
// Make sure we have the correct entity type and that it is valid.
|
||||
if (!entity.isValid()
|
||||
|| !(entity instanceof LivingEntity)
|
||||
@ -101,11 +104,11 @@ public class StackingTask extends BukkitRunnable {
|
||||
// If only stack on surface is enabled make sure the entity is on a surface then entity is stackable.
|
||||
return !Setting.ONLY_STACK_ON_SURFACE.getBoolean()
|
||||
|| Methods.canFly(livingEntity)
|
||||
|| (livingEntity.isOnGround() || livingEntity.getLocation().getBlock().isLiquid());
|
||||
|| (livingEntity.isOnGround() || location.getBlock().isLiquid());
|
||||
|
||||
}
|
||||
|
||||
private void processEntity(LivingEntity livingEntity) {
|
||||
private void processEntity(LivingEntity livingEntity, Location location) {
|
||||
// Get the stack from the entity. It should be noted that this value will
|
||||
// be null if our entity is not a stack.
|
||||
EntityStack stack = plugin.getEntityStackManager().getStack(livingEntity);
|
||||
@ -128,8 +131,8 @@ public class StackingTask extends BukkitRunnable {
|
||||
int maxEntityStackSize = getEntityStackSize(livingEntity);
|
||||
|
||||
// Get similar entities around our entity and make sure those entities are both compatible and stackable.
|
||||
List<LivingEntity> stackableFriends = plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity)
|
||||
.stream().filter(this::isEntityStackable).collect(Collectors.toList());
|
||||
List<LivingEntity> stackableFriends = plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity, location)
|
||||
.stream().filter(entity -> isEntityStackable(entity, location)).collect(Collectors.toList());
|
||||
|
||||
// Loop through our similar stackable entities.
|
||||
for (LivingEntity entity : stackableFriends) {
|
||||
@ -173,7 +176,7 @@ public class StackingTask extends BukkitRunnable {
|
||||
&& (stack.getAmount() + 1) <= maxEntityStackSize
|
||||
&& Methods.canFly(entity)
|
||||
&& Setting.ONLY_STACK_FLYING_DOWN.getBoolean()
|
||||
&& livingEntity.getLocation().getY() > entity.getLocation().getY()) {
|
||||
&& location.getY() > entity.getLocation().getY()) {
|
||||
|
||||
// Create a new stack with the current stacks amount and add one to it.
|
||||
EntityStack newStack = stackManager.addStack(entity, stack.getAmount() + 1);
|
||||
|
@ -5,13 +5,12 @@ import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.entity.Check;
|
||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.utils.settings.Setting;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -175,11 +174,45 @@ public class EntityUtils {
|
||||
return newEntity;
|
||||
}
|
||||
|
||||
public List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initalEntity) {
|
||||
private List<LivingEntity> getNearbyEntities(Location location, double radius) {
|
||||
List<LivingEntity> entities = new ArrayList<>();
|
||||
for (Chunk chunk : getNearbyChunks(location, radius)) {
|
||||
for (Entity e : chunk.getEntities()) {
|
||||
if (!(e instanceof LivingEntity) || location.distance(e.getLocation()) >= radius) continue;
|
||||
entities.add((LivingEntity) e);
|
||||
}
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
private List<Chunk> getNearbyChunks(Location location, double radius) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return new ArrayList<>();
|
||||
|
||||
Chunk firstChunk = location.getChunk();
|
||||
List<Chunk> chunks = Lists.newArrayList();
|
||||
chunks.add(firstChunk);
|
||||
int minX = (int) Math.floor(((location.getX() - radius) - 2.0D) / 16.0D);
|
||||
int maxX = (int) Math.floor(((location.getX() + radius) + 2.0D) / 16.0D);
|
||||
int minZ = (int) Math.floor(((location.getZ() - radius) - 2.0D) / 16.0D);
|
||||
int maxZ = (int) Math.floor(((location.getZ() + radius) + 2.0D) / 16.0D);
|
||||
|
||||
for (int x = minX; x <= maxX; ++x) {
|
||||
for (int z = minZ; z <= maxZ; ++z) {
|
||||
if (firstChunk.getX() == x && firstChunk.getZ() == z) continue;
|
||||
Chunk chunk = world.getChunkAt(x, z);
|
||||
if (chunk.isLoaded() && !chunks.contains(chunk))
|
||||
chunks.add(chunk);
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initalEntity, Location location) {
|
||||
// Create a list of all entities around the initial entity of the same type.
|
||||
List<LivingEntity> entityList = initalEntity.getNearbyEntities(searchRadius, searchRadius, searchRadius)
|
||||
List<LivingEntity> entityList = getNearbyEntities(location, searchRadius)
|
||||
.stream().filter(entity -> entity.getType() == initalEntity.getType() && entity != initalEntity)
|
||||
.map(entity -> (LivingEntity) entity).collect(Collectors.toList());
|
||||
.collect(Collectors.toCollection(LinkedList::new));
|
||||
|
||||
if (stackFlyingDown && Methods.canFly(initalEntity))
|
||||
entityList.removeIf(entity -> entity.getLocation().getY() > initalEntity.getLocation().getY());
|
||||
|
Loading…
Reference in New Issue
Block a user