Moving some spell classes, moved BloodUtils API stuff for books into main code

This commit is contained in:
WayofTime 2014-11-13 08:42:49 -05:00
parent beea2e875a
commit 8c1396421a
169 changed files with 227 additions and 250 deletions

View file

@ -0,0 +1,650 @@
package WayofTime.alchemicalWizardry.api.spell;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class EntitySpellProjectile extends Entity implements IProjectile
{
private int xTile = -1;
private int yTile = -1;
private int zTile = -1;
private int inTile = 0;
private int inData = 0;
private boolean inGround = false;
/**
* The owner of this arrow.
*/
public EntityPlayer shootingEntity;
private int ticksInAir = 0;
private int ricochetCounter = 0;
private boolean scheduledForDeath = false;
private boolean isSilkTouch = false;
//Custom variables
private int maxRicochet = 0;
private float damage = 1;
public List<IProjectileImpactEffect> impactList = new ArrayList();
private boolean penetration = false;
public List<IProjectileUpdateEffect> updateEffectList = new ArrayList();
public List<SpellEffect> spellEffectList = new LinkedList();
private int blocksBroken = 0;
public EntitySpellProjectile(World par1World)
{
super(par1World);
this.setSize(0.5F, 0.5F);
}
public EntitySpellProjectile(World par1World, double par2, double par4, double par6)
{
super(par1World);
this.setSize(0.5F, 0.5F);
this.setPosition(par2, par4, par6);
yOffset = 0.0F;
}
public EntitySpellProjectile(World par1World, EntityPlayer par2EntityPlayer)
{
super(par1World);
shootingEntity = par2EntityPlayer;
float par3 = 0.8F;
this.setSize(0.1F, 0.1F);
this.setLocationAndAngles(par2EntityPlayer.posX, par2EntityPlayer.posY + par2EntityPlayer.getEyeHeight(), par2EntityPlayer.posZ, par2EntityPlayer.rotationYaw, par2EntityPlayer.rotationPitch);
posX -= MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * 0.16F;
posY -= 0.2D;
posZ -= MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * 0.16F;
this.setPosition(posX, posY, posZ);
yOffset = 0.0F;
motionX = -MathHelper.sin(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI);
motionZ = MathHelper.cos(rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(rotationPitch / 180.0F * (float) Math.PI);
motionY = -MathHelper.sin(rotationPitch / 180.0F * (float) Math.PI);
this.setThrowableHeading(motionX, motionY, motionZ, par3 * 1.5F, 1.0F);
}
@Override
protected void entityInit()
{
dataWatcher.addObject(16, Byte.valueOf((byte) 0));
}
/**
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z
* direction.
*/
@Override
public void setThrowableHeading(double var1, double var3, double var5, float var7, float var8)
{
float var9 = MathHelper.sqrt_double(var1 * var1 + var3 * var3 + var5 * var5);
var1 /= var9;
var3 /= var9;
var5 /= var9;
var1 += rand.nextGaussian() * 0.007499999832361937D * var8;
var3 += rand.nextGaussian() * 0.007499999832361937D * var8;
var5 += rand.nextGaussian() * 0.007499999832361937D * var8;
var1 *= var7;
var3 *= var7;
var5 *= var7;
motionX = var1;
motionY = var3;
motionZ = var5;
float var10 = MathHelper.sqrt_double(var1 * var1 + var5 * var5);
prevRotationYaw = rotationYaw = (float) (Math.atan2(var1, var5) * 180.0D / Math.PI);
prevRotationPitch = rotationPitch = (float) (Math.atan2(var3, var10) * 180.0D / Math.PI);
}
@Override
@SideOnly(Side.CLIENT)
/**
* Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,
* posY, posZ, yaw, pitch
*/
public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9)
{
this.setPosition(par1, par3, par5);
this.setRotation(par7, par8);
}
@Override
@SideOnly(Side.CLIENT)
/**
* Sets the velocity to the args. Args: x, y, z
*/
public void setVelocity(double par1, double par3, double par5)
{
motionX = par1;
motionY = par3;
motionZ = par5;
if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
{
float var7 = MathHelper.sqrt_double(par1 * par1 + par5 * par5);
prevRotationYaw = rotationYaw = (float) (Math.atan2(par1, par5) * 180.0D / Math.PI);
prevRotationPitch = rotationPitch = (float) (Math.atan2(par3, var7) * 180.0D / Math.PI);
prevRotationPitch = rotationPitch;
prevRotationYaw = rotationYaw;
this.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch);
}
}
/**
* Called to update the entity's position/logic.
*/
@Override
public void onUpdate()
{
super.onUpdate();
this.performUpdateEffects();
if (ticksInAir > 600)
{
this.setDead();
}
if (shootingEntity == null)
{
List players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(posX - 1, posY - 1, posZ - 1, posX + 1, posY + 1, posZ + 1));
Iterator i = players.iterator();
double closestDistance = Double.MAX_VALUE;
EntityPlayer closestPlayer = null;
while (i.hasNext())
{
EntityPlayer e = (EntityPlayer) i.next();
double distance = e.getDistanceToEntity(this);
if (distance < closestDistance)
{
closestPlayer = e;
}
}
if (closestPlayer != null)
{
shootingEntity = closestPlayer;
}
}
if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
{
float var1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
prevRotationYaw = rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI);
prevRotationPitch = rotationPitch = (float) (Math.atan2(motionY, var1) * 180.0D / Math.PI);
}
Block var16 = worldObj.getBlock(xTile, yTile, zTile);
if (var16 != null)
{
var16.setBlockBoundsBasedOnState(worldObj, xTile, yTile, zTile);
AxisAlignedBB var2 = var16.getCollisionBoundingBoxFromPool(worldObj, xTile, yTile, zTile);
if (var2 != null && var2.isVecInside(Vec3.createVectorHelper(posX, posY, posZ)))
{
inGround = true;
}
}
if (inGround)
{
Block var18 = worldObj.getBlock(xTile, yTile, zTile);
int var19 = worldObj.getBlockMetadata(xTile, yTile, zTile);
if (var18.equals(Block.getBlockById(inTile)) && var19 == inData)
{
// this.groundImpact();
// this.setDead();
}
} else
{
++ticksInAir;
if (ticksInAir > 1 && ticksInAir < 3)
{
//worldObj.spawnParticle("flame", posX + smallGauss(0.1D), posY + smallGauss(0.1D), posZ + smallGauss(0.1D), 0D, 0D, 0D);
for (int particles = 0; particles < 3; particles++)
{
this.doFiringParticles();
}
}
Vec3 var17 = Vec3.createVectorHelper(posX, posY, posZ);
Vec3 var3 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
MovingObjectPosition var4 = worldObj.func_147447_a(var17, var3, true, false, false);
var17 = Vec3.createVectorHelper(posX, posY, posZ);
var3 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
if (var4 != null)
{
var3 = Vec3.createVectorHelper(var4.hitVec.xCoord, var4.hitVec.yCoord, var4.hitVec.zCoord);
}
Entity var5 = null;
List var6 = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
double var7 = 0.0D;
Iterator var9 = var6.iterator();
float var11;
while (var9.hasNext())
{
Entity var10 = (Entity) var9.next();
if (var10.canBeCollidedWith() && (var10 != shootingEntity || ticksInAir >= 5))
{
var11 = 0.3F;
AxisAlignedBB var12 = var10.boundingBox.expand(var11, var11, var11);
MovingObjectPosition var13 = var12.calculateIntercept(var17, var3);
if (var13 != null)
{
double var14 = var17.distanceTo(var13.hitVec);
if (var14 < var7 || var7 == 0.0D)
{
var5 = var10;
var7 = var14;
}
}
}
}
if (var5 != null)
{
var4 = new MovingObjectPosition(var5);
}
if (var4 != null)
{
this.onImpact(var4);
if (scheduledForDeath)
{
this.setDead();
}
}
posX += motionX;
posY += motionY;
posZ += motionZ;
MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
this.setPosition(posX, posY, posZ);
//this.doBlockCollisions();
}
}
private void doFlightParticles()
{
if (ticksInAir % 3 == 0)
{
double gauss = gaussian(1.0F);
worldObj.spawnParticle("mobSpell", posX, posY, posZ, gauss, gauss, 0.0F);
}
}
private void doFiringParticles()
{
worldObj.spawnParticle("mobSpellAmbient", posX + smallGauss(0.1D), posY + smallGauss(0.1D), posZ + smallGauss(0.1D), 0.5D, 0.5D, 0.5D);
worldObj.spawnParticle("flame", posX, posY, posZ, gaussian(motionX), gaussian(motionY), gaussian(motionZ));
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
@Override
public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
{
par1NBTTagCompound.setShort("xTile", (short) xTile);
par1NBTTagCompound.setShort("yTile", (short) yTile);
par1NBTTagCompound.setShort("zTile", (short) zTile);
par1NBTTagCompound.setByte("inTile", (byte) inTile);
par1NBTTagCompound.setByte("inData", (byte) inData);
par1NBTTagCompound.setByte("inGround", (byte) (inGround ? 1 : 0));
NBTTagList effectList = new NBTTagList();
for (SpellEffect eff : spellEffectList)
{
effectList.appendTag(eff.getTag());
}
// for (String str : this.effectList)
// {
// if (str != null)
// {
// NBTTagCompound tag = new NBTTagCompound();
//
// tag.setString("Class", str);
// effectList.appendTag(tag);
// }
// }
par1NBTTagCompound.setTag("Effects", effectList);
par1NBTTagCompound.setInteger("blocksBroken", blocksBroken);
par1NBTTagCompound.setBoolean("isSilkTouch", isSilkTouch);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
@Override
public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
{
xTile = par1NBTTagCompound.getShort("xTile");
yTile = par1NBTTagCompound.getShort("yTile");
zTile = par1NBTTagCompound.getShort("zTile");
inTile = par1NBTTagCompound.getByte("inTile") & 255;
inData = par1NBTTagCompound.getByte("inData") & 255;
inGround = par1NBTTagCompound.getByte("inGround") == 1;
blocksBroken = par1NBTTagCompound.getInteger("blocksBroken");
isSilkTouch = par1NBTTagCompound.getBoolean("isSilkTouch");
NBTTagList tagList = par1NBTTagCompound.getTagList("Effects", Constants.NBT.TAG_COMPOUND);
List<SpellEffect> spellEffectList = new LinkedList();
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
SpellEffect eff = SpellEffect.getEffectFromTag(tag);
if (eff != null)
{
spellEffectList.add(eff);
}
}
this.spellEffectList = spellEffectList;
// this.effectList = new LinkedList();
// for (int i = 0; i < tagList.tagCount(); i++)
// {
// NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
//
// this.effectList.add(tag.getString("Class"));
// }
//SpellParadigmProjectile parad = SpellParadigmProjectile.getParadigmForStringArray(effectList);
SpellParadigmProjectile parad = SpellParadigmProjectile.getParadigmForEffectArray(spellEffectList);
parad.applyAllSpellEffects();
parad.prepareProjectile(this);
}
/**
* returns if this entity triggers Block.onEntityWalking on the blocks they
* walk on. used for spiders and wolves to prevent them from trampling crops
*/
@Override
protected boolean canTriggerWalking()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public float getShadowSize()
{
return 0.0F;
}
/**
* Sets the amount of knockback the arrow applies when it hits a mob.
*/
public void setKnockbackStrength(int par1)
{
}
/**
* If returns false, the item will not inflict any damage against entities.
*/
@Override
public boolean canAttackWithItem()
{
return false;
}
/**
* Whether the arrow has a stream of critical hit particles flying behind
* it.
*/
public void setIsCritical(boolean par1)
{
byte var2 = dataWatcher.getWatchableObjectByte(16);
if (par1)
{
dataWatcher.updateObject(16, Byte.valueOf((byte) (var2 | 1)));
} else
{
dataWatcher.updateObject(16, Byte.valueOf((byte) (var2 & -2)));
}
}
/**
* Whether the arrow has a stream of critical hit particles flying behind
* it.
*/
public boolean getIsCritical()
{
byte var1 = dataWatcher.getWatchableObjectByte(16);
return (var1 & 1) != 0;
}
private void onImpact(MovingObjectPosition mop)
{
if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY && mop.entityHit != null)
{
if (mop.entityHit == shootingEntity) return;
this.onImpact(mop.entityHit);
this.performEntityImpactEffects(mop.entityHit);
} else if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
{
if (!this.penetration)
{
this.groundImpact(mop.sideHit);
this.performTileImpactEffects(mop);
}
}
}
private void onImpact(Entity mop) //TODO
{
if (mop == shootingEntity && ticksInAir > 3)
{
shootingEntity.attackEntityFrom(DamageSource.causePlayerDamage(shootingEntity), 1);
this.setDead();
} else
{
doDamage(this.damage, mop);
}
spawnHitParticles("exorcism", 8);
this.setDead();
}
private void spawnHitParticles(String string, int i)
{
for (int particles = 0; particles < i; particles++)
{
worldObj.spawnParticle("mobSpellAmbient", posX + smallGauss(0.1D), posY + smallGauss(0.1D), posZ + smallGauss(0.1D), posGauss(1.0F), posGauss(1.0F), 0.0F);
}
}
private void doDamage(float f, Entity mop)
{
mop.attackEntityFrom(this.getDamageSource(), f);
}
private DamageSource getDamageSource()
{
return DamageSource.causePlayerDamage(shootingEntity);
}
private void groundImpact(int sideHit)
{
this.ricochet(sideHit);
}
private double smallGauss(double d)
{
return (worldObj.rand.nextFloat() - 0.5D) * d;
}
private double posGauss(double d)
{
return rand.nextFloat() * 0.5D * d;
}
private double gaussian(double d)
{
return d + d * ((rand.nextFloat() - 0.5D) / 4);
}
private void ricochet(int sideHit)
{
switch (sideHit)
{
case 0:
case 1:
// topHit, bottomHit, reflect Y
motionY = motionY * -1;
break;
case 2:
case 3:
// westHit, eastHit, reflect Z
motionZ = motionZ * -1;
break;
case 4:
case 5:
// southHit, northHit, reflect X
motionX = motionX * -1;
break;
}
ricochetCounter++;
if (ricochetCounter > this.getRicochetMax())
{
scheduledForDeath = true;
for (int particles = 0; particles < 4; particles++)
{
switch (sideHit)
{
case 0:
worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), -gaussian(0.1D), gaussian(0.1D));
break;
case 1:
worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), gaussian(0.1D));
break;
case 2:
worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), -gaussian(0.1D));
break;
case 3:
worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), gaussian(0.1D));
break;
case 4:
worldObj.spawnParticle("smoke", posX, posY, posZ, -gaussian(0.1D), gaussian(0.1D), gaussian(0.1D));
break;
case 5:
worldObj.spawnParticle("smoke", posX, posY, posZ, gaussian(0.1D), gaussian(0.1D), gaussian(0.1D));
break;
}
}
}
}
//Custom stuff
public int getRicochetMax()
{
return this.maxRicochet;
}
public void setRicochetMax(int ricochet)
{
this.maxRicochet = ricochet;
}
public void setImpactList(List<IProjectileImpactEffect> list)
{
this.impactList = list;
}
public void setUpdateEffectList(List<IProjectileUpdateEffect> list)
{
this.updateEffectList = list;
}
private void performEntityImpactEffects(Entity mop)
{
if (impactList != null)
{
for (IProjectileImpactEffect impactEffect : impactList)
{
impactEffect.onEntityImpact(mop, this);
}
}
}
private void performTileImpactEffects(MovingObjectPosition mop)
{
if (impactList != null)
{
for (IProjectileImpactEffect impactEffect : impactList)
{
impactEffect.onTileImpact(worldObj, mop);
}
}
}
private void performUpdateEffects()
{
if (updateEffectList != null)
{
for (IProjectileUpdateEffect updateEffect : updateEffectList)
{
updateEffect.onUpdateEffect(this);
}
}
}
public void setPenetration(boolean penetration)
{
this.penetration = penetration;
}
public float getDamage()
{
return this.damage;
}
public void setDamage(float damage)
{
this.damage = damage;
}
public void setSpellEffectList(List<SpellEffect> list)
{
this.spellEffectList = list;
}
public int getBlocksBroken()
{
return this.blocksBroken;
}
public void setBlocksBroken(int blocksBroken)
{
this.blocksBroken = blocksBroken;
}
public boolean getIsSilkTouch()
{
return this.isSilkTouch;
}
public void setIsSilkTouch(boolean bool)
{
this.isSilkTouch = bool;
}
}

