initial commit

This commit is contained in:
Sen 2025-03-11 00:23:54 +01:00 committed by Sen
parent 3c9ee26b06
commit 22186c33b9
1458 changed files with 282792 additions and 0 deletions

View file

@ -0,0 +1,634 @@
package game.entity.projectile;
import java.util.List;
import game.ExtMath;
import game.block.Block;
import game.enchantment.EnchantmentHelper;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
import game.entity.types.IObjectData;
import game.entity.types.IProjectile;
import game.init.BlockRegistry;
import game.init.Config;
import game.init.Items;
import game.init.SoundEvent;
import game.item.ItemStack;
import game.material.Material;
import game.nbt.NBTTagCompound;
import game.renderer.particle.ParticleType;
import game.world.BlockPos;
import game.world.BoundingBox;
import game.world.HitPosition;
import game.world.State;
import game.world.Vec3;
import game.world.World;
public class EntityArrow extends Entity implements IProjectile, IObjectData
{
private int xTile = -1;
private int yTile = -1;
private int zTile = -1;
private Block inTile;
private int inData;
private boolean inGround;
/** 1 if the player can pick up the arrow */
public int canBePickedUp;
/** Seems to be some sort of timer for animating an arrow. */
public int arrowShake;
/** The owner of this arrow. */
public Entity shootingEntity;
private int ticksInGround;
private int ticksInAir;
private double damage = 2.0D;
/** The amount of knockback an arrow applies when it hits a mob. */
private int knockbackStrength;
public EntityArrow(World worldIn)
{
super(worldIn);
this.renderDistWeight = 10.0D;
this.setSize(0.5F, 0.5F);
}
public EntityArrow(World worldIn, double x, double y, double z)
{
super(worldIn);
this.renderDistWeight = 10.0D;
this.setSize(0.5F, 0.5F);
this.setPosition(x, y, z);
}
public EntityArrow(World worldIn, double x, double y, double z, int data)
{
this(worldIn, x, y, z);
Entity entity2 = worldIn.getEntityByID(data);
if(entity2 instanceof EntityLiving) {
this.shootingEntity = entity2;
}
}
public EntityArrow(World worldIn, EntityLiving shooter, EntityLiving target, float velocity, float innacuracy)
{
super(worldIn);
this.renderDistWeight = 10.0D;
this.shootingEntity = shooter;
if (shooter.isPlayer())
{
this.canBePickedUp = 1;
}
this.posY = shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D;
double d0 = target.posX - shooter.posX;
double d1 = target.getEntityBoundingBox().minY + (double)(target.height / 3.0F) - this.posY;
double d2 = target.posZ - shooter.posZ;
double d3 = (double)ExtMath.sqrtd(d0 * d0 + d2 * d2);
if (d3 >= 1.0E-7D)
{
float f = (float)(ExtMath.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
float f1 = (float)(-(ExtMath.atan2(d1, d3) * 180.0D / Math.PI));
double d4 = d0 / d3;
double d5 = d2 / d3;
this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f, f1);
float f2 = (float)(d3 * 0.20000000298023224D);
this.setThrowableHeading(d0, d1 + (double)f2, d2, velocity, innacuracy);
}
}
public EntityArrow(World worldIn, EntityLiving shooter, float velocity)
{
super(worldIn);
this.renderDistWeight = 10.0D;
this.shootingEntity = shooter;
if (shooter.isPlayer())
{
this.canBePickedUp = 1;
}
this.setSize(0.5F, 0.5F);
this.setLocationAndAngles(shooter.posX, shooter.posY + (double)shooter.getEyeHeight(), shooter.posZ, shooter.rotYaw, shooter.rotPitch);
this.posX -= (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * 0.16F);
this.posY -= 0.10000000149011612D;
this.posZ -= (double)(ExtMath.sin(this.rotYaw / 180.0F * (float)Math.PI) * 0.16F);
this.setPosition(this.posX, this.posY, this.posZ);
this.motionX = (double)(-ExtMath.sin(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI));
this.motionZ = (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI));
this.motionY = (double)(-ExtMath.sin(this.rotPitch / 180.0F * (float)Math.PI));
this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, velocity * 1.5F, 1.0F);
}
protected void entityInit()
{
this.dataWatcher.addObject(16, Byte.valueOf((byte)0));
}
/**
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
*/
public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy)
{
float f = ExtMath.sqrtd(x * x + y * y + z * z);
x = x / (double)f;
y = y / (double)f;
z = z / (double)f;
x = x + this.rand.gaussian() * (double)(this.rand.chance() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy;
y = y + this.rand.gaussian() * (double)(this.rand.chance() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy;
z = z + this.rand.gaussian() * (double)(this.rand.chance() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy;
x = x * (double)velocity;
y = y * (double)velocity;
z = z * (double)velocity;
this.motionX = x;
this.motionY = y;
this.motionZ = z;
float f1 = ExtMath.sqrtd(x * x + z * z);
this.prevYaw = this.rotYaw = (float)(ExtMath.atan2(x, z) * 180.0D / Math.PI);
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(y, (double)f1) * 180.0D / Math.PI);
this.ticksInGround = 0;
}
public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean p_180426_10_)
{
this.setPosition(x, y, z);
this.setRotation(yaw, pitch);
}
/**
* Sets the velocity to the args. Args: x, y, z
*/
public void setVelocity(double x, double y, double z)
{
this.motionX = x;
this.motionY = y;
this.motionZ = z;
if (this.prevPitch == 0.0F && this.prevYaw == 0.0F)
{
float f = ExtMath.sqrtd(x * x + z * z);
this.prevYaw = this.rotYaw = (float)(ExtMath.atan2(x, z) * 180.0D / Math.PI);
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(y, (double)f) * 180.0D / Math.PI);
this.prevPitch = this.rotPitch;
this.prevYaw = this.rotYaw;
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotYaw, this.rotPitch);
this.ticksInGround = 0;
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.prevPitch == 0.0F && this.prevYaw == 0.0F)
{
float f = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.prevYaw = this.rotYaw = (float)(ExtMath.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(this.motionY, (double)f) * 180.0D / Math.PI);
}
BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
State iblockstate = this.worldObj.getState(blockpos);
Block block = iblockstate.getBlock();
if (block.getMaterial() != Material.air)
{
block.setBlockBoundsBasedOnState(this.worldObj, blockpos);
BoundingBox axisalignedbb = block.getCollisionBoundingBox(this.worldObj, blockpos, iblockstate);
if (axisalignedbb != null && axisalignedbb.isVecInside(new Vec3(this.posX, this.posY, this.posZ)))
{
this.inGround = true;
}
}
if (this.arrowShake > 0)
{
--this.arrowShake;
}
if (this.inGround)
{
int j = block.getMetaFromState(iblockstate);
if (block == this.inTile && j == this.inData)
{
++this.ticksInGround;
if (this.ticksInGround >= 1200)
{
this.setDead();
}
}
else
{
this.inGround = false;
this.motionX *= (double)(this.rand.floatv() * 0.2F);
this.motionY *= (double)(this.rand.floatv() * 0.2F);
this.motionZ *= (double)(this.rand.floatv() * 0.2F);
this.ticksInGround = 0;
this.ticksInAir = 0;
}
}
else
{
++this.ticksInAir;
Vec3 vec31 = new Vec3(this.posX, this.posY, this.posZ);
Vec3 vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
HitPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec31, vec3, false, true, false);
vec31 = new Vec3(this.posX, this.posY, this.posZ);
vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (movingobjectposition != null)
{
vec3 = new Vec3(movingobjectposition.vec.xCoord, movingobjectposition.vec.yCoord, movingobjectposition.vec.zCoord);
}
Entity entity = null;
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double d0 = 0.0D;
for (int i = 0; i < list.size(); ++i)
{
Entity entity1 = (Entity)list.get(i);
if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5))
{
float f1 = 0.3F;
BoundingBox axisalignedbb1 = entity1.getEntityBoundingBox().expand((double)f1, (double)f1, (double)f1);
HitPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3);
if (movingobjectposition1 != null)
{
double d1 = vec31.squareDistanceTo(movingobjectposition1.vec);
if (d1 < d0 || d0 == 0.0D)
{
entity = entity1;
d0 = d1;
}
}
}
}
if (entity != null)
{
movingobjectposition = new HitPosition(entity);
}
// if (movingobjectposition != null && movingobjectposition.entity != null && movingobjectposition.entity.isPlayer())
// {
// EntityNPC entityplayer = (EntityNPC)movingobjectposition.entity;
//
// if (entityplayer.creative || this.shootingEntity.isPlayer() && !((EntityNPC)this.shootingEntity).canAttackPlayer(entityplayer))
// {
// movingobjectposition = null;
// }
// }
if (movingobjectposition != null)
{
if (movingobjectposition.entity != null)
{
float f2 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
int l = ExtMath.ceild((double)f2 * this.damage);
if (this.getIsCritical())
{
l += this.rand.zrange(l / 2 + 2);
}
DamageSource damagesource;
if (this.shootingEntity == null)
{
damagesource = DamageSource.causeShotDamage(this, this);
}
else
{
damagesource = DamageSource.causeShotDamage(this, this.shootingEntity);
}
if (this.isBurning()) // && !(movingobjectposition.entityHit instanceof EntityAITakePlace))
{
movingobjectposition.entity.setFire(5);
}
if ((this.worldObj.client || Config.damageArrow) && movingobjectposition.entity.attackEntityFrom(damagesource, l))
{
if (movingobjectposition.entity instanceof EntityLiving)
{
EntityLiving entitylivingbase = (EntityLiving)movingobjectposition.entity;
if (!this.worldObj.client)
{
entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
}
if (this.knockbackStrength > 0)
{
float f7 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (f7 > 0.0F)
{
movingobjectposition.entity.addKnockback(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f7, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f7);
}
}
if (this.shootingEntity instanceof EntityLiving)
{
EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
EnchantmentHelper.applyArthropodEnchantments((EntityLiving)this.shootingEntity, entitylivingbase);
}
// if (this.shootingEntity != null && movingobjectposition.entityHit != this.shootingEntity && movingobjectposition.entityHit.isPlayer() && this.shootingEntity.isPlayer())
// {
// ((EntityNPCMP)this.shootingEntity).netHandler.sendPacket(new S29PacketSoundEffect(
// "random.successful_hit", shootingEntity.posX,
// shootingEntity.posY + (double)shootingEntity.getEyeHeight(), shootingEntity.posZ, 0.18F, 0.45F));
// }
}
this.playSound(SoundEvent.BOWHIT, 1.0F, 1.2F / (this.rand.floatv() * 0.2F + 0.9F));
// if (!(movingobjectposition.entityHit instanceof EntityAITakePlace))
// {
this.setDead();
// }
}
else
{
this.motionX *= -0.10000000149011612D;
this.motionY *= -0.10000000149011612D;
this.motionZ *= -0.10000000149011612D;
this.rotYaw += 180.0F;
this.prevYaw += 180.0F;
this.ticksInAir = 0;
}
}
else
{
BlockPos blockpos1 = movingobjectposition.block;
this.xTile = blockpos1.getX();
this.yTile = blockpos1.getY();
this.zTile = blockpos1.getZ();
State iblockstate1 = this.worldObj.getState(blockpos1);
this.inTile = iblockstate1.getBlock();
this.inData = this.inTile.getMetaFromState(iblockstate1);
this.motionX = (double)((float)(movingobjectposition.vec.xCoord - this.posX));
this.motionY = (double)((float)(movingobjectposition.vec.yCoord - this.posY));
this.motionZ = (double)((float)(movingobjectposition.vec.zCoord - this.posZ));
float f5 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
this.posX -= this.motionX / (double)f5 * 0.05000000074505806D;
this.posY -= this.motionY / (double)f5 * 0.05000000074505806D;
this.posZ -= this.motionZ / (double)f5 * 0.05000000074505806D;
this.playSound(SoundEvent.BOWHIT, 1.0F, 1.2F / (this.rand.floatv() * 0.2F + 0.9F));
this.inGround = true;
this.arrowShake = 7;
this.setIsCritical(false);
if (this.inTile.getMaterial() != Material.air)
{
this.inTile.onEntityCollidedWithBlock(this.worldObj, blockpos1, iblockstate1, this);
}
}
}
if (this.getIsCritical())
{
for (int k = 0; k < 4; ++k)
{
this.worldObj.spawnParticle(ParticleType.CRIT, this.posX + this.motionX * (double)k / 4.0D, this.posY + this.motionY * (double)k / 4.0D, this.posZ + this.motionZ * (double)k / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ);
}
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
float f3 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotYaw = (float)(ExtMath.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
for (this.rotPitch = (float)(ExtMath.atan2(this.motionY, (double)f3) * 180.0D / Math.PI); this.rotPitch - this.prevPitch < -180.0F; this.prevPitch -= 360.0F)
{
;
}
while (this.rotPitch - this.prevPitch >= 180.0F)
{
this.prevPitch += 360.0F;
}
while (this.rotYaw - this.prevYaw < -180.0F)
{
this.prevYaw -= 360.0F;
}
while (this.rotYaw - this.prevYaw >= 180.0F)
{
this.prevYaw += 360.0F;
}
this.rotPitch = this.prevPitch + (this.rotPitch - this.prevPitch) * 0.2F;
this.rotYaw = this.prevYaw + (this.rotYaw - this.prevYaw) * 0.2F;
float f4 = 0.99F;
float f6 = 0.05F;
if (this.isInLiquid())
{
for (int i1 = 0; i1 < 4; ++i1)
{
float f8 = 0.25F;
this.worldObj.spawnParticle(ParticleType.WATER_BUBBLE, this.posX - this.motionX * (double)f8, this.posY - this.motionY * (double)f8, this.posZ - this.motionZ * (double)f8, this.motionX, this.motionY, this.motionZ);
}
f4 = 0.6F;
}
if (this.isWet())
{
this.extinguish();
}
this.motionX *= (double)f4;
this.motionY *= (double)f4;
this.motionZ *= (double)f4;
this.motionY -= (double)f6;
this.setPosition(this.posX, this.posY, this.posZ);
this.doBlockCollisions();
}
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
tagCompound.setShort("xTile", (short)this.xTile);
tagCompound.setShort("yTile", (short)this.yTile);
tagCompound.setShort("zTile", (short)this.zTile);
tagCompound.setShort("life", (short)this.ticksInGround);
String resourcelocation = BlockRegistry.REGISTRY.getNameForObject(this.inTile);
tagCompound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
tagCompound.setByte("inData", (byte)this.inData);
tagCompound.setByte("shake", (byte)this.arrowShake);
tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
tagCompound.setByte("pickup", (byte)this.canBePickedUp);
tagCompound.setDouble("damage", this.damage);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
this.xTile = tagCompund.getShort("xTile");
this.yTile = tagCompund.getShort("yTile");
this.zTile = tagCompund.getShort("zTile");
this.ticksInGround = tagCompund.getShort("life");
if (tagCompund.hasKey("inTile", 8))
{
this.inTile = BlockRegistry.getByIdFallback(tagCompund.getString("inTile"));
}
else
{
this.inTile = BlockRegistry.getBlockById(tagCompund.getByte("inTile") & 255);
}
this.inData = tagCompund.getByte("inData") & 255;
this.arrowShake = tagCompund.getByte("shake") & 255;
this.inGround = tagCompund.getByte("inGround") == 1;
if (tagCompund.hasKey("damage", 99))
{
this.damage = tagCompund.getDouble("damage");
}
if (tagCompund.hasKey("pickup", 99))
{
this.canBePickedUp = tagCompund.getByte("pickup");
}
else if (tagCompund.hasKey("player", 99))
{
this.canBePickedUp = tagCompund.getBoolean("player") ? 1 : 0;
}
}
/**
* Called by a player entity when they collide with an entity
*/
public void onCollideWithPlayer(EntityNPC entityIn)
{
if (!this.worldObj.client && this.inGround && this.arrowShake <= 0)
{
boolean flag = this.canBePickedUp == 1; // || this.canBePickedUp == 2 && entityIn.creative;
if (this.canBePickedUp == 1 && !entityIn.inventory.addItemStackToInventory(new ItemStack(Items.arrow, 1)))
{
flag = false;
}
if (flag)
{
this.playSound(SoundEvent.POP, 0.2F, ((this.rand.floatv() - this.rand.floatv()) * 0.7F + 1.0F) * 2.0F);
entityIn.onItemPickup(this, 1);
this.setDead();
}
}
}
/**
* returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
* prevent them from trampling crops
*/
protected boolean canTriggerWalking()
{
return false;
}
public void setDamage(double damageIn)
{
this.damage = damageIn;
}
public double getDamage()
{
return this.damage;
}
/**
* Sets the amount of knockback the arrow applies when it hits a mob.
*/
public void setKnockbackStrength(int knockbackStrengthIn)
{
this.knockbackStrength = knockbackStrengthIn;
}
/**
* If returns false, the item will not inflict any damage against entities.
*/
public boolean canAttackWithItem()
{
return false;
}
public float getEyeHeight()
{
return 0.0F;
}
/**
* Whether the arrow has a stream of critical hit particles flying behind it.
*/
public void setIsCritical(boolean critical)
{
byte b0 = this.dataWatcher.getWatchableObjectByte(16);
if (critical)
{
this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 1)));
}
else
{
this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -2)));
}
}
/**
* Whether the arrow has a stream of critical hit particles flying behind it.
*/
public boolean getIsCritical()
{
byte b0 = this.dataWatcher.getWatchableObjectByte(16);
return (b0 & 1) != 0;
}
public int getTrackingRange() {
return 64;
}
public int getUpdateFrequency() {
return 20;
}
public boolean isSendingVeloUpdates() {
return false;
}
public int getPacketData() {
return this.shootingEntity != null ? this.shootingEntity.getId() : this.getId();
}
public boolean hasSpawnVelocity() {
return true;
}
}

