base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,728 @@
package net.minecraft.entity.projectile;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Enchantments;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.network.play.server.SPacketChangeGameState;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class EntityArrow extends Entity implements IProjectile
{
private static final Predicate<Entity> ARROW_TARGETS = Predicates.and(EntitySelectors.NOT_SPECTATING, EntitySelectors.IS_ALIVE, new Predicate<Entity>()
{
public boolean apply(@Nullable Entity p_apply_1_)
{
return p_apply_1_.canBeCollidedWith();
}
});
private static final DataParameter<Byte> CRITICAL = EntityDataManager.<Byte>createKey(EntityArrow.class, DataSerializers.BYTE);
private int xTile;
private int yTile;
private int zTile;
private Block inTile;
private int inData;
protected boolean inGround;
protected int timeInGround;
/** 1 if the player can pick up the arrow */
public EntityArrow.PickupStatus pickupStatus;
/** 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;
/** The amount of knockback an arrow applies when it hits a mob. */
private int knockbackStrength;
public EntityArrow(World worldIn)
{
super(worldIn);
this.xTile = -1;
this.yTile = -1;
this.zTile = -1;
this.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
this.damage = 2.0D;
this.setSize(0.5F, 0.5F);
}
public EntityArrow(World worldIn, double x, double y, double z)
{
this(worldIn);
this.setPosition(x, y, z);
}
public EntityArrow(World worldIn, EntityLivingBase shooter)
{
this(worldIn, shooter.posX, shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D, shooter.posZ);
this.shootingEntity = shooter;
if (shooter instanceof EntityPlayer)
{
this.pickupStatus = EntityArrow.PickupStatus.ALLOWED;
}
}
/**
* Checks if the entity is in range to render.
*/
@SideOnly(Side.CLIENT)
public boolean isInRangeToRenderDist(double distance)
{
double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 10.0D;
if (Double.isNaN(d0))
{
d0 = 1.0D;
}
d0 = d0 * 64.0D * getRenderDistanceWeight();
return distance < d0 * d0;
}
protected void entityInit()
{
this.dataManager.register(CRITICAL, Byte.valueOf((byte)0));
}
public void shoot(Entity shooter, float pitch, float yaw, float p_184547_4_, float velocity, float inaccuracy)
{
float f = -MathHelper.sin(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
float f1 = -MathHelper.sin(pitch * 0.017453292F);
float f2 = MathHelper.cos(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
this.shoot((double)f, (double)f1, (double)f2, velocity, inaccuracy);
this.motionX += shooter.motionX;
this.motionZ += shooter.motionZ;
if (!shooter.onGround)
{
this.motionY += shooter.motionY;
}
}
/**
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
*/
public void shoot(double x, double y, double z, float velocity, float inaccuracy)
{
float f = MathHelper.sqrt(x * x + y * y + z * z);
x = x / (double)f;
y = y / (double)f;
z = z / (double)f;
x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
z = z + this.rand.nextGaussian() * 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 = MathHelper.sqrt(x * x + z * z);
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
this.ticksInGround = 0;
}
/**
* Set the position and rotation values directly without any clamping.
*/
@SideOnly(Side.CLIENT)
public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
{
this.setPosition(x, y, z);
this.setRotation(yaw, pitch);
}
/**
* Updates the entity motion clientside, called by packets from the server
*/
@SideOnly(Side.CLIENT)
public void setVelocity(double x, double y, double z)
{
this.motionX = x;
this.motionY = y;
this.motionZ = z;
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
{
float f = MathHelper.sqrt(x * x + z * z);
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
this.ticksInGround = 0;
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
{
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
}
BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
IBlockState iblockstate = this.world.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (iblockstate.getMaterial() != Material.AIR)
{
AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).contains(new Vec3d(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.world.collidesWithAnyBlock(this.getEntityBoundingBox().grow(0.05D)))
{
this.inGround = false;
this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
this.ticksInGround = 0;
this.ticksInAir = 0;
}
else
{
++this.ticksInGround;
if (this.ticksInGround >= 1200)
{
this.setDead();
}
}
++this.timeInGround;
}
else
{
this.timeInGround = 0;
++this.ticksInAir;
Vec3d vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d1, vec3d, false, true, false);
vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (raytraceresult != null)
{
vec3d = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
}
Entity entity = this.findEntityOnPath(vec3d1, vec3d);
if (entity != null)
{
raytraceresult = new RayTraceResult(entity);
}
if (raytraceresult != null && raytraceresult.entityHit instanceof EntityPlayer)
{
EntityPlayer entityplayer = (EntityPlayer)raytraceresult.entityHit;
if (this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer))
{
raytraceresult = null;
}
}
if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult))
{
this.onHit(raytraceresult);
}
if (this.getIsCritical())
{
for (int k = 0; k < 4; ++k)
{
this.world.spawnParticle(EnumParticleTypes.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 f4 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f4) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
{
;
}
while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
{
this.prevRotationPitch += 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw < -180.0F)
{
this.prevRotationYaw -= 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
{
this.prevRotationYaw += 360.0F;
}
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
float f1 = 0.99F;
float f2 = 0.05F;
if (this.isInWater())
{
for (int i = 0; i < 4; ++i)
{
float f3 = 0.25F;
this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ);
}
f1 = 0.6F;
}
if (this.isWet())
{
this.extinguish();
}
this.motionX *= (double)f1;
this.motionY *= (double)f1;
this.motionZ *= (double)f1;
if (!this.hasNoGravity())
{
this.motionY -= 0.05000000074505806D;
}
this.setPosition(this.posX, this.posY, this.posZ);
this.doBlockCollisions();
}
}
/**
* Called when the arrow hits a block or an entity
*/
protected void onHit(RayTraceResult raytraceResultIn)
{
Entity entity = raytraceResultIn.entityHit;
if (entity != null)
{
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
int i = MathHelper.ceil((double)f * this.damage);
if (this.getIsCritical())
{
i += this.rand.nextInt(i / 2 + 2);
}
DamageSource damagesource;
if (this.shootingEntity == null)
{
damagesource = DamageSource.causeArrowDamage(this, this);
}
else
{
damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity);
}
if (this.isBurning() && !(entity instanceof EntityEnderman))
{
entity.setFire(5);
}
if (entity.attackEntityFrom(damagesource, (float)i))
{
if (entity instanceof EntityLivingBase)
{
EntityLivingBase entitylivingbase = (EntityLivingBase)entity;
if (!this.world.isRemote)
{
entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
}
if (this.knockbackStrength > 0)
{
float f1 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (f1 > 0.0F)
{
entitylivingbase.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1);
}
}
if (this.shootingEntity instanceof EntityLivingBase)
{
EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase)this.shootingEntity, entitylivingbase);
}
this.arrowHit(entitylivingbase);
if (this.shootingEntity != null && entitylivingbase != this.shootingEntity && entitylivingbase instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP)
{
((EntityPlayerMP)this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
}
}
this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
if (!(entity instanceof EntityEnderman))
{
this.setDead();
}
}
else
{
this.motionX *= -0.10000000149011612D;
this.motionY *= -0.10000000149011612D;
this.motionZ *= -0.10000000149011612D;
this.rotationYaw += 180.0F;
this.prevRotationYaw += 180.0F;
this.ticksInAir = 0;
if (!this.world.isRemote && this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ < 0.0010000000474974513D)
{
if (this.pickupStatus == EntityArrow.PickupStatus.ALLOWED)
{
this.entityDropItem(this.getArrowStack(), 0.1F);
}
this.setDead();
}
}
}
else
{
BlockPos blockpos = raytraceResultIn.getBlockPos();
this.xTile = blockpos.getX();
this.yTile = blockpos.getY();
this.zTile = blockpos.getZ();
IBlockState iblockstate = this.world.getBlockState(blockpos);
this.inTile = iblockstate.getBlock();
this.inData = this.inTile.getMetaFromState(iblockstate);
this.motionX = (double)((float)(raytraceResultIn.hitVec.x - this.posX));
this.motionY = (double)((float)(raytraceResultIn.hitVec.y - this.posY));
this.motionZ = (double)((float)(raytraceResultIn.hitVec.z - this.posZ));
float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
this.posX -= this.motionX / (double)f2 * 0.05000000074505806D;
this.posY -= this.motionY / (double)f2 * 0.05000000074505806D;
this.posZ -= this.motionZ / (double)f2 * 0.05000000074505806D;
this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
this.inGround = true;
this.arrowShake = 7;
this.setIsCritical(false);
if (iblockstate.getMaterial() != Material.AIR)
{
this.inTile.onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this);
}
}
}
/**
* Tries to move the entity towards the specified location.
*/
public void move(MoverType type, double x, double y, double z)
{
super.move(type, x, y, z);
if (this.inGround)
{
this.xTile = MathHelper.floor(this.posX);
this.yTile = MathHelper.floor(this.posY);
this.zTile = MathHelper.floor(this.posZ);
}
}
protected void arrowHit(EntityLivingBase living)
{
}
@Nullable
protected Entity findEntityOnPath(Vec3d start, Vec3d end)
{
Entity entity = null;
List<Entity> list = this.world.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D), ARROW_TARGETS);
double d0 = 0.0D;
for (int i = 0; i < list.size(); ++i)
{
Entity entity1 = list.get(i);
if (entity1 != this.shootingEntity || this.ticksInAir >= 5)
{
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(start, end);
if (raytraceresult != null)
{
double d1 = start.squareDistanceTo(raytraceresult.hitVec);
if (d1 < d0 || d0 == 0.0D)
{
entity = entity1;
d0 = d1;
}
}
}
}
return entity;
}
public static void registerFixesArrow(DataFixer fixer, String name)
{
}
public static void registerFixesArrow(DataFixer fixer)
{
registerFixesArrow(fixer, "Arrow");
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
compound.setInteger("xTile", this.xTile);
compound.setInteger("yTile", this.yTile);
compound.setInteger("zTile", this.zTile);
compound.setShort("life", (short)this.ticksInGround);
ResourceLocation resourcelocation = Block.REGISTRY.getNameForObject(this.inTile);
compound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
compound.setByte("inData", (byte)this.inData);
compound.setByte("shake", (byte)this.arrowShake);
compound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
compound.setByte("pickup", (byte)this.pickupStatus.ordinal());
compound.setDouble("damage", this.damage);
compound.setBoolean("crit", this.getIsCritical());
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
this.xTile = compound.getInteger("xTile");
this.yTile = compound.getInteger("yTile");
this.zTile = compound.getInteger("zTile");
this.ticksInGround = compound.getShort("life");
if (compound.hasKey("inTile", 8))
{
this.inTile = Block.getBlockFromName(compound.getString("inTile"));
}
else
{
this.inTile = Block.getBlockById(compound.getByte("inTile") & 255);
}
this.inData = compound.getByte("inData") & 255;
this.arrowShake = compound.getByte("shake") & 255;
this.inGround = compound.getByte("inGround") == 1;
if (compound.hasKey("damage", 99))
{
this.damage = compound.getDouble("damage");
}
if (compound.hasKey("pickup", 99))
{
this.pickupStatus = EntityArrow.PickupStatus.getByOrdinal(compound.getByte("pickup"));
}
else if (compound.hasKey("player", 99))
{
this.pickupStatus = compound.getBoolean("player") ? EntityArrow.PickupStatus.ALLOWED : EntityArrow.PickupStatus.DISALLOWED;
}
this.setIsCritical(compound.getBoolean("crit"));
}
/**
* Called by a player entity when they collide with an entity
*/
public void onCollideWithPlayer(EntityPlayer entityIn)
{
if (!this.world.isRemote && this.inGround && this.arrowShake <= 0)
{
boolean flag = this.pickupStatus == EntityArrow.PickupStatus.ALLOWED || this.pickupStatus == EntityArrow.PickupStatus.CREATIVE_ONLY && entityIn.capabilities.isCreativeMode;
if (this.pickupStatus == EntityArrow.PickupStatus.ALLOWED && !entityIn.inventory.addItemStackToInventory(this.getArrowStack()))
{
flag = false;
}
if (flag)
{
entityIn.onItemPickup(this, 1);
this.setDead();
}
}
}
protected abstract ItemStack getArrowStack();
/**
* 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;
}
/**
* Returns true if it's possible to attack this entity with an item.
*/
public boolean canBeAttackedWithItem()
{
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 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
if (critical)
{
this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 | 1)));
}
else
{
this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 & -2)));
}
}
/**
* Whether the arrow has a stream of critical hit particles flying behind it.
*/
public boolean getIsCritical()
{
byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
return (b0 & 1) != 0;
}
public void setEnchantmentEffectsFromEntity(EntityLivingBase p_190547_1_, float p_190547_2_)
{
int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, p_190547_1_);
int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, p_190547_1_);
this.setDamage((double)(p_190547_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.world.getDifficulty().getDifficultyId() * 0.11F));
if (i > 0)
{
this.setDamage(this.getDamage() + (double)i * 0.5D + 0.5D);
}
if (j > 0)
{
this.setKnockbackStrength(j);
}
if (EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FLAME, p_190547_1_) > 0)
{
this.setFire(100);
}
}
public static enum PickupStatus
{
DISALLOWED,
ALLOWED,
CREATIVE_ONLY;
public static EntityArrow.PickupStatus getByOrdinal(int ordinal)
{
if (ordinal < 0 || ordinal > values().length)
{
ordinal = 0;
}
return values()[ordinal];
}
}
}

