use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class GlowWorld method getNearbyEntities.
/**
* Returns a list of entities within a bounding box centered around a Location.
*
* <p>Some implementations may impose artificial restrictions on the size of the search bounding
* box.
*
* @param location The center of the bounding box
* @param x 1/2 the size of the box along x axis
* @param y 1/2 the size of the box along y axis
* @param z 1/2 the size of the box along z axis
* @return the collection of entities near location. This will always be a non-null collection.
*/
@Override
public Collection<Entity> getNearbyEntities(Location location, double x, double y, double z) {
Vector minCorner = new Vector(location.getX() - x, location.getY() - y, location.getZ() - z);
Vector maxCorner = new Vector(location.getX() + x, location.getY() + y, location.getZ() + z);
// TODO: test
BoundingBox searchBox = BoundingBox.fromCorners(minCorner, maxCorner);
GlowEntity except = null;
return entityManager.getEntitiesInside(searchBox, except);
}
use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class Explosion method damageEntities.
// ///////////////////////////////////////
// Damage entities
private void damageEntities() {
float power = this.power;
this.power *= 2;
Collection<Entity> entities = getNearbyEntities();
for (Entity entity : entities) {
if (!(entity instanceof GlowEntity)) {
continue;
}
// refine area to sphere, instead of box
if (distanceToSquared(entity) > power * power) {
continue;
}
double exposure = world.rayTrace(location, (GlowEntity) entity);
double impact = (1 - (distanceTo(entity) / power / 2)) * exposure;
double damage = (impact * impact + impact) * 8 * power + 1;
int epf = getProtectionFactor(entity);
double reduction = calculateEnchantedReduction(epf);
damage = damage * reduction;
exposure -= exposure * epf * 0.15;
DamageCause damageCause;
if (source == null || source.getType() == EntityType.PRIMED_TNT) {
damageCause = DamageCause.BLOCK_EXPLOSION;
} else {
damageCause = DamageCause.ENTITY_EXPLOSION;
}
((GlowEntity) entity).damage(damage, source, damageCause);
if (entity instanceof GlowPlayer && ((GlowPlayer) entity).isFlying()) {
continue;
}
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
Vector rayLength = RayUtil.getVelocityRay(distanceToHead(livingEntity));
rayLength.multiply(exposure);
Vector currentVelocity = entity.getVelocity();
currentVelocity.add(rayLength);
entity.setVelocity(currentVelocity);
}
}
}
use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class TestForCommand method execute.
@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
if (!testPermission(sender, commandMessages.getPermissionMessage())) {
return true;
}
if (args.length < 1) {
sendUsageMessage(sender, commandMessages);
return false;
}
String name = args[0];
Entity[] entities;
if (name.startsWith("@")) {
CommandTarget target = new CommandTarget(sender, name);
entities = target.getMatched(CommandUtils.getLocation(sender));
if (entities.length == 0) {
commandMessages.getGeneric(GenericMessage.NO_MATCHES).sendInColor(ChatColor.RED, sender, name);
return false;
}
} else {
// TODO: Select custom-named non-player entities?
GlowPlayer player = (GlowPlayer) Bukkit.getPlayerExact(args[0]);
if (player == null) {
commandMessages.getGeneric(GenericMessage.NO_SUCH_PLAYER).sendInColor(ChatColor.RED, sender, name);
return false;
} else {
entities = new Entity[] { player };
}
}
LocalizedStringImpl foundMessage = new LocalizedStringImpl("testfor.found", commandMessages.getResourceBundle());
if (args.length >= 2) {
String data = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
CompoundTag tag;
try {
tag = Mojangson.parseCompound(data);
} catch (MojangsonParseException e) {
commandMessages.getGeneric(GenericMessage.INVALID_JSON).sendInColor(ChatColor.RED, sender, e.getMessage());
return false;
}
LocalizedStringImpl wrongDataMessage = new LocalizedStringImpl("testfor.wrong-data", commandMessages.getResourceBundle());
for (Entity entity : entities) {
if (entity instanceof GlowEntity) {
CompoundTag entityTag = new CompoundTag();
EntityStorage.save((GlowEntity) entity, entityTag);
if (tag.matches(entityTag)) {
foundMessage.send(sender, CommandUtils.getName(entity));
} else {
wrongDataMessage.sendInColor(ChatColor.RED, sender, CommandUtils.getName(entity));
}
}
}
} else {
for (Entity entity : entities) {
foundMessage.send(sender, CommandUtils.getName(entity));
}
}
// matching entities.
return true;
}
use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class SummonCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender))
return true;
if (sender instanceof ConsoleCommandSender) {
sender.sendMessage("This command can only be executed by a player or via command blocks.");
return true;
}
Location location = null;
if (sender instanceof Player) {
location = ((Player) sender).getLocation().clone();
} else if (sender instanceof BlockCommandSender) {
location = ((BlockCommandSender) sender).getBlock().getLocation().clone();
}
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
if (args.length >= 4) {
location = CommandUtils.getLocation(location, args[1], args[2], args[3]);
}
if (location == null) {
return false;
}
location.setYaw(0.0f);
location.setPitch(0.0f);
CompoundTag tag = null;
if (args.length >= 5) {
String data = String.join(" ", new ArrayList<>(Arrays.asList(args)).subList(4, args.length));
try {
tag = Mojangson.parseCompound(data);
} catch (MojangsonParseException e) {
sender.sendMessage(ChatColor.RED + "Invalid Data Tag: " + e.getMessage());
}
}
String entityName = args[0];
if (!checkSummon(sender, entityName)) {
return true;
}
GlowEntity entity;
if (EntityType.fromName(entityName) != null) {
entity = (GlowEntity) location.getWorld().spawnEntity(location, EntityType.fromName(entityName));
} else {
Class<? extends GlowEntity> clazz = EntityRegistry.getCustomEntityDescriptor(entityName).getEntityClass();
entity = ((GlowWorld) location.getWorld()).spawn(location, clazz, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
if (tag != null) {
EntityStorage.load(entity, tag);
}
sender.sendMessage("Object successfully summoned.");
return true;
}
use of net.glowstone.entity.GlowEntity in project Glowstone by GlowstoneMC.
the class GlowChunk method unload.
@Deprecated
public boolean unload(boolean save, boolean safe) {
safe = false;
if (!isLoaded()) {
return true;
}
if (safe && world.isChunkInUse(x, z)) {
return false;
}
if (save && !world.getChunkManager().performSave(this)) {
return false;
}
EventFactory.getInstance().callEvent(new ChunkUnloadEvent(this));
sections = null;
biomes = null;
heightMap = null;
blockEntities.clear();
if (save) {
for (GlowEntity entity : entities) {
entity.remove();
}
entities.clear();
}
return true;
}
Aggregations