View file

@ -0,0 +1,169 @@
package game.entity.projectile;
import game.entity.DamageSource;
import game.entity.npc.EntityGargoyle;
import game.entity.types.EntityLiving;
import game.init.Config;
import game.potion.Potion;
import game.potion.PotionEffect;
import game.world.HitPosition;
import game.world.World;
public class EntityBox extends EntityProjectile
{
public EntityBox(World worldIn)
{
super(worldIn);
this.setSize(0.3125F, 0.3125F);
}
public EntityBox(World worldIn, EntityLiving shooter, double accelX, double accelY, double accelZ, boolean invul)
{
super(worldIn, shooter, accelX, accelY, accelZ, 0.2f, 2.0f);
this.setSize(0.3125F, 0.3125F);
this.setInvulnerable(invul);
}
/**
* Return the motion factor for this projectile. The factor is multiplied by the original motion.
*/
protected float getMotionFactor()
{
return this.isInvulnerable() ? 0.98F : super.getMotionFactor();
}
public EntityBox(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
this.setSize(0.3125F, 0.3125F);
}
/**
* Returns true if the entity is on fire. Used by render to add the fire effect on rendering.
*/
public boolean isBurning()
{
return false;
}
// /**
// * Explosion resistance of a block relative to this entity
// */
// public float getExplosionResistance(Explosion explosionIn, World worldIn, BlockPos pos, IBlockState blockStateIn)
// {
// float f = super.getExplosionResistance(explosionIn, worldIn, pos, blockStateIn);
// Block block = blockStateIn.getBlock();
//
// if (this.isInvulnerable() && EntityWither.canDestroyBlock(block))
// {
// f = Math.min(0.8F, f);
// }
//
// return f;
// }
/**
* Called when this EntityFireball hits a block or entity.
*/
protected void onImpact(HitPosition movingObject)
{
if (!this.worldObj.client)
{
if (movingObject.entity != null)
{
if(Config.damageFlyingBox) {
if (this.shootingEntity != null)
{
if (movingObject.entity.attackEntityFrom(DamageSource.causeMobDamage(this.shootingEntity),
this.isInvulnerable() ? this.rand.range(10, 14) : this.rand.range(8, 10)))
{
if (!movingObject.entity.isEntityAlive())
{
this.shootingEntity.heal(this.rand.range(5, this.isInvulnerable() ? 10 : 7));
}
else
{
this.applyEnchantments(this.shootingEntity, movingObject.entity);
}
}
}
else
{
movingObject.entity.attackEntityFrom(DamageSource.magic, 5);
}
}
if (movingObject.entity instanceof EntityLiving && !(movingObject.entity instanceof EntityGargoyle))
{
// int i = 0;
//
// if (this.worldObj.getDifficulty() == Difficulty.NORMAL)
// {
// i = 10;
// }
// else if (this.worldObj.getDifficulty() == Difficulty.HARD)
// {
// i = 40;
// }
//
// if (i > 0)
// {
((EntityLiving)movingObject.entity).addEffect(new PotionEffect(Potion.moveSlowdown.id, 20 * this.rand.range(35, 55), this.rand.chance(1, 2, 5)));
// }
}
}
this.worldObj.newExplosion(this, this.posX, this.posY, this.posZ, this.rand.frange(1.0f, 3.0f), false, false, false);
this.setDead();
}
}
// public void onUpdate() {
// super.onUpdate();
// if(!this.worldObj.client && this.age++ >= 200)
// this.setDead();
// }
// public void writeEntityToNBT(NBTTagCompound tagCompound)
// {
// super.writeEntityToNBT(tagCompound);
// tagCompound.setInteger("Age", this.age);
// }
//
// public void readEntityFromNBT(NBTTagCompound tagCompund)
// {
// super.readEntityFromNBT(tagCompund);
// this.age = tagCompund.getInteger("Age");
// }
/**
* Returns true if other Entities should be prevented from moving through this Entity.
*/
public boolean canBeCollidedWith()
{
return false;
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource source, int amount)
{
return false;
}
protected void entityInit()
{
this.dataWatcher.addObject(10, Byte.valueOf((byte)0));
}
public boolean isInvulnerable()
{
return this.dataWatcher.getWatchableObjectByte(10) == 1;
}
public void setInvulnerable(boolean invulnerable)
{
this.dataWatcher.updateObject(10, Byte.valueOf((byte)(invulnerable ? 1 : 0)));
}
}