View File

@@ -0,0 +1,107 @@
package net.minecraft.entity.projectile;
import java.util.List;
import net.minecraft.entity.EntityAreaEffectCloud;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityDragonFireball extends EntityFireball
{
public EntityDragonFireball(World worldIn)
{
super(worldIn);
this.setSize(1.0F, 1.0F);
}
@SideOnly(Side.CLIENT)
public EntityDragonFireball(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
{
super(worldIn, x, y, z, accelX, accelY, accelZ);
this.setSize(1.0F, 1.0F);
}
public EntityDragonFireball(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ)
{
super(worldIn, shooter, accelX, accelY, accelZ);
this.setSize(1.0F, 1.0F);
}
public static void registerFixesDragonFireball(DataFixer fixer)
{
EntityFireball.registerFixesFireball(fixer, "DragonFireball");
}
/**
* Called when this EntityFireball hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (result.entityHit == null || !result.entityHit.isEntityEqual(this.shootingEntity))
{
if (!this.world.isRemote)
{
List<EntityLivingBase> list = this.world.<EntityLivingBase>getEntitiesWithinAABB(EntityLivingBase.class, this.getEntityBoundingBox().grow(4.0D, 2.0D, 4.0D));
EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.world, this.posX, this.posY, this.posZ);
entityareaeffectcloud.setOwner(this.shootingEntity);
entityareaeffectcloud.setParticle(EnumParticleTypes.DRAGON_BREATH);
entityareaeffectcloud.setRadius(3.0F);
entityareaeffectcloud.setDuration(600);
entityareaeffectcloud.setRadiusPerTick((7.0F - entityareaeffectcloud.getRadius()) / (float)entityareaeffectcloud.getDuration());
entityareaeffectcloud.addEffect(new PotionEffect(MobEffects.INSTANT_DAMAGE, 1, 1));
if (!list.isEmpty())
{
for (EntityLivingBase entitylivingbase : list)
{
double d0 = this.getDistanceSq(entitylivingbase);
if (d0 < 16.0D)
{
entityareaeffectcloud.setPosition(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ);
break;
}
}
}
this.world.playEvent(2006, new BlockPos(this.posX, this.posY, this.posZ), 0);
this.world.spawnEntity(entityareaeffectcloud);
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, float amount)
{
return false;
}
protected EnumParticleTypes getParticleType()
{
return EnumParticleTypes.DRAGON_BREATH;
}
protected boolean isFireballFiery()
{
return false;
}
}

View File

@@ -0,0 +1,88 @@
package net.minecraft.entity.projectile;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityEgg extends EntityThrowable
{
public EntityEgg(World worldIn)
{
super(worldIn);
}
public EntityEgg(World worldIn, EntityLivingBase throwerIn)
{
super(worldIn, throwerIn);
}
public EntityEgg(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
public static void registerFixesEgg(DataFixer fixer)
{
EntityThrowable.registerFixesThrowable(fixer, "ThrownEgg");
}
/**
* Handler for {@link World#setEntityState}
*/
@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id)
{
if (id == 3)
{
double d0 = 0.08D;
for (int i = 0; i < 8; ++i)
{
this.world.spawnParticle(EnumParticleTypes.ITEM_CRACK, this.posX, this.posY, this.posZ, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, ((double)this.rand.nextFloat() - 0.5D) * 0.08D, Item.getIdFromItem(Items.EGG));
}
}
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (result.entityHit != null)
{
result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);
}
if (!this.world.isRemote)
{
if (this.rand.nextInt(8) == 0)
{
int i = 1;
if (this.rand.nextInt(32) == 0)
{
i = 4;
}
for (int j = 0; j < i; ++j)
{
EntityChicken entitychicken = new EntityChicken(this.world);
entitychicken.setGrowingAge(-24000);
entitychicken.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
this.world.spawnEntity(entitychicken);
}
}
this.world.setEntityState(this, (byte)3);
this.setDead();
}
}
}

View File

