Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add item_projectile and fake_arrow DenizenEntityTypes
The item_projectile works like a snowball and fires hit and damage events (set to 0 damage) for the entire Bukkit server.
- Loading branch information
Showing
6 changed files
with
258 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/net/aufdemrand/denizen/utilities/entity/CraftItemProjectile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package net.aufdemrand.denizen.utilities.entity; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.craftbukkit.v1_8_R1.CraftServer; | ||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld; | ||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftHumanEntity; | ||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftItem; | ||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftLivingEntity; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.projectiles.ProjectileSource; | ||
|
||
public class CraftItemProjectile extends CraftItem implements DenizenCustomEntity, ItemProjectile { | ||
|
||
private boolean doesBounce; | ||
|
||
public CraftItemProjectile(CraftServer server, EntityItemProjectile entity) { | ||
super(server, entity); | ||
} | ||
|
||
@CreateEntity | ||
public static ItemProjectile createItemProjectile(Location location) { | ||
CraftWorld world = (CraftWorld) location.getWorld(); | ||
EntityItemProjectile entity = new EntityItemProjectile(world, location); | ||
return (ItemProjectile) entity.getBukkitEntity(); | ||
} | ||
|
||
@Override | ||
public EntityItemProjectile getHandle() { | ||
return (EntityItemProjectile) super.getHandle(); | ||
} | ||
|
||
@Override | ||
public String getEntityTypeName() { | ||
return "ITEM_PROJECTILE"; | ||
} | ||
|
||
@Override | ||
public ProjectileSource getShooter() { | ||
return getHandle().projectileSource; | ||
} | ||
|
||
@Override | ||
public void setShooter(ProjectileSource shooter) { | ||
if (shooter instanceof CraftLivingEntity) { | ||
getHandle().shooter = ((CraftLivingEntity) shooter).getHandle(); | ||
if (shooter instanceof CraftHumanEntity) { | ||
getHandle().shooterName = ((CraftHumanEntity) shooter).getName(); | ||
} | ||
} else { | ||
getHandle().shooter = null; | ||
getHandle().shooterName = null; | ||
} | ||
getHandle().projectileSource = shooter; | ||
} | ||
|
||
@Override | ||
public boolean doesBounce() { | ||
return doesBounce; | ||
} | ||
|
||
@Override | ||
public void setBounce(boolean doesBounce) { | ||
this.doesBounce = doesBounce; | ||
} | ||
|
||
|
||
@Override | ||
public void _INVALID_setShooter(LivingEntity livingEntity) { | ||
// Do nothing | ||
} | ||
|
||
@Override | ||
public LivingEntity _INVALID_getShooter() { | ||
return null; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/net/aufdemrand/denizen/utilities/entity/DenizenCustomEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.aufdemrand.denizen.utilities.entity; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.util.Vector; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
public interface DenizenCustomEntity extends Entity { | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CreateEntity {} | ||
|
||
public String getEntityTypeName(); | ||
} |
145 changes: 145 additions & 0 deletions
145
src/main/java/net/aufdemrand/denizen/utilities/entity/EntityItemProjectile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package net.aufdemrand.denizen.utilities.entity; | ||
|
||
import net.minecraft.server.v1_8_R1.*; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.craftbukkit.v1_8_R1.CraftServer; | ||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld; | ||
import org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory; | ||
|
||
import java.util.List; | ||
|
||
public class EntityItemProjectile extends EntityItem implements IProjectile { | ||
|
||
public EntityLiving shooter; | ||
public String shooterName; | ||
private int age; | ||
|
||
public EntityItemProjectile(CraftWorld craftWorld, Location location) { | ||
super(craftWorld.getHandle()); | ||
this.pickupDelay = Integer.MAX_VALUE; | ||
setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); | ||
this.a(0.25F, 0.25F); | ||
world.addEntity(this); | ||
bukkitEntity = new CraftItemProjectile((CraftServer) Bukkit.getServer(), this); | ||
} | ||
|
||
@Override | ||
public void s_() { | ||
K(); | ||
BlockPosition blockposition = new BlockPosition(locX, locY, locZ); | ||
IBlockData iblockdata = world.getType(blockposition); | ||
Block block = iblockdata.getBlock(); | ||
|
||
if (block.getMaterial() != Material.AIR) { | ||
AxisAlignedBB axisalignedbb = block.a(world, blockposition, iblockdata); | ||
|
||
if ((axisalignedbb != null) && (axisalignedbb.a(new Vec3D(locX, locY, locZ)))) { | ||
CraftEventFactory.callProjectileHitEvent(this); | ||
this.die(); | ||
} | ||
} | ||
age += 1; | ||
Vec3D vec3d = new Vec3D(locX, locY, locZ); | ||
Vec3D vec3d1 = new Vec3D(locX + motX, locY + motY, locZ + motZ); | ||
MovingObjectPosition movingobjectposition = world.rayTrace(vec3d, vec3d1, false, true, false); | ||
|
||
vec3d = new Vec3D(locX, locY, locZ); | ||
vec3d1 = new Vec3D(locX + motX, locY + motY, locZ + motZ); | ||
if (movingobjectposition != null) { | ||
vec3d1 = new Vec3D(movingobjectposition.pos.a, movingobjectposition.pos.b, movingobjectposition.pos.c); | ||
} | ||
|
||
Entity entity = null; | ||
List list = world.getEntities(this, getBoundingBox().a(motX, motY, motZ).grow(1.0D, 1.0D, 1.0D)); | ||
double d0 = 0.0D; | ||
|
||
for (Object aList : list) { | ||
Entity entity1 = (Entity) aList; | ||
|
||
if ((entity1.ad()) && ((entity1 != shooter) || (age >= 5))) { | ||
float f1 = 0.3F; | ||
AxisAlignedBB axisalignedbb1 = entity1.getBoundingBox().grow(f1, f1, f1); | ||
MovingObjectPosition movingobjectposition1 = axisalignedbb1.a(vec3d, vec3d1); | ||
|
||
if (movingobjectposition1 != null) { | ||
double d1 = vec3d.distanceSquared(movingobjectposition1.pos); | ||
|
||
if ((d1 < d0) || (d0 == 0.0D)) { | ||
entity = entity1; | ||
d0 = d1; | ||
} | ||
} | ||
} | ||
} | ||
if (entity != null) { | ||
movingobjectposition = new MovingObjectPosition(entity); | ||
} | ||
if ((movingobjectposition != null) && (movingobjectposition.entity != null) && ((movingobjectposition.entity instanceof EntityHuman))) { | ||
EntityHuman entityhuman = (EntityHuman) movingobjectposition.entity; | ||
if ((entityhuman.abilities.isInvulnerable) || (((shooter instanceof EntityHuman)) && (!((EntityHuman) shooter).a(entityhuman)))) { | ||
movingobjectposition = null; | ||
} | ||
} | ||
if (movingobjectposition != null) { | ||
if (movingobjectposition.entity != null && movingobjectposition.entity instanceof EntityLiving) { | ||
movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.getShooter()), 0F); | ||
this.die(); | ||
} else if (movingobjectposition.a() != null) { | ||
if (block.getMaterial() != Material.AIR) { | ||
motX = ((float) (movingobjectposition.pos.a - locX)); | ||
motY = ((float) (movingobjectposition.pos.b - locY)); | ||
motZ = ((float) (movingobjectposition.pos.c - locZ)); | ||
float f3 = MathHelper.sqrt(motX * motX + motY * motY + motZ * motZ); | ||
locX -= motX / f3 * 0.0500000007450581D; | ||
locY -= motY / f3 * 0.0500000007450581D; | ||
locZ -= motZ / f3 * 0.0500000007450581D; | ||
CraftEventFactory.callProjectileHitEvent(this); | ||
this.die(); | ||
} | ||
} | ||
} | ||
|
||
locX += motX; | ||
locY += motY; | ||
locZ += motZ; | ||
float f3 = 0.99F; | ||
float f1 = 0.05F; | ||
motX *= f3; | ||
motY *= f3; | ||
motZ *= f3; | ||
motY -= f1; | ||
setPosition(locX, locY, locZ); | ||
checkBlockCollisions(); | ||
} | ||
|
||
@Override | ||
public void shoot(double d0, double d1, double d2, float f, float f1) { | ||
float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2); | ||
|
||
d0 /= f2; | ||
d1 /= f2; | ||
d2 /= f2; | ||
d0 += random.nextGaussian() * 0.007499999832361937D * f1; | ||
d1 += random.nextGaussian() * 0.007499999832361937D * f1; | ||
d2 += random.nextGaussian() * 0.007499999832361937D * f1; | ||
d0 *= f; | ||
d1 *= f; | ||
d2 *= f; | ||
motX = d0; | ||
motY = d1; | ||
motZ = d2; | ||
float f3 = MathHelper.sqrt(d0 * d0 + d2 * d2); | ||
|
||
lastYaw = yaw = (float) (Math.atan2(d0, d2) * 180.0D / 3.1415927410125732D); | ||
lastPitch = pitch = (float) (Math.atan2(d1, f3) * 180.0D / 3.1415927410125732D); | ||
} | ||
|
||
public EntityLiving getShooter() { | ||
if (this.shooter == null && this.shooterName != null && this.shooterName.length() > 0) { | ||
this.shooter = this.world.a(this.shooterName); | ||
} | ||
|
||
return this.shooter; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/net/aufdemrand/denizen/utilities/entity/ItemProjectile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.aufdemrand.denizen.utilities.entity; | ||
|
||
import org.bukkit.entity.Item; | ||
import org.bukkit.entity.Projectile; | ||
|
||
public interface ItemProjectile extends Item, Projectile { | ||
} |