View file

@ -0,0 +1,406 @@
package game.entity.projectile;
import java.util.List;
import game.ExtMath;
import game.enchantment.EnchantmentHelper;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.types.EntityLiving;
import game.entity.types.IObjectData;
import game.entity.types.IProjectile;
import game.init.Config;
import game.init.SoundEvent;
import game.nbt.NBTTagCompound;
import game.world.BoundingBox;
import game.world.HitPosition;
import game.world.Vec3;
import game.world.World;
public class EntityBullet extends Entity implements IProjectile, IObjectData
{
public Entity shootingEntity;
private int ticksInAir;
private int age;
private int damage = 5;
public EntityBullet(World worldIn)
{
super(worldIn);
this.renderDistWeight = 10.0D;
this.setSize(0.5F, 0.5F);
}
public EntityBullet(World worldIn, double x, double y, double z)
{
super(worldIn);
this.renderDistWeight = 10.0D;
this.setSize(0.5F, 0.5F);
this.setPosition(x, y, z);
}
public EntityBullet(World worldIn, double x, double y, double z, int data)
{
this(worldIn, x, y, z);
Entity entity2 = worldIn.getEntityByID(data);
if(entity2 instanceof EntityLiving) {
this.shootingEntity = entity2;
}
}
public EntityBullet(World worldIn, EntityLiving shooter, EntityLiving target, float velocity, float innacuracy)
{
super(worldIn);
this.renderDistWeight = 10.0D;
this.shootingEntity = shooter;
this.posY = shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D;
double d0 = target.posX - shooter.posX;
double d1 = target.getEntityBoundingBox().minY + (double)(target.height * 0.7f) - this.posY;
double d2 = target.posZ - shooter.posZ;
double d3 = (double)ExtMath.sqrtd(d0 * d0 + d2 * d2);
if (d3 >= 1.0E-7D)
{
float f = (float)(ExtMath.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
float f1 = (float)(-(ExtMath.atan2(d1, d3) * 180.0D / Math.PI));
double d4 = d0 / d3;
double d5 = d2 / d3;
this.setLocationAndAngles(shooter.posX + d4, this.posY, shooter.posZ + d5, f, f1);
// float f2 = (float)(d3 * 0.20000000298023224D);
this.setThrowableHeading(d0, d1 /* + (double)f2 */ , d2, velocity, innacuracy);
}
}
public EntityBullet(World worldIn, EntityLiving shooter, float velocity)
{
super(worldIn);
this.renderDistWeight = 10.0D;
this.shootingEntity = shooter;
this.setSize(0.5F, 0.5F);
this.setLocationAndAngles(shooter.posX, shooter.posY + (double)shooter.getEyeHeight(), shooter.posZ, shooter.rotYaw, shooter.rotPitch);
this.posX -= (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * 0.16F);
this.posY -= 0.10000000149011612D;
this.posZ -= (double)(ExtMath.sin(this.rotYaw / 180.0F * (float)Math.PI) * 0.16F);
this.setPosition(this.posX, this.posY, this.posZ);
this.motionX = (double)(-ExtMath.sin(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI));
this.motionZ = (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI));
this.motionY = (double)(-ExtMath.sin(this.rotPitch / 180.0F * (float)Math.PI));
this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, velocity, 0.5F);
}
protected void entityInit()
{
}
/**
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
*/
public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy)
{
float f = ExtMath.sqrtd(x * x + y * y + z * z);
x = x / (double)f;
y = y / (double)f;
z = z / (double)f;
x = x + this.rand.gaussian() * (double)(this.rand.chance() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy;
y = y + this.rand.gaussian() * (double)(this.rand.chance() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy;
z = z + this.rand.gaussian() * (double)(this.rand.chance() ? -1 : 1) * 0.007499999832361937D * (double)inaccuracy;
x = x * (double)velocity;
y = y * (double)velocity;
z = z * (double)velocity;
this.motionX = x;
this.motionY = y;
this.motionZ = z;
float f1 = ExtMath.sqrtd(x * x + z * z);
this.prevYaw = this.rotYaw = (float)(ExtMath.atan2(x, z) * 180.0D / Math.PI);
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(y, (double)f1) * 180.0D / Math.PI);
}
public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean p_180426_10_)
{
this.setPosition(x, y, z);
this.setRotation(yaw, pitch);
}
/**
* Sets the velocity to the args. Args: x, y, z
*/
public void setVelocity(double x, double y, double z)
{
this.motionX = x;
this.motionY = y;
this.motionZ = z;
if (this.prevPitch == 0.0F && this.prevYaw == 0.0F)
{
float f = ExtMath.sqrtd(x * x + z * z);
this.prevYaw = this.rotYaw = (float)(ExtMath.atan2(x, z) * 180.0D / Math.PI);
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(y, (double)f) * 180.0D / Math.PI);
this.prevPitch = this.rotPitch;
this.prevYaw = this.rotYaw;
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotYaw, this.rotPitch);
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.prevPitch == 0.0F && this.prevYaw == 0.0F)
{
float f = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.prevYaw = this.rotYaw = (float)(ExtMath.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(this.motionY, (double)f) * 180.0D / Math.PI);
}
if(!this.worldObj.client && ++this.age >= 200) {
this.setDead();
return;
}
++this.ticksInAir;
Vec3 vec31 = new Vec3(this.posX, this.posY, this.posZ);
Vec3 vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
HitPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec31, vec3, false, true, false);
vec31 = new Vec3(this.posX, this.posY, this.posZ);
vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (movingobjectposition != null)
{
vec3 = new Vec3(movingobjectposition.vec.xCoord, movingobjectposition.vec.yCoord, movingobjectposition.vec.zCoord);
}
Entity entity = null;
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double d0 = 0.0D;
for (int i = 0; i < list.size(); ++i)
{
Entity entity1 = (Entity)list.get(i);
if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5))
{
float f1 = 0.3F;
BoundingBox axisalignedbb1 = entity1.getEntityBoundingBox().expand((double)f1, (double)f1, (double)f1);
HitPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3);
if (movingobjectposition1 != null)
{
double d1 = vec31.squareDistanceTo(movingobjectposition1.vec);
if (d1 < d0 || d0 == 0.0D)
{
entity = entity1;
d0 = d1;
}
}
}
}
if (entity != null)
{
movingobjectposition = new HitPosition(entity);
}
// if (movingobjectposition != null && movingobjectposition.entity != null && movingobjectposition.entity.isPlayer())
// {
// EntityNPC entityplayer = (EntityNPC)movingobjectposition.entity;
//
// if (entityplayer.creative || this.shootingEntity.isPlayer() && !((EntityNPC)this.shootingEntity).canAttackPlayer(entityplayer))
// {
// movingobjectposition = null;
// }
// }
if (movingobjectposition != null)
{
if (movingobjectposition.entity != null)
{
float f2 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
int l = ExtMath.ceild((double)f2 * (double)this.damage);
DamageSource damagesource;
if (this.shootingEntity == null)
{
damagesource = DamageSource.causeShotDamage(this, this);
}
else
{
damagesource = DamageSource.causeShotDamage(this, this.shootingEntity);
}
if ((this.worldObj.client || Config.damageBullet) && movingobjectposition.entity.attackEntityFrom(damagesource, l))
{
if (movingobjectposition.entity instanceof EntityLiving)
{
EntityLiving entitylivingbase = (EntityLiving)movingobjectposition.entity;
// if (!this.worldObj.client)
// {
// entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
// }
// if (this.knockbackStrength > 0)
// {
// float f7 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
//
// if (f7 > 0.0F)
// {
// movingobjectposition.entityHit.addKnockback(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f7, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f7);
// }
// }
if (this.shootingEntity instanceof EntityLiving)
{
EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
EnchantmentHelper.applyArthropodEnchantments((EntityLiving)this.shootingEntity, entitylivingbase);
}
// if (this.shootingEntity != null && movingobjectposition.entityHit != this.shootingEntity && movingobjectposition.entityHit.isPlayer() && this.shootingEntity.isPlayer())
// {
// ((EntityNPCMP)this.shootingEntity).netHandler.sendPacket(new S29PacketSoundEffect(
// "random.successful_hit", shootingEntity.posX,
// shootingEntity.posY + (double)shootingEntity.getEyeHeight(), shootingEntity.posZ, 0.18F, 0.45F));
// }
}
this.playSound(SoundEvent.METALHIT, 0.2F, this.rand.floatv() * 0.2F + 1.5F);
// this.setDead();
}
// else
// {
this.setDead();
// this.motionX *= -0.10000000149011612D;
// this.motionY *= -0.10000000149011612D;
// this.motionZ *= -0.10000000149011612D;
// this.rotYaw += 180.0F;
// this.prevYaw += 180.0F;
// this.ticksInAir = 0;
// }
}
else
{
this.playSound(SoundEvent.METALHIT, 0.5F, this.rand.floatv() * 0.2F + 1.5F);
this.setDead();
}
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
float f3 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotYaw = (float)(ExtMath.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
for (this.rotPitch = (float)(ExtMath.atan2(this.motionY, (double)f3) * 180.0D / Math.PI); this.rotPitch - this.prevPitch < -180.0F; this.prevPitch -= 360.0F)
{
;
}
while (this.rotPitch - this.prevPitch >= 180.0F)
{
this.prevPitch += 360.0F;
}
while (this.rotYaw - this.prevYaw < -180.0F)
{
this.prevYaw -= 360.0F;
}
while (this.rotYaw - this.prevYaw >= 180.0F)
{
this.prevYaw += 360.0F;
}
this.rotPitch = this.prevPitch + (this.rotPitch - this.prevPitch) * 0.2F;
this.rotYaw = this.prevYaw + (this.rotYaw - this.prevYaw) * 0.2F;
// float f4 = 0.99F;
// float f6 = 0.001F;
// if (this.isInLiquid())
// {
// for (int i1 = 0; i1 < 4; ++i1)
// {
// float f8 = 0.25F;
// this.worldObj.spawnParticle(ParticleType.WATER_BUBBLE, this.posX - this.motionX * (double)f8, this.posY - this.motionY * (double)f8, this.posZ - this.motionZ * (double)f8, this.motionX, this.motionY, this.motionZ);
// }
//
// f4 = 0.85F;
// }
// if (this.isWet())
// {
// this.extinguish();
// }
// this.motionX *= (double)f4;
// this.motionY *= (double)f4;
// this.motionZ *= (double)f4;
// this.motionY -= (double)f6;
this.setPosition(this.posX, this.posY, this.posZ);
// this.doBlockCollisions();
}
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
tagCompound.setInteger("damage", this.damage);
tagCompound.setInteger("age", this.age);
}
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
if(tagCompund.hasKey("damage", 99))
this.damage = tagCompund.getInteger("damage");
this.age = tagCompund.getInteger("age");
}
protected boolean canTriggerWalking()
{
return false;
}
public void setDamage(int damageIn)
{
this.damage = damageIn;
}
public int getDamage()
{
return this.damage;
}
public boolean canAttackWithItem()
{
return false;
}
public float getEyeHeight()
{
return 0.0F;
}
public int getTrackingRange() {
return 96;
}
public int getUpdateFrequency() {
return 1;
}
public boolean isSendingVeloUpdates() {
return false;
}
public int getPacketData() {
return this.shootingEntity != null ? this.shootingEntity.getId() : this.getId();
}
public boolean hasSpawnVelocity() {
return true;
}
}