@@ -0,0 +1,194 @@
package net.minecraft.entity.projectile;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.SoundEvents;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityEvokerFangs extends Entity
{
private int warmupDelayTicks;
private boolean sentSpikeEvent;
private int lifeTicks;
private boolean clientSideAttackStarted;
private EntityLivingBase caster;
private UUID casterUuid;
public EntityEvokerFangs(World worldIn)
{
super(worldIn);
this.lifeTicks = 22;
this.setSize(0.5F, 0.8F);
}
public EntityEvokerFangs(World worldIn, double x, double y, double z, float p_i47276_8_, int p_i47276_9_, EntityLivingBase casterIn)
{
this(worldIn);
this.warmupDelayTicks = p_i47276_9_;
this.setCaster(casterIn);
this.rotationYaw = p_i47276_8_ * (180F / (float)Math.PI);
this.setPosition(x, y, z);
}
protected void entityInit()
{
}
public void setCaster(@Nullable EntityLivingBase p_190549_1_)
{
this.caster = p_190549_1_;
this.casterUuid = p_190549_1_ == null ? null : p_190549_1_.getUniqueID();
}
@Nullable
public EntityLivingBase getCaster()
{
if (this.caster == null && this.casterUuid != null && this.world instanceof WorldServer)
{
Entity entity = ((WorldServer)this.world).getEntityFromUuid(this.casterUuid);
if (entity instanceof EntityLivingBase)
{
this.caster = (EntityLivingBase)entity;
}
}
return this.caster;
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
protected void readEntityFromNBT(NBTTagCompound compound)
{
this.warmupDelayTicks = compound.getInteger("Warmup");
this.casterUuid = compound.getUniqueId("OwnerUUID");
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
protected void writeEntityToNBT(NBTTagCompound compound)
{
compound.setInteger("Warmup", this.warmupDelayTicks);
if (this.casterUuid != null)
{
compound.setUniqueId("OwnerUUID", this.casterUuid);
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.world.isRemote)
{
if (this.clientSideAttackStarted)
{
--this.lifeTicks;
if (this.lifeTicks == 14)
{
for (int i = 0; i < 12; ++i)
{
double d0 = this.posX + (this.rand.nextDouble() * 2.0D - 1.0D) * (double)this.width * 0.5D;
double d1 = this.posY + 0.05D + this.rand.nextDouble() * 1.0D;
double d2 = this.posZ + (this.rand.nextDouble() * 2.0D - 1.0D) * (double)this.width * 0.5D;
double d3 = (this.rand.nextDouble() * 2.0D - 1.0D) * 0.3D;
double d4 = 0.3D + this.rand.nextDouble() * 0.3D;
double d5 = (this.rand.nextDouble() * 2.0D - 1.0D) * 0.3D;
this.world.spawnParticle(EnumParticleTypes.CRIT, d0, d1 + 1.0D, d2, d3, d4, d5);
}
}
}
}
else if (--this.warmupDelayTicks < 0)
{
if (this.warmupDelayTicks == -8)
{
for (EntityLivingBase entitylivingbase : this.world.getEntitiesWithinAABB(EntityLivingBase.class, this.getEntityBoundingBox().grow(0.2D, 0.0D, 0.2D)))
{
this.damage(entitylivingbase);
}
}
if (!this.sentSpikeEvent)
{
this.world.setEntityState(this, (byte)4);
this.sentSpikeEvent = true;
}
if (--this.lifeTicks < 0)
{
this.setDead();
}
}
}
private void damage(EntityLivingBase p_190551_1_)
{
EntityLivingBase entitylivingbase = this.getCaster();
if (p_190551_1_.isEntityAlive() && !p_190551_1_.getIsInvulnerable() && p_190551_1_ != entitylivingbase)
{
if (entitylivingbase == null)
{
p_190551_1_.attackEntityFrom(DamageSource.MAGIC, 6.0F);
}
else
{
if (entitylivingbase.isOnSameTeam(p_190551_1_))
{
return;
}
p_190551_1_.attackEntityFrom(DamageSource.causeIndirectMagicDamage(this, entitylivingbase), 6.0F);
}
}
}
/**
* Handler for {@link World#setEntityState}
*/
@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id)
{
super.handleStatusUpdate(id);
if (id == 4)
{
this.clientSideAttackStarted = true;
if (!this.isSilent())
{
this.world.playSound(this.posX, this.posY, this.posZ, SoundEvents.EVOCATION_FANGS_ATTACK, this.getSoundCategory(), 1.0F, this.rand.nextFloat() * 0.2F + 0.85F, false);
}
}
}
@SideOnly(Side.CLIENT)
public float getAnimationProgress(float partialTicks)
{
if (!this.clientSideAttackStarted)
{
return 0.0F;
}
else
{
int i = this.lifeTicks - 2;
return i <= 0 ? 1.0F : 1.0F - ((float)i - partialTicks) / 20.0F;
}
}
}

View File

@@ -0,0 +1,275 @@
package net.minecraft.entity.projectile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class EntityFireball extends Entity
{
public EntityLivingBase shootingEntity;
private int ticksAlive;
private int ticksInAir;
public double accelerationX;
public double accelerationY;
public double accelerationZ;
public EntityFireball(World worldIn)
{
super(worldIn);
this.setSize(1.0F, 1.0F);
}
protected void entityInit()
{
}
/**
* Checks if the entity is in range to render.
*/
@SideOnly(Side.CLIENT)
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 EntityFireball(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
{
super(worldIn);
this.setSize(1.0F, 1.0F);
this.setLocationAndAngles(x, y, z, this.rotationYaw, this.rotationPitch);
this.setPosition(x, y, z);
double d0 = (double)MathHelper.sqrt(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 EntityFireball(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ)
{
super(worldIn);
this.shootingEntity = shooter;
this.setSize(1.0F, 1.0F);
this.setLocationAndAngles(shooter.posX, shooter.posY, shooter.posZ, shooter.rotationYaw, shooter.rotationPitch);
this.setPosition(this.posX, this.posY, this.posZ);
this.motionX = 0.0D;
this.motionY = 0.0D;
this.motionZ = 0.0D;
accelX = accelX + this.rand.nextGaussian() * 0.4D;
accelY = accelY + this.rand.nextGaussian() * 0.4D;
accelZ = accelZ + this.rand.nextGaussian() * 0.4D;
double d0 = (double)MathHelper.sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ);
this.accelerationX = accelX / d0 * 0.1D;
this.accelerationY = accelY / d0 * 0.1D;
this.accelerationZ = accelZ / d0 * 0.1D;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
if (this.world.isRemote || (this.shootingEntity == null || !this.shootingEntity.isDead) && this.world.isBlockLoaded(new BlockPos(this)))
{
super.onUpdate();
if (this.isFireballFiery())
{
this.setFire(1);
}
++this.ticksInAir;
RayTraceResult raytraceresult = ProjectileHelper.forwardsRaycast(this, true, this.ticksInAir >= 25, this.shootingEntity);
if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult))
{
this.onImpact(raytraceresult);
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
ProjectileHelper.rotateTowardsMovement(this, 0.2F);
float f = this.getMotionFactor();
if (this.isInWater())
{
for (int i = 0; i < 4; ++i)
{
float f1 = 0.25F;
this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ);
}
f = 0.8F;
}
this.motionX += this.accelerationX;
this.motionY += this.accelerationY;
this.motionZ += this.accelerationZ;
this.motionX *= (double)f;
this.motionY *= (double)f;
this.motionZ *= (double)f;
this.world.spawnParticle(this.getParticleType(), 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();
}
}
protected boolean isFireballFiery()
{
return true;
}
protected EnumParticleTypes getParticleType()
{
return EnumParticleTypes.SMOKE_NORMAL;
}
/**
* 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(RayTraceResult result);
public static void registerFixesFireball(DataFixer fixer, String name)
{
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
compound.setTag("direction", this.newDoubleNBTList(new double[] {this.motionX, this.motionY, this.motionZ}));
compound.setTag("power", this.newDoubleNBTList(new double[] {this.accelerationX, this.accelerationY, this.accelerationZ}));
compound.setInteger("life", this.ticksAlive);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
if (compound.hasKey("power", 9))
{
NBTTagList nbttaglist = compound.getTagList("power", 6);
if (nbttaglist.tagCount() == 3)
{
this.accelerationX = nbttaglist.getDoubleAt(0);
this.accelerationY = nbttaglist.getDoubleAt(1);
this.accelerationZ = nbttaglist.getDoubleAt(2);
}
}
this.ticksAlive = compound.getInteger("life");
if (compound.hasKey("direction", 9) && compound.getTagList("direction", 6).tagCount() == 3)
{
NBTTagList nbttaglist1 = compound.getTagList("direction", 6);
this.motionX = nbttaglist1.getDoubleAt(0);
this.motionY = nbttaglist1.getDoubleAt(1);
this.motionZ = nbttaglist1.getDoubleAt(2);
}
else
{
this.setDead();
}
}
/**
* 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, float amount)
{
if (this.isEntityInvulnerable(source))
{
return false;
}
else
{
this.markVelocityChanged();
if (source.getTrueSource() != null)
{
Vec3d vec3d = source.getTrueSource().getLookVec();
if (vec3d != null)
{
this.motionX = vec3d.x;
this.motionY = vec3d.y;
this.motionZ = vec3d.z;
this.accelerationX = this.motionX * 0.1D;
this.accelerationY = this.motionY * 0.1D;
this.accelerationZ = this.motionZ * 0.1D;
}
if (source.getTrueSource() instanceof EntityLivingBase)
{
this.shootingEntity = (EntityLivingBase)source.getTrueSource();
}
return true;
}
else
{
return false;
}
}
}
/**
* Gets how bright this entity is.
*/
public float getBrightness()
{
return 1.0F;
}
@SideOnly(Side.CLIENT)
public int getBrightnessForRender()
{
return 15728880;
}
}

View File

@@ -0,0 +1,643 @@
package net.minecraft.entity.projectile;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.stats.StatList;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityFishHook extends Entity
{
private static final DataParameter<Integer> DATA_HOOKED_ENTITY = EntityDataManager.<Integer>createKey(EntityFishHook.class, DataSerializers.VARINT);
private boolean inGround;
private int ticksInGround;
private EntityPlayer angler;
private int ticksInAir;
private int ticksCatchable;
private int ticksCaughtDelay;
private int ticksCatchableDelay;
private float fishApproachAngle;
public Entity caughtEntity;
private EntityFishHook.State currentState = EntityFishHook.State.FLYING;
private int luck;
private int lureSpeed;
@SideOnly(Side.CLIENT)
public EntityFishHook(World worldIn, EntityPlayer p_i47290_2_, double x, double y, double z)
{
super(worldIn);
this.init(p_i47290_2_);
this.setPosition(x, y, z);
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
}
public EntityFishHook(World worldIn, EntityPlayer fishingPlayer)
{
super(worldIn);
this.init(fishingPlayer);
this.shoot();
}
private void init(EntityPlayer p_190626_1_)
{
this.setSize(0.25F, 0.25F);
this.ignoreFrustumCheck = true;
this.angler = p_190626_1_;
this.angler.fishEntity = this;
}
public void setLureSpeed(int p_191516_1_)
{
this.lureSpeed = p_191516_1_;
}
public void setLuck(int p_191517_1_)
{
this.luck = p_191517_1_;
}
private void shoot()
{
float f = this.angler.prevRotationPitch + (this.angler.rotationPitch - this.angler.prevRotationPitch);
float f1 = this.angler.prevRotationYaw + (this.angler.rotationYaw - this.angler.prevRotationYaw);
float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI);
float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI);
float f4 = -MathHelper.cos(-f * 0.017453292F);
float f5 = MathHelper.sin(-f * 0.017453292F);
double d0 = this.angler.prevPosX + (this.angler.posX - this.angler.prevPosX) - (double)f3 * 0.3D;
double d1 = this.angler.prevPosY + (this.angler.posY - this.angler.prevPosY) + (double)this.angler.getEyeHeight();
double d2 = this.angler.prevPosZ + (this.angler.posZ - this.angler.prevPosZ) - (double)f2 * 0.3D;
this.setLocationAndAngles(d0, d1, d2, f1, f);
this.motionX = (double)(-f3);
this.motionY = (double)MathHelper.clamp(-(f5 / f4), -5.0F, 5.0F);
this.motionZ = (double)(-f2);
float f6 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
this.motionX *= 0.6D / (double)f6 + 0.5D + this.rand.nextGaussian() * 0.0045D;
this.motionY *= 0.6D / (double)f6 + 0.5D + this.rand.nextGaussian() * 0.0045D;
this.motionZ *= 0.6D / (double)f6 + 0.5D + this.rand.nextGaussian() * 0.0045D;
float f7 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f7) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
}
protected void entityInit()
{
this.getDataManager().register(DATA_HOOKED_ENTITY, Integer.valueOf(0));
}
public void notifyDataManagerChange(DataParameter<?> key)
{
if (DATA_HOOKED_ENTITY.equals(key))
{
int i = ((Integer)this.getDataManager().get(DATA_HOOKED_ENTITY)).intValue();
this.caughtEntity = i > 0 ? this.world.getEntityByID(i - 1) : null;
}
super.notifyDataManagerChange(key);
}
/**
* Checks if the entity is in range to render.
*/
@SideOnly(Side.CLIENT)
public boolean isInRangeToRenderDist(double distance)
{
double d0 = 64.0D;
return distance < 4096.0D;
}
/**
* Set the position and rotation values directly without any clamping.
*/
@SideOnly(Side.CLIENT)
public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
{
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.angler == null)
{
this.setDead();
}
else if (this.world.isRemote || !this.shouldStopFishing())
{
if (this.inGround)
{
++this.ticksInGround;
if (this.ticksInGround >= 1200)
{
this.setDead();
return;
}
}
float f = 0.0F;
BlockPos blockpos = new BlockPos(this);
IBlockState iblockstate = this.world.getBlockState(blockpos);
if (iblockstate.getMaterial() == Material.WATER)
{
f = BlockLiquid.getBlockLiquidHeight(iblockstate, this.world, blockpos);
}
if (this.currentState == EntityFishHook.State.FLYING)
{
if (this.caughtEntity != null)
{
this.motionX = 0.0D;
this.motionY = 0.0D;
this.motionZ = 0.0D;
this.currentState = EntityFishHook.State.HOOKED_IN_ENTITY;
return;
}
if (f > 0.0F)
{
this.motionX *= 0.3D;
this.motionY *= 0.2D;
this.motionZ *= 0.3D;
this.currentState = EntityFishHook.State.BOBBING;
return;
}
if (!this.world.isRemote)
{
this.checkCollision();
}
if (!this.inGround && !this.onGround && !this.collidedHorizontally)
{
++this.ticksInAir;
}
else
{
this.ticksInAir = 0;
this.motionX = 0.0D;
this.motionY = 0.0D;
this.motionZ = 0.0D;
}
}
else
{
if (this.currentState == EntityFishHook.State.HOOKED_IN_ENTITY)
{
if (this.caughtEntity != null)
{
if (this.caughtEntity.isDead)
{
this.caughtEntity = null;
this.currentState = EntityFishHook.State.FLYING;
}
else
{
this.posX = this.caughtEntity.posX;
double d2 = (double)this.caughtEntity.height;
this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D;
this.posZ = this.caughtEntity.posZ;
this.setPosition(this.posX, this.posY, this.posZ);
}
}
return;
}
if (this.currentState == EntityFishHook.State.BOBBING)
{
this.motionX *= 0.9D;
this.motionZ *= 0.9D;
double d0 = this.posY + this.motionY - (double)blockpos.getY() - (double)f;
if (Math.abs(d0) < 0.01D)
{
d0 += Math.signum(d0) * 0.1D;
}
this.motionY -= d0 * (double)this.rand.nextFloat() * 0.2D;
if (!this.world.isRemote && f > 0.0F)
{
this.catchingFish(blockpos);
}
}
}
if (iblockstate.getMaterial() != Material.WATER)
{
this.motionY -= 0.03D;
}
this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
this.updateRotation();
double d1 = 0.92D;
this.motionX *= 0.92D;
this.motionY *= 0.92D;
this.motionZ *= 0.92D;
this.setPosition(this.posX, this.posY, this.posZ);
}
}
private boolean shouldStopFishing()
{
ItemStack itemstack = this.angler.getHeldItemMainhand();
ItemStack itemstack1 = this.angler.getHeldItemOffhand();
boolean flag = itemstack.getItem() instanceof net.minecraft.item.ItemFishingRod;
boolean flag1 = itemstack1.getItem() instanceof net.minecraft.item.ItemFishingRod;
if (!this.angler.isDead && this.angler.isEntityAlive() && (flag || flag1) && this.getDistanceSq(this.angler) <= 1024.0D)
{
return false;
}
else
{
this.setDead();
return true;
}
}
private void updateRotation()
{
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
{
;
}
while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
{
this.prevRotationPitch += 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw < -180.0F)
{
this.prevRotationYaw -= 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
{
this.prevRotationYaw += 360.0F;
}
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
}
private void checkCollision()
{
Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1, false, true, false);
vec3d = new Vec3d(this.posX, this.posY, this.posZ);
vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (raytraceresult != null)
{
vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
}
Entity entity = null;
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
double d0 = 0.0D;
for (Entity entity1 : list)
{
if (this.canBeHooked(entity1) && (entity1 != this.angler || this.ticksInAir >= 5))
{
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
RayTraceResult raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
if (raytraceresult1 != null)
{
double d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec);
if (d1 < d0 || d0 == 0.0D)
{
entity = entity1;
d0 = d1;
}
}
}
}
if (entity != null)
{
raytraceresult = new RayTraceResult(entity);
}
if (raytraceresult != null && raytraceresult.typeOfHit != RayTraceResult.Type.MISS)
{
if (raytraceresult.typeOfHit == RayTraceResult.Type.ENTITY)
{
this.caughtEntity = raytraceresult.entityHit;
this.setHookedEntity();
}
else
{
this.inGround = true;
}
}
}
private void setHookedEntity()
{
this.getDataManager().set(DATA_HOOKED_ENTITY, Integer.valueOf(this.caughtEntity.getEntityId() + 1));
}
private void catchingFish(BlockPos p_190621_1_)
{
WorldServer worldserver = (WorldServer)this.world;
int i = 1;
BlockPos blockpos = p_190621_1_.up();
if (this.rand.nextFloat() < 0.25F && this.world.isRainingAt(blockpos))
{
++i;
}
if (this.rand.nextFloat() < 0.5F && !this.world.canSeeSky(blockpos))
{
--i;
}
if (this.ticksCatchable > 0)
{
--this.ticksCatchable;
if (this.ticksCatchable <= 0)
{
this.ticksCaughtDelay = 0;
this.ticksCatchableDelay = 0;
}
else
{
this.motionY -= 0.2D * (double)this.rand.nextFloat() * (double)this.rand.nextFloat();
}
}
else if (this.ticksCatchableDelay > 0)
{
this.ticksCatchableDelay -= i;
if (this.ticksCatchableDelay > 0)
{
this.fishApproachAngle = (float)((double)this.fishApproachAngle + this.rand.nextGaussian() * 4.0D);
float f = this.fishApproachAngle * 0.017453292F;
float f1 = MathHelper.sin(f);
float f2 = MathHelper.cos(f);
double d0 = this.posX + (double)(f1 * (float)this.ticksCatchableDelay * 0.1F);
double d1 = (double)((float)MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F);
double d2 = this.posZ + (double)(f2 * (float)this.ticksCatchableDelay * 0.1F);
IBlockState state = worldserver.getBlockState(new BlockPos(d0, d1 - 1.0D, d2));
if (state.getMaterial() == Material.WATER)
{
if (this.rand.nextFloat() < 0.15F)
{
worldserver.spawnParticle(EnumParticleTypes.WATER_BUBBLE, d0, d1 - 0.10000000149011612D, d2, 1, (double)f1, 0.1D, (double)f2, 0.0D);
}
float f3 = f1 * 0.04F;
float f4 = f2 * 0.04F;
worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, d0, d1, d2, 0, (double)f4, 0.01D, (double)(-f3), 1.0D);
worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, d0, d1, d2, 0, (double)(-f4), 0.01D, (double)f3, 1.0D);
}
}
else
{
this.motionY = (double)(-0.4F * MathHelper.nextFloat(this.rand, 0.6F, 1.0F));
this.playSound(SoundEvents.ENTITY_BOBBER_SPLASH, 0.25F, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);
double d3 = this.getEntityBoundingBox().minY + 0.5D;
worldserver.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX, d3, this.posZ, (int)(1.0F + this.width * 20.0F), (double)this.width, 0.0D, (double)this.width, 0.20000000298023224D);
worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, this.posX, d3, this.posZ, (int)(1.0F + this.width * 20.0F), (double)this.width, 0.0D, (double)this.width, 0.20000000298023224D);
this.ticksCatchable = MathHelper.getInt(this.rand, 20, 40);
}
}
else if (this.ticksCaughtDelay > 0)
{
this.ticksCaughtDelay -= i;
float f5 = 0.15F;
if (this.ticksCaughtDelay < 20)
{
f5 = (float)((double)f5 + (double)(20 - this.ticksCaughtDelay) * 0.05D);
}
else if (this.ticksCaughtDelay < 40)
{
f5 = (float)((double)f5 + (double)(40 - this.ticksCaughtDelay) * 0.02D);
}
else if (this.ticksCaughtDelay < 60)
{
f5 = (float)((double)f5 + (double)(60 - this.ticksCaughtDelay) * 0.01D);
}
if (this.rand.nextFloat() < f5)
{
float f6 = MathHelper.nextFloat(this.rand, 0.0F, 360.0F) * 0.017453292F;
float f7 = MathHelper.nextFloat(this.rand, 25.0F, 60.0F);
double d4 = this.posX + (double)(MathHelper.sin(f6) * f7 * 0.1F);
double d5 = (double)((float)MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F);
double d6 = this.posZ + (double)(MathHelper.cos(f6) * f7 * 0.1F);
IBlockState state = worldserver.getBlockState(new BlockPos((int) d4, (int) d5 - 1, (int) d6));
if (state.getMaterial() == Material.WATER)
{
worldserver.spawnParticle(EnumParticleTypes.WATER_SPLASH, d4, d5, d6, 2 + this.rand.nextInt(2), 0.10000000149011612D, 0.0D, 0.10000000149011612D, 0.0D);
}
}
if (this.ticksCaughtDelay <= 0)
{
this.fishApproachAngle = MathHelper.nextFloat(this.rand, 0.0F, 360.0F);
this.ticksCatchableDelay = MathHelper.getInt(this.rand, 20, 80);
}
}
else
{
this.ticksCaughtDelay = MathHelper.getInt(this.rand, 100, 600);
this.ticksCaughtDelay -= this.lureSpeed * 20 * 5;
}
}
protected boolean canBeHooked(Entity p_189739_1_)
{
return p_189739_1_.canBeCollidedWith() || p_189739_1_ instanceof EntityItem;
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
}
public int handleHookRetraction()
{
if (!this.world.isRemote && this.angler != null)
{
int i = 0;
net.minecraftforge.event.entity.player.ItemFishedEvent event = null;
if (this.caughtEntity != null)
{
this.bringInHookedEntity();
this.world.setEntityState(this, (byte)31);
i = this.caughtEntity instanceof EntityItem ? 3 : 5;
}
else if (this.ticksCatchable > 0)
{
LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer)this.world);
lootcontext$builder.withLuck((float)this.luck + this.angler.getLuck()).withPlayer(this.angler).withLootedEntity(this); // Forge: add player & looted entity to LootContext
List<ItemStack> result = this.world.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING).generateLootForPools(this.rand, lootcontext$builder.build());
event = new net.minecraftforge.event.entity.player.ItemFishedEvent(result, this.inGround ? 2 : 1, this);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled())
{
this.setDead();
return event.getRodDamage();
}
for (ItemStack itemstack : result)
{
EntityItem entityitem = new EntityItem(this.world, this.posX, this.posY, this.posZ, itemstack);
double d0 = this.angler.posX - this.posX;
double d1 = this.angler.posY - this.posY;
double d2 = this.angler.posZ - this.posZ;
double d3 = (double)MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
double d4 = 0.1D;
entityitem.motionX = d0 * 0.1D;
entityitem.motionY = d1 * 0.1D + (double)MathHelper.sqrt(d3) * 0.08D;
entityitem.motionZ = d2 * 0.1D;
this.world.spawnEntity(entityitem);
this.angler.world.spawnEntity(new EntityXPOrb(this.angler.world, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, this.rand.nextInt(6) + 1));
Item item = itemstack.getItem();
if (item == Items.FISH || item == Items.COOKED_FISH)
{
this.angler.addStat(StatList.FISH_CAUGHT, 1);
}
}
i = 1;
}
if (this.inGround)
{
i = 2;
}
this.setDead();
return event == null ? i : event.getRodDamage();
}
else
{
return 0;
}
}
/**
* Handler for {@link World#setEntityState}
*/
@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id)
{
if (id == 31 && this.world.isRemote && this.caughtEntity instanceof EntityPlayer && ((EntityPlayer)this.caughtEntity).isUser())
{
this.bringInHookedEntity();
}
super.handleStatusUpdate(id);
}
protected void bringInHookedEntity()
{
if (this.angler != null)
{
double d0 = this.angler.posX - this.posX;
double d1 = this.angler.posY - this.posY;
double d2 = this.angler.posZ - this.posZ;
double d3 = 0.1D;
this.caughtEntity.motionX += d0 * 0.1D;
this.caughtEntity.motionY += d1 * 0.1D;
this.caughtEntity.motionZ += d2 * 0.1D;
}
}
/**
* 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;
}
/**
* Will get destroyed next tick.
*/
public void setDead()
{
super.setDead();
if (this.angler != null)
{
this.angler.fishEntity = null;
}
}
public EntityPlayer getAngler()
{
return this.angler;
}
static enum State
{
FLYING,
HOOKED_IN_ENTITY,
BOBBING;
}
}