View file

@ -0,0 +1,72 @@
package WayofTime.alchemicalWizardry.api.spell;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import java.util.List;
public abstract class ExtrapolatedMeleeEntityEffect implements IMeleeSpellEntityEffect
{
protected float range;
protected float radius;
protected int powerUpgrades;
protected int potencyUpgrades;
protected int costUpgrades;
protected int maxHit;
public ExtrapolatedMeleeEntityEffect(int power, int potency, int cost)
{
this.powerUpgrades = power;
this.potencyUpgrades = potency;
this.costUpgrades = cost;
this.range = 0;
this.radius = 0;
this.maxHit = 1;
}
@Override
public void onEntityImpact(World world, EntityPlayer entityPlayer)
{
Vec3 lookVec = entityPlayer.getLook(range);
double x = entityPlayer.posX + lookVec.xCoord;
double y = entityPlayer.posY + entityPlayer.getEyeHeight() + lookVec.yCoord;
double z = entityPlayer.posZ + lookVec.zCoord;
List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(x - 0.5f, y - 0.5f, z - 0.5f, x + 0.5f, y + 0.5f, z + 0.5f).expand(radius, radius, radius));
int hit = 0;
if (entities != null)
{
for (Entity entity : entities)
{
if (hit < maxHit && !entity.equals(entityPlayer))
{
if (this.entityEffect(world, entity, entityPlayer))
{
hit++;
}
}
}
}
}
protected abstract boolean entityEffect(World world, Entity entity, EntityPlayer player);
public void setRange(float range)
{
this.range = range;
}
public void setRadius(float radius)
{
this.radius = radius;
}
public void setMaxNumberHit(int maxHit)
{
this.maxHit = maxHit;
}
}

