use of net.minecraft.server.v1_8_R2.EntityArmorStand in project VehiclesPlus2.0 by legofreak107.
the class Bike method Bike.
public static void Bike(PacketPlayInSteerVehicle ppisv, Player p) {
ArmorStand a2 = (ArmorStand) p.getVehicle();
Seat s = plugin.seatInfo.get(a2);
ArmorStand a = (ArmorStand) s.parent;
Vehicle v = plugin.vehicleInfo.get(a);
if (p.getOpenInventory() != null && p.getOpenInventory() instanceof PlayerInventory) {
p.openInventory(v.inv);
}
float forward = ppisv.b();
float side = ppisv.a();
if (v.fuelbar == null) {
BossBar b = Bukkit.createBossBar("fuel" + v.owner, BarColor.GREEN, BarStyle.SOLID);
v.fuelbar = b;
}
Location tloc = a2.getLocation().clone();
Location smoke = tloc.add(tloc.getDirection().setY(0).normalize().multiply(-1.5));
smoke.getWorld().spawnParticle(Particle.SMOKE_LARGE, smoke.getX(), smoke.getY() + 1, smoke.getZ(), 1, 0, 0, 0, 0);
v.fuelbar.setTitle("Fuel: " + (int) (v.fuel / v.maxFuel * 100) + "%");
v.fuelbar.setProgress((v.fuel / v.maxFuel));
if (!v.parts.ENGINE) {
} else {
if (v.fuelbar.getPlayers().contains(p)) {
} else {
v.fuelbar.addPlayer(p);
v.fuelbar.setVisible(true);
}
if (v.fuel <= 0.5) {
v.fuelbar.setTitle("Out of fuel!");
} else {
v.fuel -= v.fualUsage / 2;
if (forward > 0) {
// Forward[W]
int broken = randInt(0, 20000);
int brokenEngine = randInt(0, 20000);
if (brokenEngine == 0) {
v.parts.ENGINE = false;
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 10, 10);
p.sendMessage("�2It looks like you have blown up your engine...");
} else if (broken == 1) {
v.parts.WHEELFL = false;
p.sendMessage("�2It looks like your rear tire is flat.");
} else if (broken == 2) {
v.parts.WHEELFR = false;
p.sendMessage("�2It looks like your front tire is flat.");
}
v.fuel -= v.fualUsage / 2;
if (v.curSpeed <= v.fspeed || v.curSpeed == 0) {
v.curSpeed = v.curSpeed += v.acceleration / 2;
}
if (!v.parts.WHEELFL || !v.parts.WHEELFR || !v.parts.WHEELRL || !v.parts.WHEELRR) {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed / 4));
} else {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
}
if (side > 0) {
// Side[A]
v.skinHolder.setHeadPose(new EulerAngle(0, 0, 170));
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
v.steering = (int) (v.turnSpeed / 2);
} else if (side < 0) {
// Side[D]
v.skinHolder.setHeadPose(new EulerAngle(0, 0, -170));
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
v.steering = -(int) (v.turnSpeed / 2);
} else {
v.steering = 0;
v.skinHolder.setHeadPose(new EulerAngle(0, 0, 0));
}
} else if (forward < 0) {
// Reverse[S]
v.skinHolder.setHeadPose(new EulerAngle(0, 0, 0));
v.fuel -= v.fualUsage / 2;
Location loc1 = new Location(a.getWorld(), a.getLocation().getBlockX() + 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
Location loc2 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
Location loc3 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() + 1);
Location loc4 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() - 1);
Location loc5 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
if (v.curSpeed >= -v.bspeed || v.curSpeed == 0) {
v.curSpeed = v.curSpeed -= v.acceleration * 2;
}
if ((loc1.getBlock().getType() != Material.AIR && loc1.getBlock().getType() != Material.LONG_GRASS && loc1.getBlock().getType() != Material.CHORUS_FLOWER && loc1.getBlock().getType() != Material.YELLOW_FLOWER && loc1.getBlock().getType() != Material.RED_ROSE && loc1.getBlock().getType() != Material.WHEAT) || (loc2.getBlock().getType() != Material.AIR && loc2.getBlock().getType() != Material.LONG_GRASS && loc2.getBlock().getType() != Material.CHORUS_FLOWER && loc2.getBlock().getType() != Material.YELLOW_FLOWER && loc2.getBlock().getType() != Material.RED_ROSE && loc2.getBlock().getType() != Material.WHEAT) || (loc3.getBlock().getType() != Material.AIR && loc3.getBlock().getType() != Material.LONG_GRASS && loc3.getBlock().getType() != Material.CHORUS_FLOWER && loc3.getBlock().getType() != Material.YELLOW_FLOWER && loc3.getBlock().getType() != Material.RED_ROSE && loc3.getBlock().getType() != Material.WHEAT) || (loc4.getBlock().getType() != Material.AIR && loc4.getBlock().getType() != Material.LONG_GRASS && loc4.getBlock().getType() != Material.CHORUS_FLOWER && loc4.getBlock().getType() != Material.YELLOW_FLOWER && loc4.getBlock().getType() != Material.RED_ROSE && loc4.getBlock().getType() != Material.WHEAT) && loc5.getBlock().getType() != Material.AIR) {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
// a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -1, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(- BwdDriveSpeed.get(a.getUniqueId())));
} else {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
}
if (side > 0) {
// Side[A]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
v.steering = (int) (v.turnSpeed / 2);
} else if (side < 0) {
// Side[D]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
v.steering = -(int) (v.turnSpeed / 2);
} else {
v.steering = 0;
v.skinHolder.setHeadPose(new EulerAngle(0, 0, 0));
}
} else {
v.steering = 0;
if (v.curSpeed > v.acceleration) {
v.curSpeed = v.curSpeed -= v.acceleration;
} else if (v.curSpeed < -v.acceleration) {
v.curSpeed = v.curSpeed += v.acceleration;
} else {
v.curSpeed = 0;
}
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
}
}
}
}
use of net.minecraft.server.v1_8_R2.EntityArmorStand in project VehiclesPlus2.0 by legofreak107.
the class Car method Car.
public static void Car(PacketPlayInSteerVehicle ppisv, Player p) {
ArmorStand a2 = (ArmorStand) p.getVehicle();
Seat s = plugin.seatInfo.get(a2);
ArmorStand a = (ArmorStand) s.parent;
Vehicle v = plugin.vehicleInfo.get(a);
if (v.running) {
if (v.curSpeed > 0)
v.mileAge += 0.005 * v.curSpeed;
if (v.curSpeed < 0)
v.mileAge -= 0.005 * v.curSpeed;
if (p.getOpenInventory() != null && p.getOpenInventory() instanceof PlayerInventory) {
p.openInventory(v.inv);
}
float forward = ppisv.b();
float side = ppisv.a();
if (v.fuelbar == null) {
BossBar b = Bukkit.createBossBar("fuel" + v.owner, BarColor.GREEN, BarStyle.SOLID);
v.fuelbar = b;
}
Location tloc = a2.getLocation().clone();
Location smoke = tloc.add(tloc.getDirection().setY(0).normalize().multiply(-1.5));
smoke.getWorld().spawnParticle(Particle.SMOKE_LARGE, smoke.getX(), smoke.getY() + 1, smoke.getZ(), 1, 0, 0, 0, 0);
v.fuelbar.setTitle("�2Fuel: " + (int) (v.fuel / v.maxFuel * 100) + "%");
v.fuelbar.setProgress((v.fuel / v.maxFuel));
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder("�6Mileage: " + (int) v.mileAge).create());
if (!v.parts.ENGINE) {
} else {
if (v.fuelbar.getPlayers().contains(p)) {
} else {
v.fuelbar.addPlayer(p);
v.fuelbar.setVisible(true);
}
if (v.fuel <= 0.5) {
v.fuelbar.setTitle("Out of fuel!");
v.running = false;
} else {
v.fuel -= v.fualUsage / 2;
if (forward > 0) {
// Forward[W]
int broken = randInt(0, (int) (20000));
int brokenEngine = randInt(0, (int) (5000000 / (v.mileAge + 1)));
int oil = randInt(0, 100);
if (brokenEngine == 0) {
v.parts.ENGINE = false;
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 10, 10);
p.sendMessage("�2It looks like you have blown up your engine...");
} else if (broken == 1) {
v.parts.WHEELFL = false;
p.sendMessage("�2It looks like your front left tire is flat.");
} else if (broken == 2) {
v.parts.WHEELFR = false;
p.sendMessage("�2It looks like your front right tire is flat.");
} else if (broken == 3) {
v.parts.WHEELRL = false;
p.sendMessage("�2It looks like your rear left tire is flat.");
} else if (broken == 4) {
v.parts.WHEELRR = false;
p.sendMessage("�2It looks like your rear right tire is flat.");
}
v.fuel -= v.fualUsage / 2;
if (v.curSpeed <= v.fspeed || v.curSpeed == 0) {
v.curSpeed = v.curSpeed += v.acceleration / 2;
}
if (!v.parts.WHEELFL || !v.parts.WHEELFR || !v.parts.WHEELRL || !v.parts.WHEELRR) {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed / 4));
} else {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
}
if (side > 0) {
// Side[A]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
v.steering = (int) (v.turnSpeed / 2);
} else if (side < 0) {
// Side[D]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
v.steering = -(int) (v.turnSpeed / 2);
} else {
v.steering = 0;
}
} else if (forward < 0) {
// Reverse[S]
v.fuel -= v.fualUsage / 2;
Location loc1 = new Location(a.getWorld(), a.getLocation().getBlockX() + 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
Location loc2 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
Location loc3 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() + 1);
Location loc4 = new Location(a.getWorld(), a.getLocation().getBlockX(), a.getLocation().getBlockY(), a.getLocation().getBlockZ() - 1);
Location loc5 = new Location(a.getWorld(), a.getLocation().getBlockX() - 1, a.getLocation().getBlockY(), a.getLocation().getBlockZ());
if (v.curSpeed >= -v.bspeed || v.curSpeed == 0) {
v.curSpeed = v.curSpeed -= v.acceleration * 2;
}
if ((loc1.getBlock().getType() != Material.AIR && loc1.getBlock().getType() != Material.LONG_GRASS && loc1.getBlock().getType() != Material.CHORUS_FLOWER && loc1.getBlock().getType() != Material.YELLOW_FLOWER && loc1.getBlock().getType() != Material.RED_ROSE && loc1.getBlock().getType() != Material.WHEAT) || (loc2.getBlock().getType() != Material.AIR && loc2.getBlock().getType() != Material.LONG_GRASS && loc2.getBlock().getType() != Material.CHORUS_FLOWER && loc2.getBlock().getType() != Material.YELLOW_FLOWER && loc2.getBlock().getType() != Material.RED_ROSE && loc2.getBlock().getType() != Material.WHEAT) || (loc3.getBlock().getType() != Material.AIR && loc3.getBlock().getType() != Material.LONG_GRASS && loc3.getBlock().getType() != Material.CHORUS_FLOWER && loc3.getBlock().getType() != Material.YELLOW_FLOWER && loc3.getBlock().getType() != Material.RED_ROSE && loc3.getBlock().getType() != Material.WHEAT) || (loc4.getBlock().getType() != Material.AIR && loc4.getBlock().getType() != Material.LONG_GRASS && loc4.getBlock().getType() != Material.CHORUS_FLOWER && loc4.getBlock().getType() != Material.YELLOW_FLOWER && loc4.getBlock().getType() != Material.RED_ROSE && loc4.getBlock().getType() != Material.WHEAT) && loc5.getBlock().getType() != Material.AIR) {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
// a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -1, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(- BwdDriveSpeed.get(a.getUniqueId())));
} else {
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
}
if (side > 0) {
// Side[A]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() + v.turnSpeed, a.getLocation().getPitch());
v.steering = (int) (v.turnSpeed / 2);
} else if (side < 0) {
// Side[D]
EntityArmorStand a1 = ((CraftArmorStand) a).getHandle();
a1.setLocation(a.getLocation().getX(), a.getLocation().getY(), a.getLocation().getZ(), a.getLocation().getYaw() - v.turnSpeed, a.getLocation().getPitch());
v.steering = -(int) (v.turnSpeed / 2);
} else {
v.steering = 0;
}
} else {
v.steering = 0;
if (v.curSpeed > v.acceleration) {
v.curSpeed = v.curSpeed -= v.acceleration;
} else if (v.curSpeed < -v.acceleration) {
v.curSpeed = v.curSpeed += v.acceleration;
} else {
v.curSpeed = 0;
}
a.setVelocity(new Vector(a.getLocation().getDirection().multiply(0.5).getX(), -v.curSpeed, a.getLocation().getDirection().multiply(0.5).getZ()).multiply(v.curSpeed));
}
}
}
}
}
use of net.minecraft.server.v1_8_R2.EntityArmorStand in project MyPet by xXKeyleXx.
the class ControlTarget method shouldStart.
@Override
public boolean shouldStart() {
if (controlPathfinderGoal == null) {
if (petEntity.getPathfinder().hasGoal("Control")) {
controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control");
}
}
if (controlPathfinderGoal == null) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
if (controlPathfinderGoal.moveTo != null && petEntity.canMove()) {
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
return false;
}
}
for (EntityLiving entityLiving : this.petEntity.world.a(EntityLiving.class, this.petEntity.getBoundingBox().grow((double) this.range, 4.0D, (double) this.range))) {
if (entityLiving != petEntity && !(entityLiving instanceof EntityArmorStand)) {
if (entityLiving instanceof EntityPlayer) {
Player targetPlayer = (Player) entityLiving.getBukkitEntity();
if (myPet.getOwner().equals(targetPlayer)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
continue;
}
} else if (entityLiving instanceof EntityTameableAnimal) {
EntityTameableAnimal tameable = (EntityTameableAnimal) entityLiving;
if (tameable.isTamed() && tameable.getOwner() != null) {
Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
if (myPet.getOwner().equals(tameableOwner)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), tameableOwner, true)) {
continue;
}
}
} else if (entityLiving instanceof EntityMyPet) {
MyPet targetMyPet = ((EntityMyPet) entityLiving).getMyPet();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
continue;
}
}
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityLiving.getBukkitEntity())) {
continue;
}
if (behaviorSkill != null) {
if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
if (entityLiving instanceof EntityTameableAnimal) {
continue;
} else if (entityLiving instanceof EntityMyPet) {
continue;
} else if (entityLiving instanceof EntityPlayer) {
continue;
}
}
}
controlPathfinderGoal.stopControl();
this.target = entityLiving;
return true;
}
}
}
return false;
}
use of net.minecraft.server.v1_8_R2.EntityArmorStand in project MyPet by xXKeyleXx.
the class MeleeAttack method shouldStart.
@Override
public boolean shouldStart() {
if (myPet.getDamage() <= 0) {
return false;
}
if (!this.petEntity.hasTarget()) {
return false;
}
EntityLiving targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle();
if (targetEntity instanceof EntityArmorStand) {
return false;
}
if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.f(targetEntity.locX, targetEntity.getBoundingBox().b, targetEntity.locZ) >= 20) {
return false;
}
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill != null && behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Friendly) {
return false;
}
if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Raid) {
if (targetEntity instanceof EntityTameableAnimal && ((EntityTameableAnimal) targetEntity).isTamed()) {
return false;
}
if (targetEntity instanceof EntityMyPet) {
return false;
}
if (targetEntity instanceof EntityPlayer) {
return false;
}
}
}
this.targetEntity = targetEntity;
return true;
}
use of net.minecraft.server.v1_8_R2.EntityArmorStand in project MyPet by xXKeyleXx.
the class ControlTarget method shouldStart.
@Override
public boolean shouldStart() {
if (controlPathfinderGoal == null) {
if (petEntity.getPathfinder().hasGoal("Control")) {
controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control");
}
}
if (controlPathfinderGoal == null) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
if (controlPathfinderGoal.moveTo != null && petEntity.canMove()) {
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
return false;
}
}
for (EntityLiving entityLiving : this.petEntity.world.a(EntityLiving.class, this.petEntity.getBoundingBox().grow(this.range, 4.0D, this.range))) {
if (entityLiving != petEntity && !(entityLiving instanceof EntityArmorStand)) {
if (entityLiving instanceof EntityPlayer) {
Player targetPlayer = (Player) entityLiving.getBukkitEntity();
if (myPet.getOwner().equals(targetPlayer)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
continue;
}
} else if (entityLiving instanceof EntityTameableAnimal) {
EntityTameableAnimal tameable = (EntityTameableAnimal) entityLiving;
if (tameable.isTamed() && tameable.getOwner() != null) {
Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
if (myPet.getOwner().equals(tameableOwner)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), tameableOwner, true)) {
continue;
}
}
} else if (entityLiving instanceof EntityMyPet) {
MyPet targetMyPet = ((EntityMyPet) entityLiving).getMyPet();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
continue;
}
}
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityLiving.getBukkitEntity())) {
continue;
}
if (behaviorSkill != null) {
if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
if (entityLiving instanceof EntityTameableAnimal) {
continue;
} else if (entityLiving instanceof EntityMyPet) {
continue;
} else if (entityLiving instanceof EntityPlayer) {
continue;
}
}
}
controlPathfinderGoal.stopControl();
this.target = entityLiving;
return true;
}
}
}
return false;
}
Aggregations