Skip to content

Commit

Permalink
Several updates per request by BluXDragon
Browse files Browse the repository at this point in the history
-PotionEffect stuff moved from Player.java to LivingEntity.java (closes
FallenMoonNetwork#45)
-Added projectile.aimAt()
-Added world.strikeLightning()
  • Loading branch information
gregcarlin committed Nov 23, 2012
1 parent 7bd96ad commit 2696deb
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 40 deletions.
42 changes: 42 additions & 0 deletions src/LivingEntity.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* Interface for living entities.
*/
Expand Down Expand Up @@ -144,4 +148,42 @@ public void dropLoot() {
public MobSpawner getSpawner() {
return getEntity().spawner;
}

/**
* Adds a potion Effect to the player
*
* @param effect the effect to add.
*/
public void addPotionEffect(PotionEffect effect) {
getEntity().d(effect.potionEffect);
}

/**
* Removes a potion Effect from player
*
* @param effect The potion effect to remove
*/

public void removePotionEffect(PotionEffect effect) {
OPotionEffect var3 = (OPotionEffect) getEntity().bl.get(effect.getType().getId());

getEntity().bl.remove(Integer.valueOf(effect.getType().getId()));
getEntity().c(var3);
}

/**
* Returns a Collection of potion effects active on the player
*
* @return List of potion effects
*/
@SuppressWarnings("unchecked")
public List<PotionEffect> getPotionEffects() {
Collection<OPotionEffect> potionEffects = getEntity().bz();
ArrayList<PotionEffect> list = new ArrayList<PotionEffect>();

for (OPotionEffect potionEffect : potionEffects) {
list.add(potionEffect.potionEffect);
}
return list;
}
}
38 changes: 0 additions & 38 deletions src/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1312,44 +1312,6 @@ public void updateInventory() {
getEntity().a(container, list);
}

/**
* Adds a potion Effect to the player
*
* @param effect the effect to add.
*/
public void addPotionEffect(PotionEffect effect) {
getEntity().d(effect.potionEffect);
}

/**
* Removes a potion Effect from player
*
* @param effect The potion effect to remove
*/

public void removePotionEffect(PotionEffect effect) {
OPotionEffect var3 = (OPotionEffect) getEntity().bl.get(effect.getType().getId());

getEntity().bl.remove(Integer.valueOf(effect.getType().getId()));
getEntity().c(var3);
}

/**
* Returns a Collection of potion effects active on the player
*
* @return List of potion effects
*/
@SuppressWarnings("unchecked")
public List<PotionEffect> getPotionEffects() {
Collection<OPotionEffect> potionEffects = getEntity().bz();
ArrayList<PotionEffect> list = new ArrayList<PotionEffect>();

for (OPotionEffect potionEffect : potionEffects) {
list.add(potionEffect.potionEffect);
}
return list;
}

/**
* Returns whether this player can receive damage.
* @return the disableDamage state
Expand Down
41 changes: 41 additions & 0 deletions src/Projectile.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,45 @@ public boolean setShooter(LivingEntity shooter) {
}
return false;
}

/**
* Aims this projectile at a location.
* May not work so well on anything that's not an instance of OIProjectile.
*
* @param x The x coordinate at which to aim it.
* @param y The y coordinate at which to aim it.
* @param z The z coordinate at which to aim it.
* @param power The power that it will be fired at.
* @param inaccuracy The inaccuracy with which it will be fired.
*/
public void aimAt(double x, double y, double z, float power, float inaccuracy) { //pretty much copied directly from OEntityArrow.c()
double var6 = x - entity.t;
double var8 = y + (double)0 - 0.699999988079071D - entity.u;
double var10 = z - entity.v;
double var12 = (double)OMathHelper.a(var6 * var6 + var10 * var10);
if(var12 >= 1.0E-7D) {
float var14 = (float)(Math.atan2(var10, var6) * 180.0D / 3.1415927410125732D) - 90.0F;
float var15 = (float)(-(Math.atan2(var8, var12) * 180.0D / 3.1415927410125732D));
double var16 = var6 / var12;
double var18 = var10 / var12;
entity.b(entity.t + var16, entity.u, entity.v + var18, var14, var15);
entity.M = 0.0F;
if(getEntity() instanceof OIProjectile) {
float var20 = (float)var12 * 0.2F;
((OIProjectile) getEntity()).c(var6, var8 + (double)var20, var10, power, inaccuracy);
}
}
}

/**
* Aims this projectile at a location.
* May not work so well on anything that's not an instance of OIProjectile.
*
* @param location The location at which to aim it.
* @param power The power that it will be fired at.
* @param inaccuracy The inaccuracy with which it will be fired.
*/
public void aimAt(Location location, float power, float inaccuracy) {
aimAt(location.x, location.y, location.z, power, inaccuracy);
}
}
24 changes: 22 additions & 2 deletions src/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -1053,11 +1053,31 @@ public int getGameMode() {
}

/**
* Launch a projectile in this world
* Launch a projectile in this world.
*
* @param p the projectile to launch
* @param p The projectile to launch.
*/
public void launchProjectile(Projectile p) {
getWorld().d(p.getEntity());
}

/**
* Have lightning strike a location.
*
* @param x The x coordinate to strike.
* @param y The y coordinate to strike.
* @param z The z coordinate to strike.
*/
public void strikeLightning(double x, double y, double z) {
getWorld().c(new OEntityLightningBolt(getWorld(), x, y, z));
}

/**
* Have lightning strike a location.
*
* @param location The location to strike.
*/
public void strikeLightning(Location location) {
strikeLightning(location.x, location.y, location.z);
}
}

0 comments on commit 2696deb

Please sign in to comment.