View File

@@ -0,0 +1,78 @@
package net.minecraft.entity.projectile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityLargeFireball extends EntityFireball
{
public int explosionPower = 1;
public EntityLargeFireball(World worldIn)
{
super(worldIn);
}
@SideOnly(Side.CLIENT)
public EntityLargeFireball(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
{
super(worldIn, x, y, z, accelX, accelY, accelZ);
}
public EntityLargeFireball(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ)
{
super(worldIn, shooter, accelX, accelY, accelZ);
}
/**
* Called when this EntityFireball hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (!this.world.isRemote)
{
if (result.entityHit != null)
{
result.entityHit.attackEntityFrom(DamageSource.causeFireballDamage(this, this.shootingEntity), 6.0F);
this.applyEnchantments(this.shootingEntity, result.entityHit);
}
boolean flag = net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this.shootingEntity);
this.world.newExplosion((Entity)null, this.posX, this.posY, this.posZ, (float)this.explosionPower, flag, flag);
this.setDead();
}
}
public static void registerFixesLargeFireball(DataFixer fixer)
{
EntityFireball.registerFixesFireball(fixer, "Fireball");
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
compound.setInteger("ExplosionPower", this.explosionPower);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
if (compound.hasKey("ExplosionPower", 99))
{
this.explosionPower = compound.getInteger("ExplosionPower");
}
}
}

View File

@@ -0,0 +1,281 @@
package net.minecraft.entity.projectile;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.passive.EntityLlama;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityLlamaSpit extends Entity implements IProjectile
{
public EntityLlama owner;
private NBTTagCompound ownerNbt;
public EntityLlamaSpit(World worldIn)
{
super(worldIn);
}
public EntityLlamaSpit(World worldIn, EntityLlama p_i47273_2_)
{
super(worldIn);
this.owner = p_i47273_2_;
this.setPosition(p_i47273_2_.posX - (double)(p_i47273_2_.width + 1.0F) * 0.5D * (double)MathHelper.sin(p_i47273_2_.renderYawOffset * 0.017453292F), p_i47273_2_.posY + (double)p_i47273_2_.getEyeHeight() - 0.10000000149011612D, p_i47273_2_.posZ + (double)(p_i47273_2_.width + 1.0F) * 0.5D * (double)MathHelper.cos(p_i47273_2_.renderYawOffset * 0.017453292F));
this.setSize(0.25F, 0.25F);
}
@SideOnly(Side.CLIENT)
public EntityLlamaSpit(World worldIn, double x, double y, double z, double p_i47274_8_, double p_i47274_10_, double p_i47274_12_)
{
super(worldIn);
this.setPosition(x, y, z);
for (int i = 0; i < 7; ++i)
{
double d0 = 0.4D + 0.1D * (double)i;
worldIn.spawnParticle(EnumParticleTypes.SPIT, x, y, z, p_i47274_8_ * d0, p_i47274_10_, p_i47274_12_ * d0);
}
this.motionX = p_i47274_8_;
this.motionY = p_i47274_10_;
this.motionZ = p_i47274_12_;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.ownerNbt != null)
{
this.restoreOwnerFromSave();
}
Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1);
vec3d = new Vec3d(this.posX, this.posY, this.posZ);
vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (raytraceresult != null)
{
vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
}
Entity entity = this.getHitEntity(vec3d, vec3d1);
if (entity != null)
{
raytraceresult = new RayTraceResult(entity);
}
if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult))
{
this.onHit(raytraceresult);
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
{
;
}
while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
{
this.prevRotationPitch += 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw < -180.0F)
{
this.prevRotationYaw -= 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
{
this.prevRotationYaw += 360.0F;
}
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
float f1 = 0.99F;
float f2 = 0.06F;
if (!this.world.isMaterialInBB(this.getEntityBoundingBox(), Material.AIR))
{
this.setDead();
}
else if (this.isInWater())
{
this.setDead();
}
else
{
this.motionX *= 0.9900000095367432D;
this.motionY *= 0.9900000095367432D;
this.motionZ *= 0.9900000095367432D;
if (!this.hasNoGravity())
{
this.motionY -= 0.05999999865889549D;
}
this.setPosition(this.posX, this.posY, this.posZ);
}
}
/**
* Updates the entity motion clientside, called by packets from the server
*/
@SideOnly(Side.CLIENT)
public void setVelocity(double x, double y, double z)
{
this.motionX = x;
this.motionY = y;
this.motionZ = z;
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
{
float f = MathHelper.sqrt(x * x + z * z);
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
}
}
@Nullable
private Entity getHitEntity(Vec3d p_190538_1_, Vec3d p_190538_2_)
{
Entity entity = null;
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
double d0 = 0.0D;
for (Entity entity1 : list)
{
if (entity1 != this.owner)
{
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(p_190538_1_, p_190538_2_);
if (raytraceresult != null)
{
double d1 = p_190538_1_.squareDistanceTo(raytraceresult.hitVec);
if (d1 < d0 || d0 == 0.0D)
{
entity = entity1;
d0 = d1;
}
}
}
}
return entity;
}
/**
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
*/
public void shoot(double x, double y, double z, float velocity, float inaccuracy)
{
float f = MathHelper.sqrt(x * x + y * y + z * z);
x = x / (double)f;
y = y / (double)f;
z = z / (double)f;
x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
z = z + this.rand.nextGaussian() * 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 = MathHelper.sqrt(x * x + z * z);
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
}
public void onHit(RayTraceResult p_190536_1_)
{
if (p_190536_1_.entityHit != null && this.owner != null)
{
p_190536_1_.entityHit.attackEntityFrom(DamageSource.causeIndirectDamage(this, this.owner).setProjectile(), 1.0F);
}
if (!this.world.isRemote)
{
this.setDead();
}
}
protected void entityInit()
{
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
protected void readEntityFromNBT(NBTTagCompound compound)
{
if (compound.hasKey("Owner", 10))
{
this.ownerNbt = compound.getCompoundTag("Owner");
}
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
protected void writeEntityToNBT(NBTTagCompound compound)
{
if (this.owner != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
UUID uuid = this.owner.getUniqueID();
nbttagcompound.setUniqueId("OwnerUUID", uuid);
compound.setTag("Owner", nbttagcompound);
}
}
private void restoreOwnerFromSave()
{
if (this.ownerNbt != null && this.ownerNbt.hasUniqueId("OwnerUUID"))
{
UUID uuid = this.ownerNbt.getUniqueId("OwnerUUID");
for (EntityLlama entityllama : this.world.getEntitiesWithinAABB(EntityLlama.class, this.getEntityBoundingBox().grow(15.0D)))
{
if (entityllama.getUniqueID().equals(uuid))
{
this.owner = entityllama;
break;
}
}
}
this.ownerNbt = null;
}
}

View File

@@ -0,0 +1,296 @@
package net.minecraft.entity.projectile;
import com.google.common.base.Predicate;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.entity.EntityAreaEffectCloud;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.PotionTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionType;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackData;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class EntityPotion extends EntityThrowable
{
private static final DataParameter<ItemStack> ITEM = EntityDataManager.<ItemStack>createKey(EntityPotion.class, DataSerializers.ITEM_STACK);
private static final Logger LOGGER = LogManager.getLogger();
public static final Predicate<EntityLivingBase> WATER_SENSITIVE = new Predicate<EntityLivingBase>()
{
public boolean apply(@Nullable EntityLivingBase p_apply_1_)
{
return EntityPotion.isWaterSensitiveEntity(p_apply_1_);
}
};
public EntityPotion(World worldIn)
{
super(worldIn);
}
public EntityPotion(World worldIn, EntityLivingBase throwerIn, ItemStack potionDamageIn)
{
super(worldIn, throwerIn);
this.setItem(potionDamageIn);
}
public EntityPotion(World worldIn, double x, double y, double z, ItemStack potionDamageIn)
{
super(worldIn, x, y, z);
if (!potionDamageIn.isEmpty())
{
this.setItem(potionDamageIn);
}
}
protected void entityInit()
{
this.getDataManager().register(ITEM, ItemStack.EMPTY);
}
public ItemStack getPotion()
{
ItemStack itemstack = (ItemStack)this.getDataManager().get(ITEM);
if (itemstack.getItem() != Items.SPLASH_POTION && itemstack.getItem() != Items.LINGERING_POTION)
{
if (this.world != null)
{
LOGGER.error("ThrownPotion entity {} has no item?!", (int)this.getEntityId());
}
return new ItemStack(Items.SPLASH_POTION);
}
else
{
return itemstack;
}
}
public void setItem(ItemStack stack)
{
this.getDataManager().set(ITEM, stack);
this.getDataManager().setDirty(ITEM);
}
/**
* Gets the amount of gravity to apply to the thrown entity with each tick.
*/
protected float getGravityVelocity()
{
return 0.05F;
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (!this.world.isRemote)
{
ItemStack itemstack = this.getPotion();
PotionType potiontype = PotionUtils.getPotionFromItem(itemstack);
List<PotionEffect> list = PotionUtils.getEffectsFromStack(itemstack);
boolean flag = potiontype == PotionTypes.WATER && list.isEmpty();
if (result.typeOfHit == RayTraceResult.Type.BLOCK && flag)
{
BlockPos blockpos = result.getBlockPos().offset(result.sideHit);
this.extinguishFires(blockpos, result.sideHit);
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
this.extinguishFires(blockpos.offset(enumfacing), enumfacing);
}
}
if (flag)
{
this.applyWater();
}
else if (!list.isEmpty())
{
if (this.isLingering())
{
this.makeAreaOfEffectCloud(itemstack, potiontype);
}
else
{
this.applySplash(result, list);
}
}
int i = potiontype.hasInstantEffect() ? 2007 : 2002;
this.world.playEvent(i, new BlockPos(this), PotionUtils.getColor(itemstack));
this.setDead();
}
}
private void applyWater()
{
AxisAlignedBB axisalignedbb = this.getEntityBoundingBox().grow(4.0D, 2.0D, 4.0D);
List<EntityLivingBase> list = this.world.<EntityLivingBase>getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb, WATER_SENSITIVE);
if (!list.isEmpty())
{
for (EntityLivingBase entitylivingbase : list)
{
double d0 = this.getDistanceSq(entitylivingbase);
if (d0 < 16.0D && isWaterSensitiveEntity(entitylivingbase))
{
entitylivingbase.attackEntityFrom(DamageSource.DROWN, 1.0F);
}
}
}
}
private void applySplash(RayTraceResult p_190543_1_, List<PotionEffect> p_190543_2_)
{
AxisAlignedBB axisalignedbb = this.getEntityBoundingBox().grow(4.0D, 2.0D, 4.0D);
List<EntityLivingBase> list = this.world.<EntityLivingBase>getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
if (!list.isEmpty())
{
for (EntityLivingBase entitylivingbase : list)
{
if (entitylivingbase.canBeHitWithPotion())
{
double d0 = this.getDistanceSq(entitylivingbase);
if (d0 < 16.0D)
{
double d1 = 1.0D - Math.sqrt(d0) / 4.0D;
if (entitylivingbase == p_190543_1_.entityHit)
{
d1 = 1.0D;
}
for (PotionEffect potioneffect : p_190543_2_)
{
Potion potion = potioneffect.getPotion();
if (potion.isInstant())
{
potion.affectEntity(this, this.getThrower(), entitylivingbase, potioneffect.getAmplifier(), d1);
}
else
{
int i = (int)(d1 * (double)potioneffect.getDuration() + 0.5D);
if (i > 20)
{
entitylivingbase.addPotionEffect(new PotionEffect(potion, i, potioneffect.getAmplifier(), potioneffect.getIsAmbient(), potioneffect.doesShowParticles()));
}
}
}
}
}
}
}
}
private void makeAreaOfEffectCloud(ItemStack p_190542_1_, PotionType p_190542_2_)
{
EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.world, this.posX, this.posY, this.posZ);
entityareaeffectcloud.setOwner(this.getThrower());
entityareaeffectcloud.setRadius(3.0F);
entityareaeffectcloud.setRadiusOnUse(-0.5F);
entityareaeffectcloud.setWaitTime(10);
entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius() / (float)entityareaeffectcloud.getDuration());
entityareaeffectcloud.setPotion(p_190542_2_);
for (PotionEffect potioneffect : PotionUtils.getFullEffectsFromItem(p_190542_1_))
{
entityareaeffectcloud.addEffect(new PotionEffect(potioneffect));
}
NBTTagCompound nbttagcompound = p_190542_1_.getTagCompound();
if (nbttagcompound != null && nbttagcompound.hasKey("CustomPotionColor", 99))
{
entityareaeffectcloud.setColor(nbttagcompound.getInteger("CustomPotionColor"));
}
this.world.spawnEntity(entityareaeffectcloud);
}
private boolean isLingering()
{
return this.getPotion().getItem() == Items.LINGERING_POTION;
}
private void extinguishFires(BlockPos pos, EnumFacing p_184542_2_)
{
if (this.world.getBlockState(pos).getBlock() == Blocks.FIRE)
{
this.world.extinguishFire((EntityPlayer)null, pos.offset(p_184542_2_), p_184542_2_.getOpposite());
}
}
public static void registerFixesPotion(DataFixer fixer)
{
EntityThrowable.registerFixesThrowable(fixer, "ThrownPotion");
fixer.registerWalker(FixTypes.ENTITY, new ItemStackData(EntityPotion.class, new String[] {"Potion"}));
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
ItemStack itemstack = new ItemStack(compound.getCompoundTag("Potion"));
if (itemstack.isEmpty())
{
this.setDead();
}
else
{
this.setItem(itemstack);
}
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
ItemStack itemstack = this.getPotion();
if (!itemstack.isEmpty())
{
compound.setTag("Potion", itemstack.writeToNBT(new NBTTagCompound()));
}
}
private static boolean isWaterSensitiveEntity(EntityLivingBase p_190544_0_)
{
return p_190544_0_ instanceof EntityEnderman || p_190544_0_ instanceof EntityBlaze;
}
}

