use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.
the class ProjectileDispenseBehavior method dispense.
@Override
public void dispense(BlockDispenser source, Item item) {
Position dispensePos = Position.fromObject(source.getDispensePosition(), source.getLevel());
CompoundTag nbt = Entity.getDefaultNBT(dispensePos);
this.correctNBT(nbt);
BlockFace face = source.getFacing();
Entity projectile = Entity.createEntity(getEntityType(), dispensePos.getLevel().getChunk(dispensePos.getFloorX(), dispensePos.getFloorZ()), nbt);
if (projectile == null) {
return;
}
projectile.setMotion(new Vector3(face.getXOffset(), face.getYOffset() + 0.1f, face.getZOffset()).multiply(6));
projectile.spawnToAll();
}
use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.
the class EntityLiving method knockBack.
public void knockBack(Entity attacker, double damage, double x, double z, double base) {
double f = Math.sqrt(x * x + z * z);
if (f <= 0) {
return;
}
f = 1 / f;
Vector3 motion = new Vector3(this.motionX, this.motionY, this.motionZ);
motion.x /= 2d;
motion.y /= 2d;
motion.z /= 2d;
motion.x += x * f * base;
motion.y += base;
motion.z += z * f * base;
if (motion.y > base) {
motion.y = base;
}
this.setMotion(motion);
}
use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.
the class ParticleCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!this.testPermission(sender)) {
return true;
}
if (args.length < 7) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
}
Level level;
if (sender instanceof Player) {
level = ((Player) sender).getLevel();
} else {
level = sender.getServer().getDefaultLevel();
}
String name = args[0].toLowerCase();
float[] floats = new float[6];
for (int i = 0; i < floats.length; i++) {
try {
double d = Double.valueOf(args[i + 1]);
floats[i] = (float) d;
} catch (Exception e) {
return false;
}
}
Vector3 pos = new Vector3(floats[0], floats[1], floats[2]);
float xd = floats[3];
float yd = floats[4];
float zd = floats[5];
int count = 1;
if (args.length > 7) {
try {
double c = Double.valueOf(args[7]);
count = (int) c;
} catch (Exception e) {
// ignore
}
}
count = Math.max(1, count);
Integer data = null;
if (args.length > 8) {
try {
double d = Double.valueOf(args[8]);
data = (int) d;
} catch (Exception e) {
// ignore
}
}
Particle particle = this.getParticle(name, pos, xd, yd, zd, data);
if (particle == null) {
sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.particle.notFound", name));
return true;
}
sender.sendMessage(new TranslationContainer("commands.particle.success", new String[] { name, String.valueOf(count) }));
Random random = new Random(System.currentTimeMillis());
for (int i = 0; i < count; i++) {
particle.setComponents(pos.x + (random.nextFloat() * 2 - 1) * xd, pos.y + (random.nextFloat() * 2 - 1) * yd, pos.z + (random.nextFloat() * 2 - 1) * zd);
level.addParticle(particle);
}
return true;
}
use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.
the class EntityEnderPearl method onUpdate.
@Override
public boolean onUpdate(int currentTick) {
if (this.closed) {
return false;
}
this.timing.startTiming();
boolean hasUpdate = super.onUpdate(currentTick);
if (this.isCollided && this.shootingEntity instanceof Player) {
this.shootingEntity.teleport(new Vector3(NukkitMath.floorDouble(this.x) + 0.5, this.y, NukkitMath.floorDouble(this.z) + 0.5), TeleportCause.ENDER_PEARL);
if ((((Player) this.shootingEntity).getGamemode() & 0x01) == 0)
this.shootingEntity.attack(5);
this.level.addSound(this, Sound.MOB_ENDERMEN_PORTAL);
}
if (this.age > 1200 || this.isCollided) {
this.kill();
hasUpdate = true;
}
this.timing.stopTiming();
return hasUpdate;
}
use of cn.nukkit.math.Vector3 in project Nukkit by Nukkit.
the class ContainerInventory method onOpen.
@Override
public void onOpen(Player who) {
super.onOpen(who);
ContainerOpenPacket pk = new ContainerOpenPacket();
pk.windowId = who.getWindowId(this);
pk.type = this.getType().getNetworkType();
InventoryHolder holder = this.getHolder();
if (holder instanceof Vector3) {
pk.x = (int) ((Vector3) holder).getX();
pk.y = (int) ((Vector3) holder).getY();
pk.z = (int) ((Vector3) holder).getZ();
} else {
pk.x = pk.y = pk.z = 0;
}
who.dataPacket(pk);
this.sendContents(who);
}
Aggregations