View file

@ -0,0 +1,9 @@
package WayofTime.alchemicalWizardry.api.spell;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public interface IMeleeSpellEntityEffect
{
public void onEntityImpact(World world, EntityPlayer entityPlayer);
}

View file

@ -0,0 +1,9 @@
package WayofTime.alchemicalWizardry.api.spell;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public interface IMeleeSpellWorldEffect
{
public void onWorldEffect(World world, EntityPlayer entityPlayer);
}

View file

@ -0,0 +1,12 @@
package WayofTime.alchemicalWizardry.api.spell;
import net.minecraft.entity.Entity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public interface IProjectileImpactEffect
{
public void onEntityImpact(Entity mop, Entity projectile);
public void onTileImpact(World world, MovingObjectPosition mop);
}

View file

@ -0,0 +1,8 @@
package WayofTime.alchemicalWizardry.api.spell;
import net.minecraft.entity.Entity;
public interface IProjectileUpdateEffect
{
public void onUpdateEffect(Entity projectile);
}

View file

@ -0,0 +1,9 @@
package WayofTime.alchemicalWizardry.api.spell;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public interface ISelfSpellEffect
{
public void onSelfUse(World world, EntityPlayer player);
}

View file

@ -0,0 +1,33 @@
package WayofTime.alchemicalWizardry.api.spell;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
public abstract class MeleeSpellCenteredWorldEffect extends MeleeSpellWorldEffect
{
protected float range;
public MeleeSpellCenteredWorldEffect(int power, int potency, int cost)
{
super(power, potency, cost);
}
@Override
public void onWorldEffect(World world, EntityPlayer entityPlayer)
{
Vec3 lookVec = entityPlayer.getLook(range).normalize();
int x = (int) (entityPlayer.posX + lookVec.xCoord * range);
int y = (int) (entityPlayer.posY + entityPlayer.getEyeHeight() + lookVec.yCoord * range);
int z = (int) (entityPlayer.posZ + lookVec.zCoord * range);
this.onCenteredWorldEffect(entityPlayer, world, x, y, z);
}
public void setRange(float range)
{
this.range = range;
}
public abstract void onCenteredWorldEffect(EntityPlayer player, World world, int posX, int posY, int posZ);
}