View File

@@ -0,0 +1,448 @@
package net.minecraft.entity.projectile;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityShulkerBullet extends Entity
{
private EntityLivingBase owner;
private Entity target;
@Nullable
private EnumFacing direction;
private int steps;
private double targetDeltaX;
private double targetDeltaY;
private double targetDeltaZ;
@Nullable
private UUID ownerUniqueId;
private BlockPos ownerBlockPos;
@Nullable
private UUID targetUniqueId;
private BlockPos targetBlockPos;
public EntityShulkerBullet(World worldIn)
{
super(worldIn);
this.setSize(0.3125F, 0.3125F);
this.noClip = true;
}
public SoundCategory getSoundCategory()
{
return SoundCategory.HOSTILE;
}
@SideOnly(Side.CLIENT)
public EntityShulkerBullet(World worldIn, double x, double y, double z, double motionXIn, double motionYIn, double motionZIn)
{
this(worldIn);
this.setLocationAndAngles(x, y, z, this.rotationYaw, this.rotationPitch);
this.motionX = motionXIn;
this.motionY = motionYIn;
this.motionZ = motionZIn;
}
public EntityShulkerBullet(World worldIn, EntityLivingBase ownerIn, Entity targetIn, EnumFacing.Axis p_i46772_4_)
{
this(worldIn);
this.owner = ownerIn;
BlockPos blockpos = new BlockPos(ownerIn);
double d0 = (double)blockpos.getX() + 0.5D;
double d1 = (double)blockpos.getY() + 0.5D;
double d2 = (double)blockpos.getZ() + 0.5D;
this.setLocationAndAngles(d0, d1, d2, this.rotationYaw, this.rotationPitch);
this.target = targetIn;
this.direction = EnumFacing.UP;
this.selectNextMoveDirection(p_i46772_4_);
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
protected void writeEntityToNBT(NBTTagCompound compound)
{
if (this.owner != null)
{
BlockPos blockpos = new BlockPos(this.owner);
NBTTagCompound nbttagcompound = NBTUtil.createUUIDTag(this.owner.getUniqueID());
nbttagcompound.setInteger("X", blockpos.getX());
nbttagcompound.setInteger("Y", blockpos.getY());
nbttagcompound.setInteger("Z", blockpos.getZ());
compound.setTag("Owner", nbttagcompound);
}
if (this.target != null)
{
BlockPos blockpos1 = new BlockPos(this.target);
NBTTagCompound nbttagcompound1 = NBTUtil.createUUIDTag(this.target.getUniqueID());
nbttagcompound1.setInteger("X", blockpos1.getX());
nbttagcompound1.setInteger("Y", blockpos1.getY());
nbttagcompound1.setInteger("Z", blockpos1.getZ());
compound.setTag("Target", nbttagcompound1);
}
if (this.direction != null)
{
compound.setInteger("Dir", this.direction.getIndex());
}
compound.setInteger("Steps", this.steps);
compound.setDouble("TXD", this.targetDeltaX);
compound.setDouble("TYD", this.targetDeltaY);
compound.setDouble("TZD", this.targetDeltaZ);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
protected void readEntityFromNBT(NBTTagCompound compound)
{
this.steps = compound.getInteger("Steps");
this.targetDeltaX = compound.getDouble("TXD");
this.targetDeltaY = compound.getDouble("TYD");
this.targetDeltaZ = compound.getDouble("TZD");
if (compound.hasKey("Dir", 99))
{
this.direction = EnumFacing.getFront(compound.getInteger("Dir"));
}
if (compound.hasKey("Owner", 10))
{
NBTTagCompound nbttagcompound = compound.getCompoundTag("Owner");
this.ownerUniqueId = NBTUtil.getUUIDFromTag(nbttagcompound);
this.ownerBlockPos = new BlockPos(nbttagcompound.getInteger("X"), nbttagcompound.getInteger("Y"), nbttagcompound.getInteger("Z"));
}
if (compound.hasKey("Target", 10))
{
NBTTagCompound nbttagcompound1 = compound.getCompoundTag("Target");
this.targetUniqueId = NBTUtil.getUUIDFromTag(nbttagcompound1);
this.targetBlockPos = new BlockPos(nbttagcompound1.getInteger("X"), nbttagcompound1.getInteger("Y"), nbttagcompound1.getInteger("Z"));
}
}
protected void entityInit()
{
}
private void setDirection(@Nullable EnumFacing directionIn)
{
this.direction = directionIn;
}
private void selectNextMoveDirection(@Nullable EnumFacing.Axis p_184569_1_)
{
double d0 = 0.5D;
BlockPos blockpos;
if (this.target == null)
{
blockpos = (new BlockPos(this)).down();
}
else
{
d0 = (double)this.target.height * 0.5D;
blockpos = new BlockPos(this.target.posX, this.target.posY + d0, this.target.posZ);
}
double d1 = (double)blockpos.getX() + 0.5D;
double d2 = (double)blockpos.getY() + d0;
double d3 = (double)blockpos.getZ() + 0.5D;
EnumFacing enumfacing = null;
if (blockpos.distanceSqToCenter(this.posX, this.posY, this.posZ) >= 4.0D)
{
BlockPos blockpos1 = new BlockPos(this);
List<EnumFacing> list = Lists.<EnumFacing>newArrayList();
if (p_184569_1_ != EnumFacing.Axis.X)
{
if (blockpos1.getX() < blockpos.getX() && this.world.isAirBlock(blockpos1.east()))
{
list.add(EnumFacing.EAST);
}
else if (blockpos1.getX() > blockpos.getX() && this.world.isAirBlock(blockpos1.west()))
{
list.add(EnumFacing.WEST);
}
}
if (p_184569_1_ != EnumFacing.Axis.Y)
{
if (blockpos1.getY() < blockpos.getY() && this.world.isAirBlock(blockpos1.up()))
{
list.add(EnumFacing.UP);
}
else if (blockpos1.getY() > blockpos.getY() && this.world.isAirBlock(blockpos1.down()))
{
list.add(EnumFacing.DOWN);
}
}
if (p_184569_1_ != EnumFacing.Axis.Z)
{
if (blockpos1.getZ() < blockpos.getZ() && this.world.isAirBlock(blockpos1.south()))
{
list.add(EnumFacing.SOUTH);
}
else if (blockpos1.getZ() > blockpos.getZ() && this.world.isAirBlock(blockpos1.north()))
{
list.add(EnumFacing.NORTH);
}
}
enumfacing = EnumFacing.random(this.rand);
if (list.isEmpty())
{
for (int i = 5; !this.world.isAirBlock(blockpos1.offset(enumfacing)) && i > 0; --i)
{
enumfacing = EnumFacing.random(this.rand);
}
}
else
{
enumfacing = list.get(this.rand.nextInt(list.size()));
}
d1 = this.posX + (double)enumfacing.getFrontOffsetX();
d2 = this.posY + (double)enumfacing.getFrontOffsetY();
d3 = this.posZ + (double)enumfacing.getFrontOffsetZ();
}
this.setDirection(enumfacing);
double d6 = d1 - this.posX;
double d7 = d2 - this.posY;
double d4 = d3 - this.posZ;
double d5 = (double)MathHelper.sqrt(d6 * d6 + d7 * d7 + d4 * d4);
if (d5 == 0.0D)
{
this.targetDeltaX = 0.0D;
this.targetDeltaY = 0.0D;
this.targetDeltaZ = 0.0D;
}
else
{
this.targetDeltaX = d6 / d5 * 0.15D;
this.targetDeltaY = d7 / d5 * 0.15D;
this.targetDeltaZ = d4 / d5 * 0.15D;
}
this.isAirBorne = true;
this.steps = 10 + this.rand.nextInt(5) * 10;
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
if (!this.world.isRemote && this.world.getDifficulty() == EnumDifficulty.PEACEFUL)
{
this.setDead();
}
else
{
super.onUpdate();
if (!this.world.isRemote)
{
if (this.target == null && this.targetUniqueId != null)
{
for (EntityLivingBase entitylivingbase : this.world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(this.targetBlockPos.add(-2, -2, -2), this.targetBlockPos.add(2, 2, 2))))
{
if (entitylivingbase.getUniqueID().equals(this.targetUniqueId))
{
this.target = entitylivingbase;
break;
}
}
this.targetUniqueId = null;
}
if (this.owner == null && this.ownerUniqueId != null)
{
for (EntityLivingBase entitylivingbase1 : this.world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(this.ownerBlockPos.add(-2, -2, -2), this.ownerBlockPos.add(2, 2, 2))))
{
if (entitylivingbase1.getUniqueID().equals(this.ownerUniqueId))
{
this.owner = entitylivingbase1;
break;
}
}
this.ownerUniqueId = null;
}
if (this.target == null || !this.target.isEntityAlive() || this.target instanceof EntityPlayer && ((EntityPlayer)this.target).isSpectator())
{
if (!this.hasNoGravity())
{
this.motionY -= 0.04D;
}
}
else
{
this.targetDeltaX = MathHelper.clamp(this.targetDeltaX * 1.025D, -1.0D, 1.0D);
this.targetDeltaY = MathHelper.clamp(this.targetDeltaY * 1.025D, -1.0D, 1.0D);
this.targetDeltaZ = MathHelper.clamp(this.targetDeltaZ * 1.025D, -1.0D, 1.0D);
this.motionX += (this.targetDeltaX - this.motionX) * 0.2D;
this.motionY += (this.targetDeltaY - this.motionY) * 0.2D;
this.motionZ += (this.targetDeltaZ - this.motionZ) * 0.2D;
}
RayTraceResult raytraceresult = ProjectileHelper.forwardsRaycast(this, true, false, this.owner);
if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult))
{
this.bulletHit(raytraceresult);
}
}
this.setPosition(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
ProjectileHelper.rotateTowardsMovement(this, 0.5F);
if (this.world.isRemote)
{
this.world.spawnParticle(EnumParticleTypes.END_ROD, this.posX - this.motionX, this.posY - this.motionY + 0.15D, this.posZ - this.motionZ, 0.0D, 0.0D, 0.0D);
}
else if (this.target != null && !this.target.isDead)
{
if (this.steps > 0)
{
--this.steps;
if (this.steps == 0)
{
this.selectNextMoveDirection(this.direction == null ? null : this.direction.getAxis());
}
}
if (this.direction != null)
{
BlockPos blockpos = new BlockPos(this);
EnumFacing.Axis enumfacing$axis = this.direction.getAxis();
if (this.world.isBlockNormalCube(blockpos.offset(this.direction), false))
{
this.selectNextMoveDirection(enumfacing$axis);
}
else
{
BlockPos blockpos1 = new BlockPos(this.target);
if (enumfacing$axis == EnumFacing.Axis.X && blockpos.getX() == blockpos1.getX() || enumfacing$axis == EnumFacing.Axis.Z && blockpos.getZ() == blockpos1.getZ() || enumfacing$axis == EnumFacing.Axis.Y && blockpos.getY() == blockpos1.getY())
{
this.selectNextMoveDirection(enumfacing$axis);
}
}
}
}
}
}
/**
* Returns true if the entity is on fire. Used by render to add the fire effect on rendering.
*/
public boolean isBurning()
{
return false;
}
/**
* Checks if the entity is in range to render.
*/
@SideOnly(Side.CLIENT)
public boolean isInRangeToRenderDist(double distance)
{
return distance < 16384.0D;
}
/**
* Gets how bright this entity is.
*/
public float getBrightness()
{
return 1.0F;
}
@SideOnly(Side.CLIENT)
public int getBrightnessForRender()
{
return 15728880;
}
protected void bulletHit(RayTraceResult result)
{
if (result.entityHit == null)
{
((WorldServer)this.world).spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.posX, this.posY, this.posZ, 2, 0.2D, 0.2D, 0.2D, 0.0D);
this.playSound(SoundEvents.ENTITY_SHULKER_BULLET_HIT, 1.0F, 1.0F);
}
else
{
boolean flag = result.entityHit.attackEntityFrom(DamageSource.causeIndirectDamage(this, this.owner).setProjectile(), 4.0F);
if (flag)
{
this.applyEnchantments(this.owner, result.entityHit);
if (result.entityHit instanceof EntityLivingBase)
{
((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.LEVITATION, 200));
}
}
}
this.setDead();
}
/**
* Returns true if other Entities should be prevented from moving through this Entity.
*/
public boolean canBeCollidedWith()
{
return true;
}
/**
* Called when the entity is attacked.
*/
public boolean attackEntityFrom(DamageSource source, float amount)
{
if (!this.world.isRemote)
{
this.playSound(SoundEvents.ENTITY_SHULKER_BULLET_HURT, 1.0F, 1.0F);
((WorldServer)this.world).spawnParticle(EnumParticleTypes.CRIT, this.posX, this.posY, this.posZ, 15, 0.2D, 0.2D, 0.2D, 0.0D);
this.setDead();
}
return true;
}
}

