Spell Work

Need to work on how the EntitySpellProjectile saves its data. Does not
work properly. Perhaps it was not registered?
This commit is contained in:
WayofTime 2014-01-25 09:22:59 -05:00
parent 5dcef131dc
commit 112b4e6b53
15 changed files with 314 additions and 92 deletions

View file

@ -5,18 +5,10 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.IProjectileImpactEffect;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.IProjectileUpdateEffect;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.AxisAlignedBB;
@ -26,6 +18,9 @@ import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellEffect;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.IProjectileImpactEffect;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.IProjectileUpdateEffect;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -50,6 +45,7 @@ public class EntitySpellProjectile extends Entity implements IProjectile
private boolean penetration = false;
public List<IProjectileUpdateEffect> updateEffectList = new ArrayList();
public List<String> effectList = new LinkedList();
public List<SpellEffect> spellEffectList = new LinkedList();
public EntitySpellProjectile(World par1World)
{
@ -81,6 +77,7 @@ public class EntitySpellProjectile extends Entity implements IProjectile
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
@ -272,19 +269,23 @@ public class EntitySpellProjectile extends Entity implements IProjectile
NBTTagList effectList = new NBTTagList();
for (String str : this.effectList)
{
if (str != null)
{
NBTTagCompound tag = new NBTTagCompound();
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);
// }
// }
tag.setString("Class", str);
effectList.appendTag(tag);
}
}
par1NBTTagCompound.setTag("Effects", effectList);
par1NBTTagCompound.setTag("Effects", effectList);
}
/**
@ -301,15 +302,32 @@ public class EntitySpellProjectile extends Entity implements IProjectile
inGround = par1NBTTagCompound.getByte("inGround") == 1;
NBTTagList tagList = par1NBTTagCompound.getTagList("Effects");
this.effectList = new LinkedList();
for (int i = 0; i < tagList.tagCount(); i++)
List<SpellEffect> spellEffectList = new LinkedList();
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
this.effectList.add(tag.getString("Class"));
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.getParadigmForStringArray(effectList);
SpellParadigmProjectile parad = SpellParadigmProjectile.getParadigmForEffectArray(spellEffectList);
parad.applyAllSpellEffects();
parad.prepareProjectile(this);
}
@ -514,7 +532,7 @@ public class EntitySpellProjectile extends Entity implements IProjectile
{
for(IProjectileImpactEffect impactEffect : impactList)
{
impactEffect.onTileImpact(mop);
impactEffect.onTileImpact(worldObj, mop);
}
}
}
@ -549,4 +567,9 @@ public class EntitySpellProjectile extends Entity implements IProjectile
{
this.effectList = stringList;
}
public void setSpellEffectList(List<SpellEffect> list)
{
this.spellEffectList = list;
}
}

View file

@ -13,7 +13,7 @@ import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhanc
public abstract class SpellParadigm
{
protected List<SpellEffect> bufferedEffectList = new ArrayList();
protected List<String> effectList = new LinkedList();
public List<String> effectList = new LinkedList();
public void addBufferedEffect(SpellEffect effect)
{

View file

@ -86,6 +86,18 @@ public class SpellParadigmProjectile extends SpellParadigm
return parad;
}
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);
@ -94,6 +106,7 @@ public class SpellParadigmProjectile extends SpellParadigm
proj.setPenetration(penetration);
proj.setEffectList(effectList);
proj.setRicochetMax(ricochetMax);
proj.setSpellEffectList(bufferedEffectList);
}
public void addImpactEffect(IProjectileImpactEffect eff)

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import WayofTime.alchemicalWizardry.common.items.EnergyItems;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellEffect;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.ISelfSpellEffect;
import WayofTime.alchemicalWizardry.common.spell.complex.enhancement.SpellEnhancement;
import net.minecraft.entity.player.EntityPlayer;
@ -53,4 +54,49 @@ public class SpellParadigmSelf extends SpellParadigm
{
return 100;
}
public static SpellParadigmSelf getParadigmForStringArray(List<String> stringList)
{
SpellParadigmSelf parad = new SpellParadigmSelf();
try
{
for(String str : stringList)
{
Class clazz = Class.forName(str);
if(clazz!=null)
{
Object obj = clazz.newInstance();
if(obj instanceof SpellEffect)
{
parad.addBufferedEffect((SpellEffect)obj);
continue;
}
if(obj instanceof SpellModifier)
{
parad.modifyBufferedEffect((SpellModifier)obj);
continue;
}
if(obj instanceof SpellEnhancement)
{
parad.applyEnhancement((SpellEnhancement)obj);
continue;
}
}
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return parad;
}
}

View file

@ -1,5 +1,6 @@
package WayofTime.alchemicalWizardry.common.spell.complex.effect;
import net.minecraft.nbt.NBTTagCompound;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellModifier;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellParadigm;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellParadigmMelee;
@ -169,4 +170,49 @@ public abstract class SpellEffect
{
return this.potencyEnhancement;
}
public NBTTagCompound getTag()
{
NBTTagCompound tag = new NBTTagCompound();
tag.setString("Class", this.getClass().getName());
tag.setInteger("power", powerEnhancement);
tag.setInteger("cost", costEnhancement);
tag.setInteger("potency", potencyEnhancement);
return tag;
}
public static SpellEffect getEffectFromTag(NBTTagCompound tag)
{
try {
Class clazz = Class.forName(tag.getString("Class"));
if(clazz !=null)
{
try {
Object obj = clazz.newInstance();
if(obj instanceof SpellEffect)
{
SpellEffect eff = (SpellEffect) obj;
eff.powerEnhancement = tag.getInteger("power");
eff.costEnhancement = tag.getInteger("cost");
eff.potencyEnhancement = tag.getInteger("potency");
return eff;
}
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}

View file

@ -3,6 +3,7 @@ package WayofTime.alchemicalWizardry.common.spell.complex.effect;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellParadigmMelee;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellParadigmProjectile;
import WayofTime.alchemicalWizardry.common.spell.complex.SpellParadigmSelf;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.ProjectileDefaultFire;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.fire.SelfDefaultFire;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.fire.SelfDefensiveFire;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects.fire.SelfEnvironmentalFire;
@ -13,7 +14,8 @@ public class SpellEffectFire extends SpellEffect
@Override
public void defaultModificationProjectile(SpellParadigmProjectile parad)
{
parad.addImpactEffect(new ProjectileDefaultFire(this.powerEnhancement,this.potencyEnhancement,this.costEnhancement));
parad.damage+=this.potencyEnhancement;
}
@Override

View file

@ -2,9 +2,10 @@ package WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects;
import net.minecraft.entity.Entity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public interface IProjectileImpactEffect
{
public void onEntityImpact(Entity mop);
public void onTileImpact(MovingObjectPosition mop);
public void onTileImpact(World world, MovingObjectPosition mop);
}

View file

@ -0,0 +1,33 @@
package WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class ProjectileDefaultFire extends ProjectileImpactEffect
{
public ProjectileDefaultFire(int power, int potency, int cost)
{
super(power, potency, cost);
}
@Override
public void onEntityImpact(Entity mop)
{
mop.setFire((int)Math.pow(2,this.powerUpgrades));
}
@Override
public void onTileImpact(World world, MovingObjectPosition mop)
{
int x = mop.blockX;
int y = mop.blockY;
int z = mop.blockZ;
if(world.isAirBlock(x, y+1, z))
{
world.setBlock(x, y+1, z, Block.fire.blockID);
}
}
}

View file

@ -0,0 +1,15 @@
package WayofTime.alchemicalWizardry.common.spell.complex.effect.impactEffects;
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;
}
}