View file

@ -0,0 +1,21 @@
package WayofTime.alchemicalWizardry.api.spell;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
public abstract class MeleeSpellWorldEffect implements IMeleeSpellWorldEffect
{
protected int powerUpgrades;
protected int potencyUpgrades;
protected int costUpgrades;
public MeleeSpellWorldEffect(int power, int potency, int cost)
{
this.powerUpgrades = power;
this.potencyUpgrades = potency;
this.costUpgrades = cost;
}
@Override
public abstract void onWorldEffect(World world, EntityPlayer entityPlayer);
}

View file

@ -0,0 +1,15 @@
package WayofTime.alchemicalWizardry.api.spell;
public abstract class ProjectileImpactEffect implements IProjectileImpactEffect
{
protected int powerUpgrades;
protected int potencyUpgrades;
protected int costUpgrades;
public ProjectileImpactEffect(int power, int potency, int cost)
{
this.powerUpgrades = power;
this.potencyUpgrades = potency;
this.costUpgrades = cost;
}
}

View file

@ -0,0 +1,15 @@
package WayofTime.alchemicalWizardry.api.spell;
public abstract class ProjectileUpdateEffect implements IProjectileUpdateEffect
{
protected int powerUpgrades;
protected int potencyUpgrades;
protected int costUpgrades;
public ProjectileUpdateEffect(int power, int potency, int cost)
{
this.powerUpgrades = power;
this.potencyUpgrades = potency;
this.costUpgrades = cost;
}
}