View File

@@ -0,0 +1,96 @@
package net.minecraft.entity.projectile;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.util.DamageSource;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class EntitySmallFireball extends EntityFireball
{
public EntitySmallFireball(World worldIn)
{
super(worldIn);
this.setSize(0.3125F, 0.3125F);
}
public EntitySmallFireball(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ)
{
super(worldIn, shooter, accelX, accelY, accelZ);
this.setSize(0.3125F, 0.3125F);
}
public EntitySmallFireball(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
{
super(worldIn, x, y, z, accelX, accelY, accelZ);
this.setSize(0.3125F, 0.3125F);
}
public static void registerFixesSmallFireball(DataFixer fixer)
{
EntityFireball.registerFixesFireball(fixer, "SmallFireball");
}
/**
* Called when this EntityFireball hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (!this.world.isRemote)
{
if (result.entityHit != null)
{
if (!result.entityHit.isImmuneToFire())
{
boolean flag = result.entityHit.attackEntityFrom(DamageSource.causeFireballDamage(this, this.shootingEntity), 5.0F);
if (flag)
{
this.applyEnchantments(this.shootingEntity, result.entityHit);
result.entityHit.setFire(5);
}
}
}
else
{
boolean flag1 = true;
if (this.shootingEntity != null && this.shootingEntity instanceof EntityLiving)
{
flag1 = net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this.shootingEntity);
}
if (flag1)
{
BlockPos blockpos = result.getBlockPos().offset(result.sideHit);
if (this.world.isAirBlock(blockpos))
{
this.world.setBlockState(blockpos, Blocks.FIRE.getDefaultState());
}
}
}
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, float amount)
{
return false;
}
}

View File

@@ -0,0 +1,73 @@
package net.minecraft.entity.projectile;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntitySnowball extends EntityThrowable
{
public EntitySnowball(World worldIn)
{
super(worldIn);
}
public EntitySnowball(World worldIn, EntityLivingBase throwerIn)
{
super(worldIn, throwerIn);
}
public EntitySnowball(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
public static void registerFixesSnowball(DataFixer fixer)
{
EntityThrowable.registerFixesThrowable(fixer, "Snowball");
}
/**
* Handler for {@link World#setEntityState}
*/
@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id)
{
if (id == 3)
{
for (int i = 0; i < 8; ++i)
{
this.world.spawnParticle(EnumParticleTypes.SNOWBALL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
}
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (result.entityHit != null)
{
int i = 0;
if (result.entityHit instanceof EntityBlaze)
{
i = 3;
}
result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
}
if (!this.world.isRemote)
{
this.world.setEntityState(this, (byte)3);
this.setDead();
}
}
}

View File

@@ -0,0 +1,83 @@
package net.minecraft.entity.projectile;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.world.World;
public class EntitySpectralArrow extends EntityArrow
{
private int duration = 200;
public EntitySpectralArrow(World worldIn)
{
super(worldIn);
}
public EntitySpectralArrow(World worldIn, EntityLivingBase shooter)
{
super(worldIn, shooter);
}
public EntitySpectralArrow(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.world.isRemote && !this.inGround)
{
this.world.spawnParticle(EnumParticleTypes.SPELL_INSTANT, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
}
protected ItemStack getArrowStack()
{
return new ItemStack(Items.SPECTRAL_ARROW);
}
protected void arrowHit(EntityLivingBase living)
{
super.arrowHit(living);
PotionEffect potioneffect = new PotionEffect(MobEffects.GLOWING, this.duration, 0);
living.addPotionEffect(potioneffect);
}
public static void registerFixesSpectralArrow(DataFixer fixer)
{
EntityArrow.registerFixesArrow(fixer, "SpectralArrow");
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
if (compound.hasKey("Duration"))
{
this.duration = compound.getInteger("Duration");
}
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
compound.setInteger("Duration", this.duration);
}
}

View File

@@ -0,0 +1,419 @@
package net.minecraft.entity.projectile;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class EntityThrowable extends Entity implements IProjectile
{
private int xTile;
private int yTile;
private int zTile;
private Block inTile;
protected boolean inGround;
public int throwableShake;
/** The entity that threw this throwable item. */
protected EntityLivingBase thrower;
private String throwerName;
private int ticksInGround;
private int ticksInAir;
public Entity ignoreEntity;
private int ignoreTime;
public EntityThrowable(World worldIn)
{
super(worldIn);
this.xTile = -1;
this.yTile = -1;
this.zTile = -1;
this.setSize(0.25F, 0.25F);
}
public EntityThrowable(World worldIn, double x, double y, double z)
{
this(worldIn);
this.setPosition(x, y, z);
}
public EntityThrowable(World worldIn, EntityLivingBase throwerIn)
{
this(worldIn, throwerIn.posX, throwerIn.posY + (double)throwerIn.getEyeHeight() - 0.10000000149011612D, throwerIn.posZ);
this.thrower = throwerIn;
}
protected void entityInit()
{
}
/**
* Checks if the entity is in range to render.
*/
@SideOnly(Side.CLIENT)
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;
}
/**
* Sets throwable heading based on an entity that's throwing it
*/
public void shoot(Entity entityThrower, float rotationPitchIn, float rotationYawIn, float pitchOffset, float velocity, float inaccuracy)
{
float f = -MathHelper.sin(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F);
float f1 = -MathHelper.sin((rotationPitchIn + pitchOffset) * 0.017453292F);
float f2 = MathHelper.cos(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F);
this.shoot((double)f, (double)f1, (double)f2, velocity, inaccuracy);
this.motionX += entityThrower.motionX;
this.motionZ += entityThrower.motionZ;
if (!entityThrower.onGround)
{
this.motionY += entityThrower.motionY;
}
}
/**
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
*/
public void shoot(double x, double y, double z, float velocity, float inaccuracy)
{
float f = MathHelper.sqrt(x * x + y * y + z * z);
x = x / (double)f;
y = y / (double)f;
z = z / (double)f;
x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
z = z + this.rand.nextGaussian() * 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 = MathHelper.sqrt(x * x + z * z);
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
this.ticksInGround = 0;
}
/**
* Updates the entity motion clientside, called by packets from the server
*/
@SideOnly(Side.CLIENT)
public void setVelocity(double x, double y, double z)
{
this.motionX = x;
this.motionY = y;
this.motionZ = z;
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
{
float f = MathHelper.sqrt(x * x + z * z);
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
this.lastTickPosX = this.posX;
this.lastTickPosY = this.posY;
this.lastTickPosZ = this.posZ;
super.onUpdate();
if (this.throwableShake > 0)
{
--this.throwableShake;
}
if (this.inGround)
{
if (this.world.getBlockState(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.nextFloat() * 0.2F);
this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
this.ticksInGround = 0;
this.ticksInAir = 0;
}
else
{
++this.ticksInAir;
}
Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ);
Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1);
vec3d = new Vec3d(this.posX, this.posY, this.posZ);
vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
if (raytraceresult != null)
{
vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
}
Entity entity = null;
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D));
double d0 = 0.0D;
boolean flag = false;
for (int i = 0; i < list.size(); ++i)
{
Entity entity1 = list.get(i);
if (entity1.canBeCollidedWith())
{
if (entity1 == this.ignoreEntity)
{
flag = true;
}
else if (this.thrower != null && this.ticksExisted < 2 && this.ignoreEntity == null)
{
this.ignoreEntity = entity1;
flag = true;
}
else
{
flag = false;
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
RayTraceResult raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
if (raytraceresult1 != null)
{
double d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec);
if (d1 < d0 || d0 == 0.0D)
{
entity = entity1;
d0 = d1;
}
}
}
}
}
if (this.ignoreEntity != null)
{
if (flag)
{
this.ignoreTime = 2;
}
else if (this.ignoreTime-- <= 0)
{
this.ignoreEntity = null;
}
}
if (entity != null)
{
raytraceresult = new RayTraceResult(entity);
}
if (raytraceresult != null)
{
if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && this.world.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.PORTAL)
{
this.setPortal(raytraceresult.getBlockPos());
}
else if (!net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult))
{
this.onImpact(raytraceresult);
}
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
{
;
}
while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
{
this.prevRotationPitch += 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw < -180.0F)
{
this.prevRotationYaw -= 360.0F;
}
while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
{
this.prevRotationYaw += 360.0F;
}
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
float f1 = 0.99F;
float f2 = this.getGravityVelocity();
if (this.isInWater())
{
for (int j = 0; j < 4; ++j)
{
float f3 = 0.25F;
this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ);
}
f1 = 0.8F;
}
this.motionX *= (double)f1;
this.motionY *= (double)f1;
this.motionZ *= (double)f1;
if (!this.hasNoGravity())
{
this.motionY -= (double)f2;
}
this.setPosition(this.posX, this.posY, this.posZ);
}
/**
* Gets the amount of gravity to apply to the thrown entity with each tick.
*/
protected float getGravityVelocity()
{
return 0.03F;
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected abstract void onImpact(RayTraceResult result);
public static void registerFixesThrowable(DataFixer fixer, String name)
{
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
compound.setInteger("xTile", this.xTile);
compound.setInteger("yTile", this.yTile);
compound.setInteger("zTile", this.zTile);
ResourceLocation resourcelocation = Block.REGISTRY.getNameForObject(this.inTile);
compound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
compound.setByte("shake", (byte)this.throwableShake);
compound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
if ((this.throwerName == null || this.throwerName.isEmpty()) && this.thrower instanceof EntityPlayer)
{
this.throwerName = this.thrower.getName();
}
compound.setString("ownerName", this.throwerName == null ? "" : this.throwerName);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
this.xTile = compound.getInteger("xTile");
this.yTile = compound.getInteger("yTile");
this.zTile = compound.getInteger("zTile");
if (compound.hasKey("inTile", 8))
{
this.inTile = Block.getBlockFromName(compound.getString("inTile"));
}
else
{
this.inTile = Block.getBlockById(compound.getByte("inTile") & 255);
}
this.throwableShake = compound.getByte("shake") & 255;
this.inGround = compound.getByte("inGround") == 1;
this.thrower = null;
this.throwerName = compound.getString("ownerName");
if (this.throwerName != null && this.throwerName.isEmpty())
{
this.throwerName = null;
}
this.thrower = this.getThrower();
}
@Nullable
public EntityLivingBase getThrower()
{
if (this.thrower == null && this.throwerName != null && !this.throwerName.isEmpty())
{
this.thrower = this.world.getPlayerEntityByName(this.throwerName);
if (this.thrower == null && this.world instanceof WorldServer)
{
try
{
Entity entity = ((WorldServer)this.world).getEntityFromUuid(UUID.fromString(this.throwerName));
if (entity instanceof EntityLivingBase)
{
this.thrower = (EntityLivingBase)entity;
}
}
catch (Throwable var2)
{
this.thrower = null;
}
}
}
return this.thrower;
}
}