View file

@ -0,0 +1,165 @@
package game.entity.projectile;
import game.entity.DamageSource;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
import game.entity.types.EntityThrowable;
import game.entity.types.IObjectData;
import game.init.Items;
import game.init.SoundEvent;
import game.item.ItemDie;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.world.HitPosition;
import game.world.World;
public class EntityDie extends EntityThrowable implements IObjectData
{
public int sides;
private boolean noPickup;
public EntityDie(World worldIn)
{
super(worldIn);
this.setSize(0.1f, 0.1f);
}
public EntityDie(World worldIn, EntityLiving throwerIn, int sides, boolean noPickup)
{
super(worldIn, throwerIn);
this.setSize(0.1f, 0.1f);
this.sides = sides;
this.noPickup = noPickup;
}
public EntityDie(World worldIn, double x, double y, double z, int sides)
{
super(worldIn, x, y, z);
this.setSize(0.1f, 0.1f);
this.sides = sides;
}
protected void onImpact(HitPosition pos)
{
if (!this.worldObj.client)
{
this.setValue(this.rand.roll(this.sides <= 0 ? 6 : this.sides));
this.motionX = this.motionY = this.motionZ = 0.0;
}
}
protected void entityInit()
{
super.entityInit();
this.dataWatcher.addObject(16, 0);
}
public void setValue(int value)
{
this.dataWatcher.updateObject(16, value);
}
public int getValue()
{
return this.dataWatcher.getWatchableObjectInt(16);
}
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
super.writeEntityToNBT(tagCompound);
tagCompound.setInteger("Sides", this.sides);
tagCompound.setInteger("Value", this.getValue());
tagCompound.setBoolean("NoPickup", this.noPickup);
}
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
super.readEntityFromNBT(tagCompund);
this.sides = tagCompund.getInteger("Sides");
this.setValue(tagCompund.getInteger("Value"));
this.noPickup = tagCompund.getBoolean("NoPickup");
}
public int getPacketData() {
return this.sides;
}
// public boolean hasSpawnVelocity() {
// return false;
// }
public void onUpdate()
{
if (this.getValue() != 0)
{
this.prevX = this.posX;
this.prevY = this.posY;
this.prevZ = this.posZ;
this.motionY -= 0.03999999910593033D;
this.moveEntity(this.motionX, this.motionY, this.motionZ);
this.motionX *= 0.9800000190734863D;
this.motionY *= 0.9800000190734863D;
this.motionZ *= 0.9800000190734863D;
}
else {
super.onUpdate();
}
}
protected float getVelocity()
{
return 0.3F;
}
public boolean canBeCollidedWith()
{
return this.getValue() != 0;
}
public int getStackMeta() {
int meta = 1;
for(int z = 0; z < ItemDie.DIE_SIDES.length; z++) {
if(this.sides == ItemDie.DIE_SIDES[z])
meta = z;
}
return meta;
}
public ItemStack getStack() {
return new ItemStack(Items.die, 1, this.getStackMeta());
}
public boolean interactFirst(EntityNPC player)
{
if(!this.worldObj.client)
{
if(this.noPickup)
this.setDead();
else if(player.inventory.addItemStackToInventory(this.getStack())) {
this.setDead();
player.worldObj.playSoundAtEntity(player, SoundEvent.POP, 0.2F, ((player.getRNG().floatv() - player.getRNG().floatv()) * 0.7F + 1.0F) * 2.0F);
player.inventoryContainer.detectAndSendChanges();
}
}
return true;
}
public boolean attackEntityFrom(DamageSource source, int amount)
{
if(this.isEntityInvulnerable(source))
return false;
if(!this.worldObj.client && !this.dead) {
if(!this.noPickup)
this.entityDropItem(this.getStack(), 0.0f);
this.setDead();
}
return true;
}
public String getDisplayName()
{
if(this.getValue() == 0)
return null;
return ItemDie.DIE_COLORS[this.getStackMeta()] + "" + this.getValue();
}
}

View file

@ -0,0 +1,80 @@
package game.entity.projectile;
import game.entity.DamageSource;
import game.entity.types.EntityLiving;
import game.entity.types.EntityThrowable;
import game.entity.types.IObjectData;
import game.init.Config;
import game.init.ItemRegistry;
import game.init.Items;
import game.nbt.NBTTagCompound;
import game.renderer.particle.ParticleType;
import game.world.HitPosition;
import game.world.World;
public class EntityDynamite extends EntityThrowable implements IObjectData
{
public int explosionSize;
public EntityDynamite(World worldIn)
{
super(worldIn);
}
public EntityDynamite(World worldIn, EntityLiving throwerIn, int power)
{
super(worldIn, throwerIn);
this.explosionSize = power & 7;
}
public EntityDynamite(World worldIn, double x, double y, double z, int power)
{
super(worldIn, x, y, z);
this.explosionSize = power & 7;
}
protected void onImpact(HitPosition pos)
{
if (pos.entity != null && Config.knockDynamite)
{
pos.entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
}
if (!this.worldObj.client)
{
float f = 4.0F * (((float)this.explosionSize)+1.0f);
EntityLiving thrower = this.getThrower();
this.worldObj.createAltExplosion(thrower == null ? this : thrower, this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, f, true);
}
for (int k = 0; k < 8; ++k)
{
this.worldObj.spawnParticle(ParticleType.ITEM_CRACK, this.posX, this.posY, this.posZ, ((double)this.rand.floatv() - 0.5D) * 0.08D, ((double)this.rand.floatv() - 0.5D) * 0.08D, ((double)this.rand.floatv() - 0.5D) * 0.08D, ItemRegistry.getIdFromItem(Items.dynamite), this.explosionSize);
}
if (!this.worldObj.client)
{
this.setDead();
}
}
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
super.writeEntityToNBT(tagCompound);
tagCompound.setByte("Power", (byte)this.explosionSize);
}
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
super.readEntityFromNBT(tagCompund);
this.explosionSize = ((int)tagCompund.getByte("Power")) & 7;
}
public int getPacketData() {
return this.explosionSize;
}
// public boolean hasSpawnVelocity() {
// return false;
// }
}

View file

@ -0,0 +1,71 @@
package game.entity.projectile;
import game.entity.DamageSource;
import game.entity.animal.EntityChicken;
import game.entity.types.EntityLiving;
import game.entity.types.EntityThrowable;
import game.init.Config;
import game.init.ItemRegistry;
import game.init.Items;
import game.renderer.particle.ParticleType;
import game.world.HitPosition;
import game.world.World;
public class EntityEgg extends EntityThrowable
{
public EntityEgg(World worldIn)
{
super(worldIn);
}
public EntityEgg(World worldIn, EntityLiving throwerIn)
{
super(worldIn, throwerIn);
}
public EntityEgg(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(HitPosition p_70184_1_)
{
if (p_70184_1_.entity != null && Config.knockEgg)
{
p_70184_1_.entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
}
if (!this.worldObj.client && this.rand.chance(8) && Config.mobs && Config.spawnEggChicken)
{
int i = this.rand.chance(1, 4, 32);
// if (this.rand.chance(32))
// {
// i = 4;
// }
for (int j = 0; j < i; ++j)
{
EntityChicken entitychicken = new EntityChicken(this.worldObj);
entitychicken.setGrowingAge(-24000);
entitychicken.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotYaw, 0.0F);
this.worldObj.spawnEntityInWorld(entitychicken);
}
}
double d0 = 0.08D;
for (int k = 0; k < 8; ++k)
{
this.worldObj.spawnParticle(ParticleType.ITEM_CRACK, this.posX, this.posY, this.posZ, ((double)this.rand.floatv() - 0.5D) * 0.08D, ((double)this.rand.floatv() - 0.5D) * 0.08D, ((double)this.rand.floatv() - 0.5D) * 0.08D, ItemRegistry.getIdFromItem(Items.egg));
}
if (!this.worldObj.client)
{
this.setDead();
}
}
}

View file