View file

@ -0,0 +1,15 @@
package WayofTime.alchemicalWizardry.api.spell;
public abstract class SelfSpellEffect implements ISelfSpellEffect
{
protected int powerUpgrades;
protected int potencyUpgrades;
protected int costUpgrades;
public SelfSpellEffect(int power, int potency, int cost)
{
this.powerUpgrades = power;
this.potencyUpgrades = potency;
this.costUpgrades = cost;
}
}

View file

@ -1,7 +1,6 @@
package WayofTime.alchemicalWizardry.api.spell;
import net.minecraft.nbt.NBTTagCompound;
import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhancement;
/**
* New wrapper class to enclose the ComplexSpellEffect

View file

@ -0,0 +1,20 @@
package WayofTime.alchemicalWizardry.api.spell;
public class SpellEnhancement
{
public static final int POWER = 0;
public static final int EFFICIENCY = 1;
public static final int POTENCY = 2;
private int state = this.POWER;
protected SpellEnhancement(int state)
{
this.state = state;
}
public int getState()
{
return this.state;
}
}

View file

@ -0,0 +1,10 @@
package WayofTime.alchemicalWizardry.api.spell;
public class SpellEnhancementCost extends SpellEnhancement
{
public SpellEnhancementCost()
{
super(SpellEnhancement.EFFICIENCY);
}
}

View file

@ -0,0 +1,10 @@
package WayofTime.alchemicalWizardry.api.spell;
public class SpellEnhancementPotency extends SpellEnhancement
{
public SpellEnhancementPotency()
{
super(SpellEnhancement.POTENCY);
}
}

View file

@ -0,0 +1,10 @@
package WayofTime.alchemicalWizardry.api.spell;
public class SpellEnhancementPower extends SpellEnhancement
{
public SpellEnhancementPower()
{
super(SpellEnhancement.POWER);
}
}

View file

@ -6,7 +6,6 @@ import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhancement;
public abstract class SpellParadigm
{

View file

@ -0,0 +1,70 @@
package WayofTime.alchemicalWizardry.api.spell;
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
public class SpellParadigmMelee extends SpellParadigm
{
private List<IMeleeSpellEntityEffect> entityEffectList;
private List<IMeleeSpellWorldEffect> worldEffectList;
public SpellParadigmMelee()
{
this.entityEffectList = new ArrayList();
this.worldEffectList = new ArrayList();
}
@Override
public void enhanceParadigm(SpellEnhancement enh)
{
}
@Override
public void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack)
{
int cost = this.getTotalCost();
if(!EnergyItems.syphonBatteries(itemStack, entityPlayer, cost))
{
return;
}
for (IMeleeSpellEntityEffect effect : entityEffectList)
{
effect.onEntityImpact(world, entityPlayer);
}
for (IMeleeSpellWorldEffect effect : worldEffectList)
{
effect.onWorldEffect(world, entityPlayer);
}
}
public void addEntityEffect(IMeleeSpellEntityEffect eff)
{
if (eff != null)
{
this.entityEffectList.add(eff);
}
}
public void addWorldEffect(IMeleeSpellWorldEffect eff)
{
if (eff != null)
{
this.worldEffectList.add(eff);
}
}
@Override
public int getDefaultCost()
{
return 0;
}
}

View file

@ -0,0 +1,101 @@
package WayofTime.alchemicalWizardry.api.spell;
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
public class SpellParadigmProjectile extends SpellParadigm
{
public DamageSource damageSource;
public float damage;
public int cost;
public List<IProjectileImpactEffect> impactList;
public List<IProjectileUpdateEffect> updateEffectList;
public boolean penetration;
public int ricochetMax;
public boolean isSilkTouch;
public SpellParadigmProjectile()
{
this.damageSource = DamageSource.generic;
this.damage = 1;
this.cost = 0;
this.impactList = new ArrayList();
this.updateEffectList = new ArrayList();
this.penetration = false;
this.ricochetMax = 0;
this.isSilkTouch = false;
}
@Override
public void enhanceParadigm(SpellEnhancement enh)
{
}
@Override
public void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack)
{
int cost = this.getTotalCost();
if(!EnergyItems.syphonBatteries(itemStack, entityPlayer, cost))
{
return;
}
EntitySpellProjectile proj = new EntitySpellProjectile(world, entityPlayer);
this.prepareProjectile(proj);
world.spawnEntityInWorld(proj);
}
public static SpellParadigmProjectile getParadigmForEffectArray(List<SpellEffect> effectList)
{
SpellParadigmProjectile parad = new SpellParadigmProjectile();
for (SpellEffect eff : effectList)
{
parad.addBufferedEffect(eff);
}
return parad;
}
public void prepareProjectile(EntitySpellProjectile proj)
{
proj.setDamage(damage);
proj.setImpactList(impactList);
proj.setUpdateEffectList(updateEffectList);
proj.setPenetration(penetration);
proj.setRicochetMax(ricochetMax);
proj.setIsSilkTouch(isSilkTouch);
proj.setSpellEffectList(bufferedEffectList);
}
public void addImpactEffect(IProjectileImpactEffect eff)
{
if (eff != null)
{
this.impactList.add(eff);
}
}
public void addUpdateEffect(IProjectileUpdateEffect eff)
{
if (eff != null)
{
this.updateEffectList.add(eff);
}
}
@Override
public int getDefaultCost()
{
return 50;
}
}

View file

@ -0,0 +1,58 @@
package WayofTime.alchemicalWizardry.api.spell;
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
public class SpellParadigmSelf extends SpellParadigm
{
public List<ISelfSpellEffect> selfSpellEffectList;
public SpellParadigmSelf()
{
selfSpellEffectList = new ArrayList();
}
@Override
public void enhanceParadigm(SpellEnhancement enh)
{
}
@Override
public void castSpell(World world, EntityPlayer entityPlayer, ItemStack itemStack)
{
this.applyAllSpellEffects();
int cost = this.getTotalCost();
if(!EnergyItems.syphonBatteries(itemStack, entityPlayer, cost))
{
return;
}
for (ISelfSpellEffect eff : selfSpellEffectList)
{
eff.onSelfUse(world, entityPlayer);
}
}
public void addSelfSpellEffect(ISelfSpellEffect eff)
{
if (eff != null)
{
this.selfSpellEffectList.add(eff);
}
}
@Override
public int getDefaultCost()
{
return 100;
}
}

View file

@ -0,0 +1,485 @@
package WayofTime.alchemicalWizardry.api.spell;
import WayofTime.alchemicalWizardry.ModItems;
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
import WayofTime.alchemicalWizardry.common.items.spell.ItemSpellMultiTool;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.tool.*;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
public class SpellParadigmTool extends SpellParadigm
{
private List<ILeftClickEffect> leftClickEffectList;
private List<IRightClickEffect> rightClickEffectList;
private List<IToolUpdateEffect> toolUpdateEffectList;
private List<IOnSummonTool> toolSummonEffectList;
private List<IOnBanishTool> toolBanishEffectList;
private List<IOnBreakBlock> breakBlockEffectList;
private List<IItemManipulator> itemManipulatorEffectList;
private List<IDigAreaEffect> digAreaEffectList;
private List<ISpecialDamageEffect> specialDamageEffectList;
private float maxDamage;
private HashMap<String, Integer> harvestLevel;
private HashMap<String, Float> digSpeed;
private HashMap<String, Float> maxDamageHash;
private HashMap<String, Float> critChanceHash;
private HashMap<String, Integer> durationHash;
private HashMap<String, String> toolInfoString;
private int fortuneLevel;
private boolean silkTouch;
private int duration;
public SpellParadigmTool()
{
this.leftClickEffectList = new LinkedList();
this.rightClickEffectList = new LinkedList();
this.toolUpdateEffectList = new LinkedList();
this.toolSummonEffectList = new LinkedList();
this.toolBanishEffectList = new LinkedList();
this.breakBlockEffectList = new LinkedList();
this.itemManipulatorEffectList = new LinkedList();
this.digAreaEffectList = new LinkedList();
this.specialDamageEffectList = new LinkedList();
this.durationHash = new HashMap();
this.toolInfoString = new HashMap();
this.critChanceHash = new HashMap();
this.maxDamage = 5;
this.harvestLevel = new HashMap();
this.harvestLevel.put("pickaxe", -1);
this.harvestLevel.put("shovel", -1);
this.harvestLevel.put("axe", -1);
this.digSpeed = new HashMap();
this.digSpeed.put("pickaxe", 1.0f);
this.digSpeed.put("shovel", 1.0f);
this.digSpeed.put("axe", 1.0f);
this.maxDamageHash = new HashMap();
this.maxDamageHash.put("default", 5.0f);
this.fortuneLevel = 0;
this.silkTouch = false;
this.duration = 0;
this.durationHash.put("default", 2400);
}
@Override
public void enhanceParadigm(SpellEnhancement enh)
{
}
@Override
public void castSpell(World world, EntityPlayer entityPlayer, ItemStack crystal)
{
if (entityPlayer.worldObj.isRemote)
{
return;
}
int cost = this.getTotalCost();
if(!EnergyItems.syphonBatteries(crystal, entityPlayer, cost))
{
return;
}
ItemStack toolStack = this.prepareTool(crystal, world);
entityPlayer.setCurrentItemOrArmor(0, toolStack);
this.onSummonTool(toolStack, world, entityPlayer);
}
/**
* @param crystalStack
* @return stack containing the new multitool
*/
public ItemStack prepareTool(ItemStack crystalStack, World world)
{
ItemStack toolStack = new ItemStack(ModItems.customTool, 1);
ItemSpellMultiTool itemTool = (ItemSpellMultiTool) ModItems.customTool;
itemTool.setItemAttack(toolStack, this.composeMaxDamageFromHash());
Set<Entry<String, Integer>> harvestLevelSet = this.harvestLevel.entrySet();
for (Entry<String, Integer> testMap : harvestLevelSet)
{
String tool = testMap.getKey();
int level = testMap.getValue();
itemTool.setHarvestLevel(toolStack, tool, level);
}
Set<Entry<String, Float>> digSpeedSet = this.digSpeed.entrySet();
for (Entry<String, Float> testMap : digSpeedSet)
{
String tool = testMap.getKey();
float speed = testMap.getValue();
itemTool.setDigSpeed(toolStack, tool, speed);
}
itemTool.setFortuneLevel(toolStack, getFortuneLevel());
itemTool.setSilkTouch(toolStack, this.getSilkTouch());
if (this.getSilkTouch())
{
this.addToolString("SilkTouch", "Silk Touch" + " " + SpellHelper.getNumeralForInt(1));
}
if (this.getFortuneLevel() > 0)
{
this.addToolString("Fortune", "Fortune" + " " + SpellHelper.getNumeralForInt(this.getFortuneLevel()));
}
itemTool.setCritChance(toolStack, this.getCritChance() / 100f);
List<String> toolStringList = new LinkedList();
for (String str : this.toolInfoString.values())
{
toolStringList.add(str);
}
itemTool.setToolListString(toolStack, toolStringList);
for (Integer integ : this.durationHash.values())
{
this.duration += integ;
}
itemTool.setDuration(toolStack, world, this.duration);
itemTool.loadParadigmIntoStack(toolStack, this.bufferedEffectList);
EnergyItems.checkAndSetItemOwner(toolStack, EnergyItems.getOwnerName(crystalStack));
itemTool.setContainedCrystal(toolStack, crystalStack);
return toolStack;
}
@Override
public int getDefaultCost()
{
return 100;
}
public static SpellParadigmTool getParadigmForEffectArray(List<SpellEffect> effectList)
{
SpellParadigmTool parad = new SpellParadigmTool();
for (SpellEffect eff : effectList)
{
parad.addBufferedEffect(eff);
}
parad.applyAllSpellEffects();
return parad;
}
public void addLeftClickEffect(ILeftClickEffect eff)
{
if (eff != null)
{
this.leftClickEffectList.add(eff);
}
}
public void addRightClickEffect(IRightClickEffect eff)
{
if (eff != null)
{
this.rightClickEffectList.add(eff);
}
}
public void addUpdateEffect(IToolUpdateEffect eff)
{
if (eff != null)
{
this.toolUpdateEffectList.add(eff);
}
}
public void addToolSummonEffect(IOnSummonTool eff)
{
if (eff != null)
{
this.toolSummonEffectList.add(eff);
}
}
public void addToolBanishEffect(IOnBanishTool eff)
{
if (eff != null)
{
this.toolBanishEffectList.add(eff);
}
}
public void addBlockBreakEffect(IOnBreakBlock eff)
{
if (eff != null)
{
this.breakBlockEffectList.add(eff);
}
}
public void addItemManipulatorEffect(IItemManipulator eff)
{
if (eff != null)
{
this.itemManipulatorEffectList.add(eff);
}
}
public void addDigAreaEffect(IDigAreaEffect eff)
{
if (eff != null)
{
this.digAreaEffectList.add(eff);
}
}
public void addSpecialDamageEffect(ISpecialDamageEffect eff)
{
if (eff != null)
{
this.specialDamageEffectList.add(eff);
}
}
public int onLeftClickEntity(ItemStack stack, EntityLivingBase attacked, EntityLivingBase weilder)
{
int total = 0;
for (ILeftClickEffect effect : this.leftClickEffectList)
{
total += effect.onLeftClickEntity(stack, attacked, weilder);
}
return total;
}
public int onRightClickBlock(ItemStack toolStack, EntityLivingBase weilder, World world, MovingObjectPosition mop)
{
int total = 0;
for (IRightClickEffect effect : this.rightClickEffectList)
{
total += effect.onRightClickBlock(toolStack, weilder, world, mop);
}
return total;
}
public int onRightClickAir(ItemStack toolStack, World world, EntityPlayer player)
{
int total = 0;
for (IRightClickEffect effect : this.rightClickEffectList)
{
total += effect.onRightClickAir(toolStack, player);
}
return total;
}
public int onUpdate(ItemStack toolStack, World world, Entity par3Entity, int invSlot, boolean inHand)
{
int total = 0;
for (IToolUpdateEffect effect : this.toolUpdateEffectList)
{
total += effect.onUpdate(toolStack, world, par3Entity, invSlot, inHand);
}
return total;
}
public int onSummonTool(ItemStack toolStack, World world, Entity entity)
{
int total = 0;
for (IOnSummonTool effect : this.toolSummonEffectList)
{
total += effect.onSummonTool(toolStack, world, entity);
}
return total;
}
public int onBanishTool(ItemStack toolStack, World world, Entity entity, int invSlot, boolean inHand)
{
int total = 0;
for (IOnBanishTool effect : this.toolBanishEffectList)
{
total += effect.onBanishTool(toolStack, world, entity, invSlot, inHand);
}
return total;
}
public int onBreakBlock(ItemStack container, World world, EntityPlayer player, Block block, int meta, int x, int y, int z, ForgeDirection sideBroken)
{
int total = 0;
for (IOnBreakBlock effect : this.breakBlockEffectList)
{
total += effect.onBlockBroken(container, world, player, block, meta, x, y, z, sideBroken);
}
return total;
}
public List<ItemStack> handleItemList(ItemStack toolStack, List<ItemStack> items)
{
List<ItemStack> heldList = items;
for (IItemManipulator eff : this.itemManipulatorEffectList)
{
List<ItemStack> newHeldList = eff.handleItemsOnBlockBroken(toolStack, heldList);
heldList = newHeldList;
}
return heldList;
}
public int digSurroundingArea(ItemStack container, World world, EntityPlayer player, MovingObjectPosition blockPos, String usedToolClass, float blockHardness, int harvestLvl, ItemSpellMultiTool itemTool)
{
int cost = 0;
for (IDigAreaEffect effect : this.digAreaEffectList)
{
cost += effect.digSurroundingArea(container, world, player, blockPos, usedToolClass, blockHardness, harvestLvl, itemTool);
}
return cost;
}
public int getFortuneLevel()
{
return this.fortuneLevel;
}
public void setFortuneLevel(int fortuneLevel)
{
this.fortuneLevel = fortuneLevel;
}
public boolean getSilkTouch()
{
return this.silkTouch;
}
public void setSilkTouch(boolean silkTouch)
{
this.silkTouch = silkTouch;
}
public int getDuration()
{
return this.duration;
}
public void setDuration(int duration)
{
this.duration = duration;
}
public void setDigSpeed(String toolClass, float digSpeed)
{
this.digSpeed.put(toolClass, digSpeed);
}
public void setHarvestLevel(String toolClass, int hlvl)
{
this.harvestLevel.put(toolClass, hlvl);
}
public float composeMaxDamageFromHash()
{
float damage = 0.0f;
for (float f : this.maxDamageHash.values())
{
damage += f;
}
return damage;
}
public void addDamageToHash(String key, float dmg)
{
this.maxDamageHash.put(key, dmg);
}
public void addToolString(String key, String str)
{
if (str != null && key != null)
{
this.toolInfoString.put(key, str);
}
}
public void addCritChance(String key, float chance)
{
//Chance is in percentage chance i.e. chance = 1.0 means 1.0%
this.critChanceHash.put(key, chance);
}
public void addDuration(String key, int dur)
{
this.durationHash.put(key, dur);
}
public float getCritChance()
{
float chance = 0.0f;
for (float fl : this.critChanceHash.values())
{
chance += fl;
}
return chance;
}
public float getAddedDamageForEntity(Entity entity)
{
HashMap<String, Float> hash = new HashMap();
for (ISpecialDamageEffect effect : this.specialDamageEffectList)
{
hash.put(effect.getKey(), effect.getDamageForEntity(entity));
}
float addedDmg = 0.0f;
for (float fl : hash.values())
{
addedDmg += fl;
}
return addedDmg;
}
}