Attack pixies!

This commit is contained in:
Vasco Lavos committed 2014-06-19 23:07:53 +01:00
1 parent a045c8fdd5
commit 32f03fb3a6
8 files changed
+97 -49

No files matched your search

@@ -1,9 +1,58 @@
package vazkii.botania.common.core.handler;
import vazkii.botania.common.entity.EntityPixie;
import vazkii.botania.common.item.ModItems;
import baubles.common.container.InventoryBaubles;
import baubles.common.lib.PlayerHandler;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class PixieHandler {
@SubscribeEvent
public void onDamageTaken(LivingHurtEvent event) {
if(!event.entityLiving.worldObj.isRemote && event.entityLiving instanceof EntityPlayer && event.source.getEntity() != null && event.source.getEntity() instanceof EntityLivingBase) {
EntityPlayer player = (EntityPlayer) event.entityLiving;
ItemStack stack = player.getCurrentEquippedItem();
float chance = getChance(stack);
for(int i = 0; i < player.inventory.armorInventory.length; i++)
chance += getChance(player.inventory.armorInventory[i]);
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
for(int i = 0; i < baubles.getSizeInventory(); i++)
chance += getChance(baubles.getStackInSlot(i));
System.out.println(chance);
if(Math.random() < chance) {
EntityPixie pixie = new EntityPixie(player.worldObj);
pixie.setPosition(player.posX, player.posY + 2, player.posZ);
float dmg = 4;
if(stack != null && stack.getItem() == ModItems.elementiumSword)
dmg += 2;
pixie.setProps((EntityLivingBase) event.source.getEntity(), player, dmg);
player.worldObj.spawnEntityInWorld(pixie);
}
}
}
float getChance(ItemStack stack) {
if(stack == null)
return 0F;
Item item = stack.getItem();
if(item instanceof IPixieSpawner)
return ((IPixieSpawner) item).getPixieChance(stack);
return 0F;
}
public static interface IPixieSpawner {
public float getPixieChance(ItemStack stack);
@@ -27,6 +27,7 @@ import vazkii.botania.common.core.handler.CommonTickHandler;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.core.handler.InternalMethodHandler;
import vazkii.botania.common.core.handler.ManaNetworkHandler;
import vazkii.botania.common.core.handler.PixieHandler;
import vazkii.botania.common.core.helper.Vector3;
import vazkii.botania.common.core.version.CommandDownloadLatest;
import vazkii.botania.common.crafting.ModCrafingRecipes;
@@ -73,6 +74,7 @@ public class CommonProxy {
MinecraftForge.TERRAIN_GEN_BUS.register(new BiomeDecorationHandler());
MinecraftForge.EVENT_BUS.register(ManaNetworkHandler.instance);
MinecraftForge.EVENT_BUS.register(new PixieHandler());
FMLCommonHandler.instance().bus().register(new CommonTickHandler());
}
@@ -12,78 +12,75 @@
package vazkii.botania.common.entity;
import vazkii.botania.common.Botania;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
public class EntityPixie extends EntityFlyingCreature {
public int courseChangeCooldown;
public double waypointX;
public double waypointY;
public double waypointZ;
EntityPlayer player = null;
float damage = 0;
public EntityPixie(World world) {
super(world);
setSize(1.0F, 1.0F);
}
public void setProps(EntityLivingBase target, EntityPlayer player, float damage) {
setAttackTarget(target);
this.player = player;
this.damage = damage;
}
@Override
protected void updateEntityActionState() {
double d0 = waypointX - posX;
double d1 = waypointY - posY;
double d2 = waypointZ - posZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
EntityLivingBase target = getAttackTarget();
System.out.println(target);
if(target != null) {
double d0 = target.posX + target.width / 2 - posX;
double d1 = target.posY + target.height / 2 - posY;
double d2 = target.posZ + target.width / 2 - posZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
if(d3 < 1.0D || d3 > 3600.0D) {
waypointX = posX + (double)((rand.nextFloat() * 4.0F - 2.0F) * 2.0F);
waypointY = posY + (double)((rand.nextFloat() * 4.0F - 2.0F) * 2.0F);
waypointZ = posZ + (double)((rand.nextFloat() * 4.0F - 2.0F) * 2.0F);
}
float mod = 0.45F;
motionX += d0 / d3 * mod;
motionY += d1 / d3 * mod;
motionZ += d2 / d3 * mod;
if(courseChangeCooldown-- <= 0) {
courseChangeCooldown += rand.nextInt(2) + 2;
d3 = (double)MathHelper.sqrt_double(d3);
if(isCourseTraversable(waypointX, waypointY, waypointZ, d3)) {
motionX += d0 / d3 * 0.1D;
motionY += d1 / d3 * 0.1D;
motionZ += d2 / d3 * 0.1D;
} else {
waypointX = posX;
waypointY = posY;
waypointZ = posZ;
if(Math.sqrt(d3) < 1F) {
if(player != null)
target.attackEntityFrom(DamageSource.causePlayerDamage(player), damage);
else target.attackEntityFrom(DamageSource.causeMobDamage(this), damage);
die();
}
}
renderYawOffset = rotationYaw = -((float)Math.atan2(motionX, motionZ)) * 180.0F / (float)Math.PI;
}
private boolean isCourseTraversable(double par1, double par3, double par5, double par7) {
double d4 = (waypointX - posX) / par7;
double d5 = (waypointY - posY) / par7;
double d6 = (waypointZ - posZ) / par7;
AxisAlignedBB axisalignedbb = boundingBox.copy();
for (int i = 1; (double)i < par7; ++i) {
axisalignedbb.offset(d4, d5, d6);
if (!worldObj.getCollidingBoundingBoxes(this, axisalignedbb).isEmpty())
return false;
}
return true;
}
@Override
public void onEntityUpdate() {
super.onEntityUpdate();
if(ticksExisted > 100)
die();
if(worldObj.isRemote)
for(int i = 0; i < 4; i++)
Botania.proxy.sparkleFX(worldObj, posX + (Math.random() - 0.5) * 0.25, posY + 0.5 + (Math.random() - 0.5) * 0.25, posZ + (Math.random() - 0.5) * 0.25, 1F, 0.25F, 0.9F, 0.1F + (float) Math.random() * 0.25F, 12);
}
public void die() {
setDead();
if(worldObj.isRemote)
for(int i = 0; i < 12; i++)
Botania.proxy.sparkleFX(worldObj, posX + (Math.random() - 0.5) * 0.25, posY + 0.5 + (Math.random() - 0.5) * 0.25, posZ + (Math.random() - 0.5) * 0.25, 1F, 0.25F, 0.9F, 1F + (float) Math.random() * 0.25F, 5);
}
}
@@ -21,7 +21,7 @@ public final class ModEntities {
int id = 0;
EntityRegistry.registerModEntity(EntityManaBurst.class, LibEntityNames.MANA_BURST, id++, Botania.instance, 64, 10, true);
EntityRegistry.registerModEntity(EntitySignalFlare.class, LibEntityNames.SIGNAL_FLARE, id++, Botania.instance, 2048, 10, false);
EntityRegistry.registerModEntity(EntityPixie.class, LibEntityNames.PIXIE, id++, Botania.instance, 80, 3, true);
EntityRegistry.registerModEntity(EntityPixie.class, LibEntityNames.PIXIE, id++, Botania.instance, 16, 3, true);
}
}
@@ -11,7 +11,7 @@ public class ItemElementiumBoots extends ItemElementiumArmor {
@Override
public float getPixieChance(ItemStack stack) {
return 0.041666666666666666666666666666667F;
return 4F / (25F / 24F) * 1.5F;
}
}
@@ -11,7 +11,7 @@ public class ItemElementiumChest extends ItemElementiumArmor {
@Override
public float getPixieChance(ItemStack stack) {
return 0.083333333333333333333333333333336F;
return 8F / (25F / 24F) * 1.5F;
}
}
@@ -11,7 +11,7 @@ public class ItemElementiumHelm extends ItemElementiumArmor {
@Override
public float getPixieChance(ItemStack stack) {
return 0.052083333333333333333333333333335F;
return 5F / (25F / 24F) * 1.5F;
}
}
@@ -11,7 +11,7 @@ public class ItemElementiumLegs extends ItemElementiumArmor {
@Override
public float getPixieChance(ItemStack stack) {
return 0.072916666666666666666666666666669F;
return 7F / (25F / 24F) * 1.5F;
}
}