@ -0,0 +1,98 @@
package game.entity.projectile;
import game.entity.DamageSource;
import game.entity.types.EntityLiving;
import game.init.Blocks;
import game.init.Config;
import game.world.BlockPos;
import game.world.HitPosition;
import game.world.World;
public class EntityFireCharge extends EntityProjectile
{
public EntityFireCharge(World worldIn)
{
super(worldIn);
this.setSize(0.3125F, 0.3125F);
}
public EntityFireCharge(World worldIn, EntityLiving shooter, double accelX, double accelY, double accelZ)
{
super(worldIn, shooter, accelX, accelY, accelZ, 0.35f, 1.0f);
this.setSize(0.3125F, 0.3125F);
}
public EntityFireCharge(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
this.setSize(0.3125F, 0.3125F);
}
public EntityFireCharge(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
{
this(worldIn, x, y, z);
this.setAcceleration(accelX, accelY, accelZ);
}
/**
* Called when this EntityFireball hits a block or entity.
*/
protected void onImpact(HitPosition movingObject)
{
if (!this.worldObj.client)
{
if (movingObject.entity != null)
{
boolean flag = Config.damageFireball &&
movingObject.entity.attackEntityFrom(DamageSource.causeFireballDamage(this, this.shootingEntity), 6);
if (flag)
{
this.applyEnchantments(this.shootingEntity, movingObject.entity);
// if (!movingObject.entityHit.isImmuneToFire())
// {
movingObject.entity.setOnFireFromObject(5);
// }
}
}
else
{
boolean flag1 = true;
if (this.shootingEntity != null && this.shootingEntity instanceof EntityLiving) // && !(this.shootingEntity.isPlayer()))
{
flag1 = Config.mobGrief;
}
if (flag1)
{
BlockPos blockpos = movingObject.block.offset(movingObject.side);
if (this.worldObj.isAirBlock(blockpos))
{
this.worldObj.setState(blockpos, Blocks.fire.getState());
}
}
}
this.setDead();
}
}
/**
* Returns true if other Entities should be prevented from moving through this Entity.
*/
public boolean canBeCollidedWith()
{
return false;
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource source, int amount)
{
return false;
}
}

View file

@ -0,0 +1,77 @@
package game.entity.projectile;
import game.entity.DamageSource;
import game.entity.types.EntityLiving;
import game.init.Config;
import game.nbt.NBTTagCompound;
import game.world.HitPosition;
import game.world.World;
public class EntityFireball extends EntityProjectile
{
public int explosionPower = 1;
public EntityFireball(World worldIn)
{
super(worldIn);
this.setSize(0.45F, 0.45F);
}
public EntityFireball(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
this.setSize(0.45F, 0.45F);
}
public EntityFireball(World worldIn, EntityLiving shooter, double accelX, double accelY, double accelZ, double velocity)
{
super(worldIn, shooter, accelX, accelY, accelZ, 0.1, velocity);
this.setSize(0.45F, 0.45F);
}
/**
* Called when this EntityFireball hits a block or entity.
*/
protected void onImpact(HitPosition movingObject)
{
if (!this.worldObj.client)
{
if (Config.damageFireball && movingObject.entity != null)
{
movingObject.entity.attackEntityFrom(DamageSource.causeFireballDamage(this, this.shootingEntity), 8);
this.applyEnchantments(this.shootingEntity, movingObject.entity);
}
boolean flag = Config.mobGrief;
this.worldObj.newExplosion(this.shootingEntity, this.posX, this.posY, this.posZ, (float)this.explosionPower, flag, false, true);
this.setDead();
}
}
public boolean attackEntityFrom(DamageSource source, int amount)
{
return false;
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
super.writeEntityToNBT(tagCompound);
tagCompound.setInteger("ExplosionPower", this.explosionPower);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
super.readEntityFromNBT(tagCompund);
if (tagCompund.hasKey("ExplosionPower", 99))
{
this.explosionPower = tagCompund.getInteger("ExplosionPower");
}
}
}

View file

@ -0,0 +1,668 @@
package game.entity.projectile;
import java.util.List;
import game.ExtMath;
import game.block.Block;
import game.enchantment.EnchantmentHelper;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.item.EntityItem;
import game.entity.item.EntityXp;
import game.entity.npc.EntityNPC;
import game.entity.types.IObjectData;
import game.init.BlockRegistry;
import game.init.Blocks;
import game.init.Config;
import game.init.Items;
import game.init.SoundEvent;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.renderer.particle.ParticleType;
import game.world.BlockPos;
import game.world.BoundingBox;
import game.world.HitPosition;
import game.world.Vec3;
import game.world.World;
import game.world.WorldServer;
import game.worldgen.LootConstants;
public class EntityHook extends Entity implements IObjectData
{
private int xTile;
private int yTile;
private int zTile;
private Block inTile;
private boolean inGround;
public int shake;
public EntityNPC angler;
private int ticksInGround;
private int ticksInAir;
private int ticksCatchable;
private int ticksCaughtDelay;
private int ticksCatchableDelay;
private float fishApproachAngle;
public Entity caughtEntity;
private int fishPosRotationIncrements;
private double fishX;
private double fishY;
private double fishZ;
private double fishYaw;
private double fishPitch;
private double clientMotionX;
private double clientMotionY;
private double clientMotionZ;
public EntityHook(World worldIn)
{
super(worldIn);
this.xTile = -1;
this.yTile = -1;
this.zTile = -1;
this.setSize(0.25F, 0.25F);
this.noFrustumCheck = true;
}
public EntityHook(World worldIn, double x, double y, double z, int data) //, EntityNPC anglerIn)
{
super(worldIn);
this.xTile = -1;
this.yTile = -1;
this.zTile = -1;
this.setSize(0.25F, 0.25F);
this.noFrustumCheck = true;
// this(worldIn);
this.setPosition(x, y, z);
// this.noFrustumCheck = true;
// this.angler = anglerIn;
// if(anglerIn != null) {
// anglerIn.fishEntity = this;
// }
// }
//
// public EntityFishHook(World worldIn, double x, double y, double z, int data)
// {
// this(worldIn, x, y, z, null);
Entity entity1 = worldIn.getEntityByID(data);
if (entity1 != null && entity1.isPlayer())
{
this.angler = (EntityNPC)entity1;
this.angler.fishEntity = this;
}
else {
this.setDead();
}
}
public EntityHook(World worldIn, EntityNPC fishingPlayer)
{
super(worldIn);
this.xTile = -1;
this.yTile = -1;
this.zTile = -1;
this.noFrustumCheck = true;
this.angler = fishingPlayer;
this.angler.fishEntity = this;
this.setSize(0.25F, 0.25F);
this.setLocationAndAngles(fishingPlayer.posX, fishingPlayer.posY + (double)fishingPlayer.getEyeHeight(), fishingPlayer.posZ, fishingPlayer.rotYaw, fishingPlayer.rotPitch);
this.posX -= (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * 0.16F);
this.posY -= 0.10000000149011612D;
this.posZ -= (double)(ExtMath.sin(this.rotYaw / 180.0F * (float)Math.PI) * 0.16F);
this.setPosition(this.posX, this.posY, this.posZ);
float f = 0.4F;
this.motionX = (double)(-ExtMath.sin(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI) * f);
this.motionZ = (double)(ExtMath.cos(this.rotYaw / 180.0F * (float)Math.PI) * ExtMath.cos(this.rotPitch / 180.0F * (float)Math.PI) * f);
this.motionY = (double)(-ExtMath.sin(this.rotPitch / 180.0F * (float)Math.PI) * f);
this.handleHookCasting(this.motionX, this.motionY, this.motionZ, 1.5F, 1.0F);
}
protected void entityInit()
{
}
public boolean writeToNBTOptional(NBTTagCompound tagCompund)
{
return false;
}
/**
* Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
* length * 64 * renderDistanceWeight Args: distance
*/
public boolean isInRangeToRenderDist(double distance)
{
double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D;
if (Double.isNaN(d0))
{
d0 = 4.0D;
}
d0 = d0 * 64.0D;
return distance < d0 * d0;
}
public void handleHookCasting(double p_146035_1_, double p_146035_3_, double p_146035_5_, float p_146035_7_, float p_146035_8_)
{
float f = ExtMath.sqrtd(p_146035_1_ * p_146035_1_ + p_146035_3_ * p_146035_3_ + p_146035_5_ * p_146035_5_);
p_146035_1_ = p_146035_1_ / (double)f;
p_146035_3_ = p_146035_3_ / (double)f;
p_146035_5_ = p_146035_5_ / (double)f;
p_146035_1_ = p_146035_1_ + this.rand.gaussian() * 0.007499999832361937D * (double)p_146035_8_;
p_146035_3_ = p_146035_3_ + this.rand.gaussian() * 0.007499999832361937D * (double)p_146035_8_;
p_146035_5_ = p_146035_5_ + this.rand.gaussian() * 0.007499999832361937D * (double)p_146035_8_;
p_146035_1_ = p_146035_1_ * (double)p_146035_7_;
p_146035_3_ = p_146035_3_ * (double)p_146035_7_;
p_146035_5_ = p_146035_5_ * (double)p_146035_7_;
this.motionX = p_146035_1_;
this.motionY = p_146035_3_;
this.motionZ = p_146035_5_;
float f1 = ExtMath.sqrtd(p_146035_1_ * p_146035_1_ + p_146035_5_ * p_146035_5_);
this.prevYaw = this.rotYaw = (float)(ExtMath.atan2(p_146035_1_, p_146035_5_) * 180.0D / Math.PI);
this.prevPitch = this.rotPitch = (float)(ExtMath.atan2(p_146035_3_, (double)f1) * 180.0D / Math.PI);
this.ticksInGround = 0;
}
public void setPositionAndRotation2(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean p_180426_10_)
{
this.fishX = x;
this.fishY = y;
this.fishZ = z;
this.fishYaw = (double)yaw;
this.fishPitch = (double)pitch;
this.fishPosRotationIncrements = posRotationIncrements;
this.motionX = this.clientMotionX;
this.motionY = this.clientMotionY;
this.motionZ = this.clientMotionZ;
}
/**
* Sets the velocity to the args. Args: x, y, z
*/
public void setVelocity(double x, double y, double z)
{
this.clientMotionX = this.motionX = x;
this.clientMotionY = this.motionY = y;
this.clientMotionZ = this.motionZ = z;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if(this.angler == null) {
this.setDead();
return;
}
if (this.fishPosRotationIncrements > 0)
{
double d7 = this.posX + (this.fishX - this.posX) / (double)this.fishPosRotationIncrements;
double d8 = this.posY + (this.fishY - this.posY) / (double)this.fishPosRotationIncrements;
double d9 = this.posZ + (this.fishZ - this.posZ) / (double)this.fishPosRotationIncrements;
double d1 = ExtMath.wrapd(this.fishYaw - (double)this.rotYaw);
this.rotYaw = (float)((double)this.rotYaw + d1 / (double)this.fishPosRotationIncrements);
this.rotPitch = (float)((double)this.rotPitch + (this.fishPitch - (double)this.rotPitch) / (double)this.fishPosRotationIncrements);
--this.fishPosRotationIncrements;
this.setPosition(d7, d8, d9);
this.setRotation(this.rotYaw, this.rotPitch);
}
else
{
if (!this.worldObj.client)
{
ItemStack itemstack = this.angler.getCurrentEquippedItem();
if (this.angler.dead || !this.angler.isEntityAlive() || itemstack == null || itemstack.getItem() != Items.fishing_rod || this.getDistanceSqToEntity(this.angler) > 1024.0D)
{
this.setDead();
this.angler.fishEntity = null;
return;
}
if (this.caughtEntity != null)
{
if (!this.caughtEntity.dead)
{
this.posX = this.caughtEntity.posX;
double d17 = (double)this.caughtEntity.height;
this.posY = this.caughtEntity.getEntityBoundingBox().minY + d17 * 0.8D;
this.posZ = this.caughtEntity.posZ;
return;
}
this.caughtEntity = null;
}
}
if (this.shake > 0)
{
--this.shake;
}
if (this.inGround)
{
if (this.worldObj.getState(new BlockPos(this.xTile, this.yTile, this.zTile)).getBlock() == this.inTile)
{
++this.ticksInGround;
if (this.ticksInGround == 1200)
{
this.setDead();
}
return;
}
this.inGround = false;
this.motionX *= (double)(this.rand.floatv() * 0.2F);
this.motionY *= (double)(this.rand.floatv() * 0.2F);
this.motionZ *= (double)(this.rand.floatv() * 0.2F);
this.ticksInGround = 0;
this.ticksInAir = 0;
}
else
{
++this.ticksInAir;
}
Vec3 vec31 = new Vec3(this.posX, this.posY, this.posZ);
Vec3 vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
HitPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec31, vec3);
vec31 = new Vec3(this.posX, this.posY, this.posZ);
vec3 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (movingobjectposition != null)
{
vec3 = new Vec3(movingobjectposition.vec.xCoord, movingobjectposition.vec.yCoord, movingobjectposition.vec.zCoord);
}
Entity entity = null;
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double d0 = 0.0D;
for (int i = 0; i < list.size(); ++i)
{
Entity entity1 = (Entity)list.get(i);
if (entity1.canBeCollidedWith() && (entity1 != this.angler || this.ticksInAir >= 5))
{
float f = 0.3F;
BoundingBox axisalignedbb = entity1.getEntityBoundingBox().expand((double)f, (double)f, (double)f);
HitPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec31, vec3);
if (movingobjectposition1 != null)
{
double d2 = vec31.squareDistanceTo(movingobjectposition1.vec);
if (d2 < d0 || d0 == 0.0D)
{
entity = entity1;
d0 = d2;
}
}
}
}
if (entity != null)
{
movingobjectposition = new HitPosition(entity);
}
if (movingobjectposition != null)
{
if (movingobjectposition.entity != null)
{
if (this.worldObj.client || !Config.knockHook || movingobjectposition.entity.attackEntityFrom(
DamageSource.causeThrownDamage(this, this.angler), 0) || !Config.hookCheckDamage)
{
if(this.worldObj.client || Config.hookEntity) // && (!(movingobjectposition.entity.isPlayer())
// || !((EntityNPC)movingobjectposition.entity).creative)))
this.caughtEntity = movingobjectposition.entity;
}
}
else
{
this.inGround = true;
}
}
if (!this.inGround)
{
this.moveEntity(this.motionX, this.motionY, this.motionZ);
float f5 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotYaw = (float)(ExtMath.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
for (this.rotPitch = (float)(ExtMath.atan2(this.motionY, (double)f5) * 180.0D / Math.PI); this.rotPitch - this.prevPitch < -180.0F; this.prevPitch -= 360.0F)
{
;
}
while (this.rotPitch - this.prevPitch >= 180.0F)
{
this.prevPitch += 360.0F;
}
while (this.rotYaw - this.prevYaw < -180.0F)
{
this.prevYaw -= 360.0F;
}
while (this.rotYaw - this.prevYaw >= 180.0F)
{
this.prevYaw += 360.0F;
}
this.rotPitch = this.prevPitch + (this.rotPitch - this.prevPitch) * 0.2F;
this.rotYaw = this.prevYaw + (this.rotYaw - this.prevYaw) * 0.2F;
float f6 = 0.92F;
if (this.onGround || this.collidedHorizontally)
{
f6 = 0.5F;
}
int j = 5;
double d10 = 0.0D;
for (int k = 0; k < j; ++k)
{
BoundingBox axisalignedbb1 = this.getEntityBoundingBox();
double d3 = axisalignedbb1.maxY - axisalignedbb1.minY;
double d4 = axisalignedbb1.minY + d3 * (double)k / (double)j;
double d5 = axisalignedbb1.minY + d3 * (double)(k + 1) / (double)j;
BoundingBox axisalignedbb2 = new BoundingBox(axisalignedbb1.minX, d4, axisalignedbb1.minZ, axisalignedbb1.maxX, d5, axisalignedbb1.maxZ);
if (this.worldObj.isAABBInLiquid(axisalignedbb2))
{
d10 += 1.0D / (double)j;
}
}
if (!this.worldObj.client && d10 > 0.0D)
{
WorldServer worldserver = (WorldServer)this.worldObj;
int l = 1;
BlockPos blockpos = (new BlockPos(this)).up();
if (this.rand.floatv() < 0.25F && this.worldObj.isRainingAt(blockpos, true))
{
l = 2;
}
if (this.rand.floatv() < 0.5F && !this.worldObj.canSeeSky(blockpos))
{
--l;
}
if (this.ticksCatchable > 0)
{
--this.ticksCatchable;
if (this.ticksCatchable <= 0)
{
this.ticksCaughtDelay = 0;
this.ticksCatchableDelay = 0;
}
}
else if (this.ticksCatchableDelay > 0)
{
this.ticksCatchableDelay -= l;
if (this.ticksCatchableDelay <= 0)
{
this.motionY -= 0.20000000298023224D;
this.playSound(SoundEvent.SPLASH, 0.25F, 1.0F + (this.rand.floatv() - this.rand.floatv()) * 0.4F);
float f8 = (float)ExtMath.floord(this.getEntityBoundingBox().minY);
worldserver.spawnParticle(ParticleType.WATER_BUBBLE, this.posX, (double)(f8 + 1.0F), this.posZ, (int)(1.0F + this.width * 20.0F), (double)this.width, 0.0D, (double)this.width, 0.20000000298023224D);
worldserver.spawnParticle(ParticleType.WATER_WAKE, this.posX, (double)(f8 + 1.0F), this.posZ, (int)(1.0F + this.width * 20.0F), (double)this.width, 0.0D, (double)this.width, 0.20000000298023224D);
this.ticksCatchable = this.rand.range(10, 30);
}
else
{
this.fishApproachAngle = (float)((double)this.fishApproachAngle + this.rand.gaussian() * 4.0D);
float f7 = this.fishApproachAngle * 0.017453292F;
float f10 = ExtMath.sin(f7);
float f11 = ExtMath.cos(f7);
double d13 = this.posX + (double)(f10 * (float)this.ticksCatchableDelay * 0.1F);
double d15 = (double)((float)ExtMath.floord(this.getEntityBoundingBox().minY) + 1.0F);
double d16 = this.posZ + (double)(f11 * (float)this.ticksCatchableDelay * 0.1F);
Block block1 = worldserver.getState(new BlockPos((int)d13, (int)d15 - 1, (int)d16)).getBlock();
if (block1 == Blocks.water || block1 == Blocks.flowing_water)
{
if (this.rand.floatv() < 0.15F)
{
worldserver.spawnParticle(ParticleType.WATER_BUBBLE, d13, d15 - 0.10000000149011612D, d16, 1, (double)f10, 0.1D, (double)f11, 0.0D);
}
float f3 = f10 * 0.04F;
float f4 = f11 * 0.04F;
worldserver.spawnParticle(ParticleType.WATER_WAKE, d13, d15, d16, 0, (double)f4, 0.01D, (double)(-f3), 1.0D);
worldserver.spawnParticle(ParticleType.WATER_WAKE, d13, d15, d16, 0, (double)(-f4), 0.01D, (double)f3, 1.0D);
}
}
}
else if (this.ticksCaughtDelay > 0)
{
this.ticksCaughtDelay -= l;
float f1 = 0.15F;
if (this.ticksCaughtDelay < 20)
{
f1 = (float)((double)f1 + (double)(20 - this.ticksCaughtDelay) * 0.05D);
}
else if (this.ticksCaughtDelay < 40)
{
f1 = (float)((double)f1 + (double)(40 - this.ticksCaughtDelay) * 0.02D);
}
else if (this.ticksCaughtDelay < 60)
{
f1 = (float)((double)f1 + (double)(60 - this.ticksCaughtDelay) * 0.01D);
}
if (this.rand.floatv() < f1)
{
float f9 = this.rand.frange(0.0F, 360.0F) * 0.017453292F;
float f2 = this.rand.frange(25.0F, 60.0F);
double d12 = this.posX + (double)(ExtMath.sin(f9) * f2 * 0.1F);
double d14 = (double)((float)ExtMath.floord(this.getEntityBoundingBox().minY) + 1.0F);
double d6 = this.posZ + (double)(ExtMath.cos(f9) * f2 * 0.1F);
Block block = worldserver.getState(new BlockPos((int)d12, (int)d14 - 1, (int)d6)).getBlock();
if (block == Blocks.water || block == Blocks.flowing_water)
{
worldserver.spawnParticle(ParticleType.WATER_SPLASH, d12, d14, d6, this.rand.range(2, 3), 0.10000000149011612D, 0.0D, 0.10000000149011612D, 0.0D);
}
}
if (this.ticksCaughtDelay <= 0)
{
this.fishApproachAngle = this.rand.frange(0.0F, 360.0F);
this.ticksCatchableDelay = this.rand.range(20, 80);
}
}
else
{
this.ticksCaughtDelay = this.rand.range(100, 900);
this.ticksCaughtDelay -= EnchantmentHelper.getLureModifier(this.angler) * 20 * 5;
}
if (this.ticksCatchable > 0)
{
this.motionY -= (double)(this.rand.floatv() * this.rand.floatv() * this.rand.floatv()) * 0.2D;
}
}
double d11 = d10 * 2.0D - 1.0D;
this.motionY += 0.03999999910593033D * d11;
if (d10 > 0.0D)
{
f6 = (float)((double)f6 * 0.9D);
this.motionY *= 0.8D;
}
this.motionX *= (double)f6;
this.motionY *= (double)f6;
this.motionZ *= (double)f6;
this.setPosition(this.posX, this.posY, this.posZ);
}
}
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
tagCompound.setShort("xTile", (short)this.xTile);
tagCompound.setShort("yTile", (short)this.yTile);
tagCompound.setShort("zTile", (short)this.zTile);
String resourcelocation = BlockRegistry.REGISTRY.getNameForObject(this.inTile);
tagCompound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
tagCompound.setByte("shake", (byte)this.shake);
tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
this.xTile = tagCompund.getShort("xTile");
this.yTile = tagCompund.getShort("yTile");
this.zTile = tagCompund.getShort("zTile");
if (tagCompund.hasKey("inTile", 8))
{
this.inTile = BlockRegistry.getByIdFallback(tagCompund.getString("inTile"));
}
else
{
this.inTile = BlockRegistry.getBlockById(tagCompund.getByte("inTile") & 255);
}
this.shake = tagCompund.getByte("shake") & 255;
this.inGround = tagCompund.getByte("inGround") == 1;
}
public int handleHookRetraction()
{
if (this.worldObj.client)
{
return 0;
}
else
{
int i = 0;
if (this.caughtEntity != null)
{
double d0 = this.angler.posX - this.posX;
double d2 = this.angler.posY - this.posY;
double d4 = this.angler.posZ - this.posZ;
double d6 = (double)ExtMath.sqrtd(d0 * d0 + d2 * d2 + d4 * d4);
double d8 = 0.1D;
this.caughtEntity.motionX += d0 * d8;
this.caughtEntity.motionY += d2 * d8 + (double)ExtMath.sqrtd(d6) * 0.08D;
this.caughtEntity.motionZ += d4 * d8;
i = 3;
}
else if (this.ticksCatchable > 0)
{
EntityItem entityitem = new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, this.getFishingResult());
double d1 = this.angler.posX - this.posX;
double d3 = this.angler.posY - this.posY;
double d5 = this.angler.posZ - this.posZ;
double d7 = (double)ExtMath.sqrtd(d1 * d1 + d3 * d3 + d5 * d5);
double d9 = 0.1D;
entityitem.motionX = d1 * d9;
entityitem.motionY = d3 * d9 + (double)ExtMath.sqrtd(d7) * 0.08D;
entityitem.motionZ = d5 * d9;
this.worldObj.spawnEntityInWorld(entityitem);
if(Config.fishingXP)
this.angler.worldObj.spawnEntityInWorld(new EntityXp(this.angler.worldObj, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, this.rand.roll(6)));
i = 1;
}
if (this.inGround)
{
i = 2;
}
this.setDead();
this.angler.fishEntity = null;
return i;
}
}
private ItemStack getFishingResult()
{
float f = this.worldObj.rand.floatv();
int i = EnchantmentHelper.getLuckOfSeaModifier(this.angler);
int j = EnchantmentHelper.getLureModifier(this.angler);
float f1 = 0.1F - (float)i * 0.025F - (float)j * 0.01F;
float f2 = 0.05F + (float)i * 0.01F - (float)j * 0.01F;
f1 = ExtMath.clampf(f1, 0.0F, 1.0F);
f2 = ExtMath.clampf(f2, 0.0F, 1.0F);
if (f < f1)
{
// this.angler.triggerAchievement(StatRegistry.junkFishedStat);
return ((RngFishable)LootConstants.FISHING_JUNK.pick(this.rand)).getItemStack(this.rand);
}
else
{
f = f - f1;
if (f < f2)
{
// this.angler.triggerAchievement(StatRegistry.treasureFishedStat);
return ((RngFishable)LootConstants.FISHING_TREASURE.pick(this.rand)).getItemStack(this.rand);
}
else
{
float f3 = f - f2;
// this.angler.triggerAchievement(StatRegistry.fishCaughtStat);
return ((RngFishable)LootConstants.FISH_TYPES.pick(this.rand)).getItemStack(this.rand);
}
}
}
/**
* Will get destroyed next tick.
*/
public void setDead()
{
super.setDead();
if (this.angler != null)
{
this.angler.fishEntity = null;
}
}
public int getTrackingRange() {
return 64;
}
public int getUpdateFrequency() {
return 5;
}
public boolean isSendingVeloUpdates() {
return true;
}
public int getPacketData() {
return this.angler != null ? this.angler.getId() : this.getId();
}
// public boolean hasSpawnVelocity() {
// return false;
// }
}