View File

@@ -0,0 +1,299 @@
package net.minecraft.entity.projectile;
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Set;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Items;
import net.minecraft.init.PotionTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionType;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityTippedArrow extends EntityArrow
{
private static final DataParameter<Integer> COLOR = EntityDataManager.<Integer>createKey(EntityTippedArrow.class, DataSerializers.VARINT);
private PotionType potion = PotionTypes.EMPTY;
private final Set<PotionEffect> customPotionEffects = Sets.<PotionEffect>newHashSet();
private boolean fixedColor;
public EntityTippedArrow(World worldIn)
{
super(worldIn);
}
public EntityTippedArrow(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
public EntityTippedArrow(World worldIn, EntityLivingBase shooter)
{
super(worldIn, shooter);
}
public void setPotionEffect(ItemStack stack)
{
if (stack.getItem() == Items.TIPPED_ARROW)
{
this.potion = PotionUtils.getPotionFromItem(stack);
Collection<PotionEffect> collection = PotionUtils.getFullEffectsFromItem(stack);
if (!collection.isEmpty())
{
for (PotionEffect potioneffect : collection)
{
this.customPotionEffects.add(new PotionEffect(potioneffect));
}
}
int i = getCustomColor(stack);
if (i == -1)
{
this.refreshColor();
}
else
{
this.setFixedColor(i);
}
}
else if (stack.getItem() == Items.ARROW)
{
this.potion = PotionTypes.EMPTY;
this.customPotionEffects.clear();
this.dataManager.set(COLOR, Integer.valueOf(-1));
}
}
public static int getCustomColor(ItemStack p_191508_0_)
{
NBTTagCompound nbttagcompound = p_191508_0_.getTagCompound();
return nbttagcompound != null && nbttagcompound.hasKey("CustomPotionColor", 99) ? nbttagcompound.getInteger("CustomPotionColor") : -1;
}
private void refreshColor()
{
this.fixedColor = false;
this.dataManager.set(COLOR, Integer.valueOf(PotionUtils.getPotionColorFromEffectList(PotionUtils.mergeEffects(this.potion, this.customPotionEffects))));
}
public void addEffect(PotionEffect effect)
{
this.customPotionEffects.add(effect);
this.getDataManager().set(COLOR, Integer.valueOf(PotionUtils.getPotionColorFromEffectList(PotionUtils.mergeEffects(this.potion, this.customPotionEffects))));
}
protected void entityInit()
{
super.entityInit();
this.dataManager.register(COLOR, Integer.valueOf(-1));
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate()
{
super.onUpdate();
if (this.world.isRemote)
{
if (this.inGround)
{
if (this.timeInGround % 5 == 0)
{
this.spawnPotionParticles(1);
}
}
else
{
this.spawnPotionParticles(2);
}
}
else if (this.inGround && this.timeInGround != 0 && !this.customPotionEffects.isEmpty() && this.timeInGround >= 600)
{
this.world.setEntityState(this, (byte)0);
this.potion = PotionTypes.EMPTY;
this.customPotionEffects.clear();
this.dataManager.set(COLOR, Integer.valueOf(-1));
}
}
private void spawnPotionParticles(int particleCount)
{
int i = this.getColor();
if (i != -1 && particleCount > 0)
{
double d0 = (double)(i >> 16 & 255) / 255.0D;
double d1 = (double)(i >> 8 & 255) / 255.0D;
double d2 = (double)(i >> 0 & 255) / 255.0D;
for (int j = 0; j < particleCount; ++j)
{
this.world.spawnParticle(EnumParticleTypes.SPELL_MOB, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, d0, d1, d2);
}
}
}
public int getColor()
{
return ((Integer)this.dataManager.get(COLOR)).intValue();
}
private void setFixedColor(int p_191507_1_)
{
this.fixedColor = true;
this.dataManager.set(COLOR, Integer.valueOf(p_191507_1_));
}
public static void registerFixesTippedArrow(DataFixer fixer)
{
EntityArrow.registerFixesArrow(fixer, "TippedArrow");
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
if (this.potion != PotionTypes.EMPTY && this.potion != null)
{
compound.setString("Potion", ((ResourceLocation)PotionType.REGISTRY.getNameForObject(this.potion)).toString());
}
if (this.fixedColor)
{
compound.setInteger("Color", this.getColor());
}
if (!this.customPotionEffects.isEmpty())
{
NBTTagList nbttaglist = new NBTTagList();
for (PotionEffect potioneffect : this.customPotionEffects)
{
nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
}
compound.setTag("CustomPotionEffects", nbttaglist);
}
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
if (compound.hasKey("Potion", 8))
{
this.potion = PotionUtils.getPotionTypeFromNBT(compound);
}
for (PotionEffect potioneffect : PotionUtils.getFullEffectsFromTag(compound))
{
this.addEffect(potioneffect);
}
if (compound.hasKey("Color", 99))
{
this.setFixedColor(compound.getInteger("Color"));
}
else
{
this.refreshColor();
}
}
protected void arrowHit(EntityLivingBase living)
{
super.arrowHit(living);
for (PotionEffect potioneffect : this.potion.getEffects())
{
living.addPotionEffect(new PotionEffect(potioneffect.getPotion(), Math.max(potioneffect.getDuration() / 8, 1), potioneffect.getAmplifier(), potioneffect.getIsAmbient(), potioneffect.doesShowParticles()));
}
if (!this.customPotionEffects.isEmpty())
{
for (PotionEffect potioneffect1 : this.customPotionEffects)
{
living.addPotionEffect(potioneffect1);
}
}
}
protected ItemStack getArrowStack()
{
if (this.customPotionEffects.isEmpty() && this.potion == PotionTypes.EMPTY)
{
return new ItemStack(Items.ARROW);
}
else
{
ItemStack itemstack = new ItemStack(Items.TIPPED_ARROW);
PotionUtils.addPotionToItemStack(itemstack, this.potion);
PotionUtils.appendEffects(itemstack, this.customPotionEffects);
if (this.fixedColor)
{
NBTTagCompound nbttagcompound = itemstack.getTagCompound();
if (nbttagcompound == null)
{
nbttagcompound = new NBTTagCompound();
itemstack.setTagCompound(nbttagcompound);
}
nbttagcompound.setInteger("CustomPotionColor", this.getColor());
}
return itemstack;
}
}
/**
* Handler for {@link World#setEntityState}
*/
@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id)
{
if (id == 0)
{
int i = this.getColor();
if (i != -1)
{
double d0 = (double)(i >> 16 & 255) / 255.0D;
double d1 = (double)(i >> 8 & 255) / 255.0D;
double d2 = (double)(i >> 0 & 255) / 255.0D;
for (int j = 0; j < 20; ++j)
{
this.world.spawnParticle(EnumParticleTypes.SPELL_MOB, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, d0, d1, d2);
}
}
}
else
{
super.handleStatusUpdate(id);
}
}
}

View File

@@ -0,0 +1,176 @@
package net.minecraft.entity.projectile;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.init.MobEffects;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityWitherSkull extends EntityFireball
{
private static final DataParameter<Boolean> INVULNERABLE = EntityDataManager.<Boolean>createKey(EntityWitherSkull.class, DataSerializers.BOOLEAN);
public EntityWitherSkull(World worldIn)
{
super(worldIn);
this.setSize(0.3125F, 0.3125F);
}
public EntityWitherSkull(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ)
{
super(worldIn, shooter, accelX, accelY, accelZ);
this.setSize(0.3125F, 0.3125F);
}
public static void registerFixesWitherSkull(DataFixer fixer)
{
EntityFireball.registerFixesFireball(fixer, "WitherSkull");
}
/**
* Return the motion factor for this projectile. The factor is multiplied by the original motion.
*/
protected float getMotionFactor()
{
return this.isInvulnerable() ? 0.73F : super.getMotionFactor();
}
@SideOnly(Side.CLIENT)
public EntityWitherSkull(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ)
{
super(worldIn, x, y, z, accelX, accelY, accelZ);
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() && block.canEntityDestroy(blockStateIn, worldIn, pos, this) && net.minecraftforge.event.ForgeEventFactory.onEntityDestroyBlock(this.shootingEntity, pos, blockStateIn))
{
f = Math.min(0.8F, f);
}
return f;
}
/**
* Called when this EntityFireball hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (!this.world.isRemote)
{
if (result.entityHit != null)
{
if (this.shootingEntity != null)
{
if (result.entityHit.attackEntityFrom(DamageSource.causeMobDamage(this.shootingEntity), 8.0F))
{
if (result.entityHit.isEntityAlive())
{
this.applyEnchantments(this.shootingEntity, result.entityHit);
}
else
{
this.shootingEntity.heal(5.0F);
}
}
}
else
{
result.entityHit.attackEntityFrom(DamageSource.MAGIC, 5.0F);
}
if (result.entityHit instanceof EntityLivingBase)
{
int i = 0;
if (this.world.getDifficulty() == EnumDifficulty.NORMAL)
{
i = 10;
}
else if (this.world.getDifficulty() == EnumDifficulty.HARD)
{
i = 40;
}
if (i > 0)
{
((EntityLivingBase)result.entityHit).addPotionEffect(new PotionEffect(MobEffects.WITHER, 20 * i, 1));
}
}
}
this.world.newExplosion(this, this.posX, this.posY, this.posZ, 1.0F, false, net.minecraftforge.event.ForgeEventFactory.getMobGriefingEvent(this.world, this.shootingEntity));
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, float amount)
{
return false;
}
protected void entityInit()
{
this.dataManager.register(INVULNERABLE, Boolean.valueOf(false));
}
/**
* Return whether this skull comes from an invulnerable (aura) wither boss.
*/
public boolean isInvulnerable()
{
return ((Boolean)this.dataManager.get(INVULNERABLE)).booleanValue();
}
/**
* Set whether this skull comes from an invulnerable (aura) wither boss.
*/
public void setInvulnerable(boolean invulnerable)
{
this.dataManager.set(INVULNERABLE, Boolean.valueOf(invulnerable));
}
protected boolean isFireballFiery()
{
return false;
}
}

