use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.
the class EntityThrownSickle method setDead.
@Override
public void setDead() {
if (getThrowingEntity() != null && getThrowingEntity() instanceof EntityNatureGuardian) {
((EntityNatureGuardian) getThrowingEntity()).hasSickle = true;
} else if (getThrowingEntity() != null && getThrowingEntity() instanceof EntityPlayer) {
if (!worldObj.isRemote)
if (getThrowingEntity().getHealth() <= 0) {
PlayerTracker.storeSoulboundItemForRespawn((EntityPlayer) getThrowingEntity(), ItemsCommonProxy.natureScytheEnchanted.copy());
} else {
if (!((EntityPlayer) getThrowingEntity()).inventory.addItemStackToInventory(ItemsCommonProxy.natureScytheEnchanted.copy())) {
EntityItem item = new EntityItem(worldObj);
item.setPosition(posX, posY, posZ);
item.setEntityItemStack(ItemsCommonProxy.natureScytheEnchanted.copy());
worldObj.spawnEntityInWorld(item);
}
}
}
super.setDead();
}
use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.
the class EntityWhirlwind method onCollideWithPlayer.
@Override
public void onCollideWithPlayer(EntityPlayer player) {
if (!worldObj.isRemote) {
Integer cd = cooldownList.get(player);
if (cd == null || cd <= 0) {
if (!worldObj.isRemote && rand.nextInt(100) < 10) {
int slot = player.inventory.mainInventory.length + rand.nextInt(4);
if (player.inventory.getStackInSlot(slot) != null) {
ItemStack armorStack = player.inventory.getStackInSlot(slot).copy();
if (!player.inventory.addItemStackToInventory(armorStack)) {
EntityItem item = new EntityItem(worldObj);
item.setPosition(player.posX, player.posY, player.posZ);
item.setVelocity(rand.nextDouble() * 0.2 - 0.1, rand.nextDouble() * 0.2 - 0.1, rand.nextDouble() * 0.2 - 0.1);
worldObj.spawnEntityInWorld(item);
}
player.inventory.setInventorySlotContents(slot, null);
}
}
player.attackEntityFrom(DamageSources.causeEntityWindDamage(this), 2);
float velX = worldObj.rand.nextFloat() * 0.2f;
float veZ = worldObj.rand.nextFloat() * 0.2f;
player.addVelocity(velX, 0.8, veZ);
AMNetHandler.INSTANCE.sendVelocityAddPacket(worldObj, player, velX, 0.8, veZ);
player.fallDistance = 0;
setCooldownFor(player);
}
}
}
use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.
the class EntityAICookNearbyFood method updateTask.
@Override
public void updateTask() {
Entity inanimate = ExtendedProperties.For(entityHost).getInanimateTarget();
double distance = this.entityHost.getDistanceSqToEntity(inanimate);
if (distance > 9D) {
this.entityHost.getNavigator().tryMoveToXYZ(inanimate.posX, inanimate.posY, inanimate.posZ, this.entityHost.getAIMoveSpeed());
} else {
this.entityHost.getNavigator().clearPathEntity();
this.entityHost.getLookHelper().setLookPositionWithEntity(inanimate, 30.0F, 30.0F);
if (timeSpentCooking < 30) {
timeSpentCooking++;
if (entityHost.getDataWatcher().getWatchableObjectInt(19) != inanimate.getEntityId()) {
entityHost.getDataWatcher().updateObject(19, inanimate.getEntityId());
}
} else {
ItemStack smelted = FurnaceRecipes.smelting().getSmeltingResult(((EntityItem) inanimate).getEntityItem());
timeSpentCooking = 0;
ExtendedProperties.For(entityHost).setInanimateTarget(null);
entityHost.getDataWatcher().updateObject(19, 0);
if (smelted != null) {
EntityItem item = new EntityItem(inanimate.worldObj, inanimate.posX, inanimate.posY, inanimate.posZ, new ItemStack(smelted.getItem(), smelted.stackSize));
entityHost.worldObj.spawnEntityInWorld(item);
inanimate.setDead();
}
}
}
}
use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.
the class ParticleApproachEntity method doUpdate.
@Override
public void doUpdate() {
if (target == null) {
this.finish();
return;
}
double posX;
double posZ;
double posY = particle.posY;
double angle;
double distanceToTarget = particle.getDistanceSqToEntity(target);
double deltaZ = target.posZ - particle.posZ;
double deltaX = target.posX - particle.posX;
angle = Math.atan2(deltaZ, deltaX);
double radians = angle;
posX = particle.posX + (approachSpeed * Math.cos(radians));
posZ = particle.posZ + (approachSpeed * Math.sin(radians));
double deltaY;
if (target instanceof EntityLiving) {
EntityLiving entityliving = (EntityLiving) target;
deltaY = posY - (entityliving.posY + entityliving.getEyeHeight());
} else if (target instanceof EntityItem) {
deltaY = posY - target.posY;
} else {
deltaY = (target.boundingBox.minY + target.boundingBox.maxY) / 2D - posY;
}
double horizontalDistance = MathHelper.sqrt_double(deltaX * deltaX + deltaZ * deltaZ);
float pitchRotation = (float) (-Math.atan2(deltaY, horizontalDistance));
double pitchRadians = pitchRotation;
posY = particle.posY - (approachSpeed * Math.sin(pitchRadians));
if (distanceToTarget <= (targetDistance * targetDistance)) {
this.finish();
} else {
particle.setPosition(posX, posY, posZ);
}
}
use of net.minecraft.entity.item.EntityItem in project ConvenientAdditions by Necr0.
the class CABlockContainer method dropItemHandler.
public void dropItemHandler(World world, BlockPos pos, ItemStackHandlerAutoSave handler, boolean clearHandler) {
for (ItemStack item : handler.getStacks()) {
if (item != null) {
float rx = world.rand.nextFloat() * 0.8F + 0.1F;
float ry = world.rand.nextFloat() * 0.8F + 0.1F;
float rz = world.rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, pos.getX() + rx, pos.getY() + ry, pos.getZ() + rz, item);
float factor = 0.05F;
entityItem.motionX = world.rand.nextGaussian() * factor;
entityItem.motionY = world.rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = world.rand.nextGaussian() * factor;
world.spawnEntity(entityItem);
}
}
if (clearHandler)
handler.setStacks(NonNullList.withSize(handler.getSlots(), ItemStack.EMPTY));
}
Aggregations