View file

@ -0,0 +1,198 @@
package game.entity.projectile;
import java.util.List;
import game.entity.types.EntityLiving;
import game.entity.types.EntityThrowable;
import game.entity.types.IObjectData;
import game.init.Items;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.potion.Potion;
import game.potion.PotionEffect;
import game.world.BlockPos;
import game.world.BoundingBox;
import game.world.HitPosition;
import game.world.World;
public class EntityPotion extends EntityThrowable implements IObjectData
{
/**
* The damage value of the thrown potion that this EntityPotion represents.
*/
private ItemStack potionDamage;
public EntityPotion(World worldIn)
{
super(worldIn);
}
public EntityPotion(World worldIn, EntityLiving throwerIn, int meta)
{
this(worldIn, throwerIn, new ItemStack(Items.potion, 1, meta));
}
public EntityPotion(World worldIn, EntityLiving throwerIn, ItemStack potionDamageIn)
{
super(worldIn, throwerIn);
this.potionDamage = potionDamageIn;
}
public EntityPotion(World worldIn, double x, double y, double z, int data)
{
this(worldIn, x, y, z, new ItemStack(Items.potion, 1, data));
}
public EntityPotion(World worldIn, double x, double y, double z, ItemStack potionDamageIn)
{
super(worldIn, x, y, z);
this.potionDamage = potionDamageIn;
}
/**
* Gets the amount of gravity to apply to the thrown entity with each tick.
*/
protected float getGravityVelocity()
{
return 0.05F;
}
protected float getVelocity()
{
return 0.5F;
}
protected float getInaccuracy()
{
return -20.0F;
}
/**
* Sets the PotionEffect by the given id of the potion effect.
*/
public void setPotionDamage(int potionId)
{
if (this.potionDamage == null)
{
this.potionDamage = new ItemStack(Items.potion, 1, 0);
}
this.potionDamage.setItemDamage(potionId);
}
/**
* Returns the damage value of the thrown potion that this EntityPotion represents.
*/
public int getPotionDamage()
{
if (this.potionDamage == null)
{
this.potionDamage = new ItemStack(Items.potion, 1, 0);
}
return this.potionDamage.getMetadata();
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(HitPosition p_70184_1_)
{
if (!this.worldObj.client)
{
List<PotionEffect> list = Items.potion.getEffects(this.potionDamage);
BoundingBox axisalignedbb = this.getEntityBoundingBox().expand(4.0D, 2.0D, 4.0D);
List<EntityLiving> list1 = this.worldObj.<EntityLiving>getEntitiesWithinAABB(EntityLiving.class, axisalignedbb);
if (!list1.isEmpty())
{
for (EntityLiving entitylivingbase : list1)
{
double d0 = this.getDistanceSqToEntity(entitylivingbase);
if (d0 < 16.0D)
{
if (list != null && !list.isEmpty())
{
double d1 = 1.0D - Math.sqrt(d0) / 4.0D;
if (entitylivingbase == p_70184_1_.entity)
{
d1 = 1.0D;
}
for (PotionEffect potioneffect : list)
{
int i = potioneffect.getPotionID();
if (Potion.POTION_TYPES[i].isInstant())
{
Potion.POTION_TYPES[i].affectEntity(this, this.getThrower(), entitylivingbase, potioneffect.getAmplifier(), d1);
}
else
{
int j = (int)(d1 * (double)potioneffect.getDuration() + 0.5D);
if (j > 20)
{
entitylivingbase.addEffect(new PotionEffect(i, j, potioneffect.getAmplifier()));
}
}
}
}
else {
entitylivingbase.extinguish();
}
}
}
}
this.worldObj.playAuxSFX(2002, new BlockPos(this), this.getPotionDamage());
this.setDead();
}
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
super.readEntityFromNBT(tagCompund);
if (tagCompund.hasKey("Potion", 10))
{
this.potionDamage = ItemStack.loadItemStackFromNBT(tagCompund.getCompoundTag("Potion"));
}
else
{
this.setPotionDamage(tagCompund.getInteger("potionValue"));
}
if (this.potionDamage == null)
{
this.setDead();
}
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
super.writeEntityToNBT(tagCompound);
if (this.potionDamage != null)
{
tagCompound.setTag("Potion", this.potionDamage.writeToNBT(new NBTTagCompound()));
}
}
public int getPacketData() {
return this.getPotionDamage();
}
// public boolean hasSpawnVelocity() {
// return false;
// }
}

View file

@ -0,0 +1,388 @@
package game.entity.projectile;
import java.util.List;
import game.ExtMath;
import game.block.Block;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.types.EntityLiving;
import game.init.BlockRegistry;
import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.renderer.particle.ParticleType;
import game.world.BlockPos;
import game.world.BoundingBox;
import game.world.HitPosition;
import game.world.Vec3;
import game.world.World;
public abstract class EntityProjectile extends Entity
{
private int xTile = -1;
private int yTile = -1;
private int zTile = -1;
private Block inTile;
private boolean inGround;
public EntityLiving shootingEntity;
private int ticksAlive;
private int ticksInAir;
public double accelerationX;
public double accelerationY;
public double accelerationZ;
private int age;
public EntityProjectile(World worldIn)
{
super(worldIn);
this.setSize(1.0F, 1.0F);
}
protected void entityInit()
{
}
/**
* Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
* length * 64 * renderDistanceWeight Args: distance
*/
public boolean isInRangeToRenderDist(double distance)
{
double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D;
if (Double.isNaN(d0))
{
d0 = 4.0D;
}
d0 = d0 * 64.0D;
return distance < d0 * d0;
}
public EntityProjectile(World worldIn, double x, double y, double z)
{
super(worldIn);
this.setSize(1.0F, 1.0F);
this.setLocationAndAngles(x, y, z, this.rotYaw, this.rotPitch);
this.setPosition(x, y, z);
}
public EntityProjectile(World worldIn, EntityLiving shooter, double accelX, double accelY, double accelZ, double random, double velo)
{
super(worldIn);
this.shootingEntity = shooter;
this.setSize(1.0F, 1.0F);
this.setLocationAndAngles(shooter.posX, shooter.posY, shooter.posZ, shooter.rotYaw, shooter.rotPitch);
this.setPosition(this.posX, this.posY, this.posZ);
this.motionX = this.motionY = this.motionZ = 0.0D;
accelX = accelX + this.rand.gaussian() * random;
accelY = accelY + this.rand.gaussian() * random;
accelZ = accelZ + this.rand.gaussian() * random;
double d0 = (double)ExtMath.sqrtd(accelX * accelX + accelY * accelY + accelZ * accelZ);
this.accelerationX = (accelX / d0 * 0.1D) * velo;
this.accelerationY = (accelY / d0 * 0.1D) * velo;
this.accelerationZ = (accelZ / d0 * 0.1D) * velo;
}
public void setAcceleration(double accelX, double accelY, double accelZ) {
double d0 = (double)ExtMath.sqrtd(accelX * accelX + accelY * accelY + accelZ * accelZ);
this.accelerationX = accelX / d0 * 0.1D;
this.accelerationY = accelY / d0 * 0.1D;
this.accelerationZ = accelZ / d0 * 0.1D;
}
public Vec3 getAcceleration() {
return new Vec3(this.accelerationX, this.accelerationY, this.accelerationZ);
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
if (this.worldObj.client || (this.shootingEntity == null || !this.shootingEntity.dead) && this.worldObj.isBlockLoaded(new BlockPos(this)))
{
super.onUpdate();
this.setFire(1);
if (this.inGround)
{
if (this.worldObj.getState(new BlockPos(this.xTile, this.yTile, this.zTile)).getBlock() == this.inTile)
{
++this.ticksAlive;
if (this.ticksAlive == 600)
{
this.setDead();
}
return;
}
this.inGround = false;
this.motionX *= (double)(this.rand.floatv() * 0.2F);
this.motionY *= (double)(this.rand.floatv() * 0.2F);
this.motionZ *= (double)(this.rand.floatv() * 0.2F);
this.ticksAlive = 0;
this.ticksInAir = 0;
}
else
{
++this.ticksInAir;
}
Vec3 vec3 = new Vec3(this.posX, this.posY, this.posZ);
Vec3 vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
HitPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
vec3 = new Vec3(this.posX, this.posY, this.posZ);
vec31 = new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (movingobjectposition != null)
{
vec31 = new Vec3(movingobjectposition.vec.xCoord, movingobjectposition.vec.yCoord, movingobjectposition.vec.zCoord);
}
Entity entity = null;
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double d0 = 0.0D;
for (int i = 0; i < list.size(); ++i)
{
Entity entity1 = (Entity)list.get(i);
if (entity1.canBeCollidedWith() && (!entity1.isEntityEqual(this.shootingEntity) || this.ticksInAir >= 25))
{
float f = 0.3F;
BoundingBox axisalignedbb = entity1.getEntityBoundingBox().expand((double)f, (double)f, (double)f);
HitPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);
if (movingobjectposition1 != null)
{
double d1 = vec3.squareDistanceTo(movingobjectposition1.vec);
if (d1 < d0 || d0 == 0.0D)
{
entity = entity1;
d0 = d1;
}
}
}
}
if (entity != null)
{
movingobjectposition = new HitPosition(entity);
}
if (movingobjectposition != null)
{
this.onImpact(movingobjectposition);
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
float f1 = ExtMath.sqrtd(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotYaw = (float)(ExtMath.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) + 90.0F;
for (this.rotPitch = (float)(ExtMath.atan2((double)f1, this.motionY) * 180.0D / Math.PI) - 90.0F; this.rotPitch - this.prevPitch < -180.0F; this.prevPitch -= 360.0F)
{
;
}
while (this.rotPitch - this.prevPitch >= 180.0F)
{
this.prevPitch += 360.0F;
}
while (this.rotYaw - this.prevYaw < -180.0F)
{
this.prevYaw -= 360.0F;
}
while (this.rotYaw - this.prevYaw >= 180.0F)
{
this.prevYaw += 360.0F;
}
this.rotPitch = this.prevPitch + (this.rotPitch - this.prevPitch) * 0.2F;
this.rotYaw = this.prevYaw + (this.rotYaw - this.prevYaw) * 0.2F;
float f2 = this.getMotionFactor();
if (this.isInLiquid())
{
for (int j = 0; j < 4; ++j)
{
float f3 = 0.25F;
this.worldObj.spawnParticle(ParticleType.WATER_BUBBLE, this.posX - this.motionX * (double)f3, this.posY - this.motionY * (double)f3, this.posZ - this.motionZ * (double)f3, this.motionX, this.motionY, this.motionZ);
}
f2 = 0.8F;
}
this.motionX += this.accelerationX;
this.motionY += this.accelerationY;
this.motionZ += this.accelerationZ;
this.motionX *= (double)f2;
this.motionY *= (double)f2;
this.motionZ *= (double)f2;
this.worldObj.spawnParticle(ParticleType.SMOKE_NORMAL, this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D);
this.setPosition(this.posX, this.posY, this.posZ);
}
else
{
this.setDead();
}
if(!this.worldObj.client && this.age++ >= 200)
this.setDead();
}
/**
* Return the motion factor for this projectile. The factor is multiplied by the original motion.
*/
protected float getMotionFactor()
{
return 0.95F;
}
/**
* Called when this EntityFireball hits a block or entity.
*/
protected abstract void onImpact(HitPosition movingObject);
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
tagCompound.setShort("xTile", (short)this.xTile);
tagCompound.setShort("yTile", (short)this.yTile);
tagCompound.setShort("zTile", (short)this.zTile);
String resourcelocation = BlockRegistry.REGISTRY.getNameForObject(this.inTile);
tagCompound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
tagCompound.setTag("direction", this.newDoubleNBTList(this.motionX, this.motionY, this.motionZ));
tagCompound.setInteger("Age", this.age);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound tagCompund)
{
this.xTile = tagCompund.getShort("xTile");
this.yTile = tagCompund.getShort("yTile");
this.zTile = tagCompund.getShort("zTile");
if (tagCompund.hasKey("inTile", 8))
{
this.inTile = BlockRegistry.getByIdFallback(tagCompund.getString("inTile"));
}
else
{
this.inTile = BlockRegistry.getBlockById(tagCompund.getByte("inTile") & 255);
}
this.inGround = tagCompund.getByte("inGround") == 1;
if (tagCompund.hasKey("direction", 9))
{
NBTTagList nbttaglist = tagCompund.getTagList("direction", 6);
this.motionX = nbttaglist.getDoubleAt(0);
this.motionY = nbttaglist.getDoubleAt(1);
this.motionZ = nbttaglist.getDoubleAt(2);
}
else
{
this.setDead();
}
this.age = tagCompund.getInteger("Age");
}
/**
* Returns true if other Entities should be prevented from moving through this Entity.
*/
public boolean canBeCollidedWith()
{
return true;
}
public float getCollisionBorderSize()
{
return 1.0F;
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource source, int amount)
{
if (this.isEntityInvulnerable(source))
{
return false;
}
else
{
this.setBeenAttacked();
if (source.getEntity() != null)
{
Vec3 vec3 = source.getEntity().getLookVec();
if (vec3 != null)
{
this.motionX = vec3.xCoord;
this.motionY = vec3.yCoord;
this.motionZ = vec3.zCoord;
this.accelerationX = this.motionX * 0.1D;
this.accelerationY = this.motionY * 0.1D;
this.accelerationZ = this.motionZ * 0.1D;
}
if (source.getEntity() instanceof EntityLiving)
{
this.shootingEntity = (EntityLiving)source.getEntity();
}
return true;
}
else
{
return false;
}
}
}
/**
* Gets how bright this entity is.
*/
public float getBrightness(float partialTicks)
{
return 1.0F;
}
public int getBrightnessForRender(float partialTicks)
{
return 15728880;
}
public int getTrackingRange() {
return 64;
}
public int getUpdateFrequency() {
return 1; // 10
}
public boolean isSendingVeloUpdates() {
return false;
}
// public int getPacketData() {
// return this.shootingEntity != null ? this.shootingEntity.getId() : 0;
// }
// public boolean hasSpawnVelocity() {
// return false;
// }
}

View file

@ -0,0 +1,56 @@
package game.entity.projectile;
import game.entity.DamageSource;
import game.entity.types.EntityLiving;
import game.entity.types.EntityThrowable;
import game.init.Config;
import game.renderer.particle.ParticleType;
import game.world.HitPosition;
import game.world.World;
public class EntitySnowball extends EntityThrowable
{
public EntitySnowball(World worldIn)
{
super(worldIn);
}
public EntitySnowball(World worldIn, EntityLiving throwerIn)
{
super(worldIn, throwerIn);
}
public EntitySnowball(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(HitPosition p_70184_1_)
{
if (p_70184_1_.entity != null)
{
// int i = 0;
// if (p_70184_1_.entityHit instanceof EntityBlaze && Config.blazeSnowballDamage)
// {
// i = 3;
// }
if(Config.knockSnowball)
p_70184_1_.entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
}
for (int j = 0; j < 8; ++j)
{
this.worldObj.spawnParticle(ParticleType.SNOWBALL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
if (!this.worldObj.client)
{
this.setDead();
}
}
}

View file

@ -0,0 +1,61 @@
package game.entity.projectile;
import game.enchantment.EnchantmentHelper;
import game.item.ItemStack;
import game.rng.Random;
import game.rng.RngItem;
public class RngFishable extends RngItem
{
private final ItemStack returnStack;
private float maxDamagePercent;
private boolean enchantable;
public RngFishable(ItemStack returnStackIn, int itemWeightIn)
{
super(itemWeightIn);
this.returnStack = returnStackIn;
}
public ItemStack getItemStack(Random random)
{
ItemStack itemstack = this.returnStack.copy();
if (this.maxDamagePercent > 0.0F)
{
int i = (int)(this.maxDamagePercent * (float)this.returnStack.getMaxDamage());
int j = itemstack.getMaxDamage() - random.zrange(random.zrange(i) + 1);
if (j > i)
{
j = i;
}
if (j < 1)
{
j = 1;
}
itemstack.setItemDamage(j);
}
if (this.enchantable)
{
EnchantmentHelper.addRandomEnchantment(random, itemstack, 30);
}
return itemstack;
}
public RngFishable setMaxDamagePercent(float maxDamagePercentIn)
{
this.maxDamagePercent = maxDamagePercentIn;
return this;
}
public RngFishable setEnchantable()
{
this.enchantable = true;
return this;
}
}