View File

@@ -0,0 +1,99 @@
package net.minecraft.entity.projectile;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public final class ProjectileHelper
{
public static RayTraceResult forwardsRaycast(Entity projectile, boolean includeEntities, boolean ignoreExcludedEntity, Entity excludedEntity)
{
double d0 = projectile.posX;
double d1 = projectile.posY;
double d2 = projectile.posZ;
double d3 = projectile.motionX;
double d4 = projectile.motionY;
double d5 = projectile.motionZ;
World world = projectile.world;
Vec3d vec3d = new Vec3d(d0, d1, d2);
Vec3d vec3d1 = new Vec3d(d0 + d3, d1 + d4, d2 + d5);
RayTraceResult raytraceresult = world.rayTraceBlocks(vec3d, vec3d1, false, true, false);
if (includeEntities)
{
if (raytraceresult != null)
{
vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z);
}
Entity entity = null;
List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(projectile, projectile.getEntityBoundingBox().expand(d3, d4, d5).grow(1.0D));
double d6 = 0.0D;
for (int i = 0; i < list.size(); ++i)
{
Entity entity1 = list.get(i);
if (entity1.canBeCollidedWith() && (ignoreExcludedEntity || !entity1.isEntityEqual(excludedEntity)) && !entity1.noClip)
{
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D);
RayTraceResult raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
if (raytraceresult1 != null)
{
double d7 = vec3d.squareDistanceTo(raytraceresult1.hitVec);
if (d7 < d6 || d6 == 0.0D)
{
entity = entity1;
d6 = d7;
}
}
}
}
if (entity != null)
{
raytraceresult = new RayTraceResult(entity);
}
}
return raytraceresult;
}
public static final void rotateTowardsMovement(Entity projectile, float rotationSpeed)
{
double d0 = projectile.motionX;
double d1 = projectile.motionY;
double d2 = projectile.motionZ;
float f = MathHelper.sqrt(d0 * d0 + d2 * d2);
projectile.rotationYaw = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) + 90.0F;
for (projectile.rotationPitch = (float)(MathHelper.atan2((double)f, d1) * (180D / Math.PI)) - 90.0F; projectile.rotationPitch - projectile.prevRotationPitch < -180.0F; projectile.prevRotationPitch -= 360.0F)
{
;
}
while (projectile.rotationPitch - projectile.prevRotationPitch >= 180.0F)
{
projectile.prevRotationPitch += 360.0F;
}
while (projectile.rotationYaw - projectile.prevRotationYaw < -180.0F)
{
projectile.prevRotationYaw -= 360.0F;
}
while (projectile.rotationYaw - projectile.prevRotationYaw >= 180.0F)
{
projectile.prevRotationYaw += 360.0F;
}
projectile.rotationPitch = projectile.prevRotationPitch + (projectile.rotationPitch - projectile.prevRotationPitch) * rotationSpeed;
projectile.rotationYaw = projectile.prevRotationYaw + (projectile.rotationYaw - projectile.prevRotationYaw) * rotationSpeed;
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.entity.projectile;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;