BloodMagic/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TESpellTable.java

127 lines
3.4 KiB
Java
Raw Normal View History

package WayofTime.alchemicalWizardry.common.tileEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySkull;
2015-07-29 08:23:01 -04:00
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.common.spell.simple.HomSpell;
import WayofTime.alchemicalWizardry.common.spell.simple.HomSpellRegistry;
2015-07-30 10:21:53 -04:00
public class TESpellTable extends TileEntity
{
2015-07-30 10:21:53 -04:00
public boolean canCastSpell()
{
return true;
}
public int getCostForSpell()
{
HomSpell spell = getSpell();
if (spell != null)
{
switch (getModifiedParadigm())
{
case 0:
return spell.getOffensiveRangedEnergy();
case 1:
return spell.getOffensiveMeleeEnergy();
case 2:
return spell.getDefensiveEnergy();
case 3:
return spell.getEnvironmentalEnergy();
}
}
return 0;
}
public int castSpell(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
HomSpell spell = getSpell();
if (spell != null)
{
switch (getModifiedParadigm())
{
case 0:
spell.onOffensiveRangedRightClick(par1ItemStack, par2World, par3EntityPlayer);
return spell.getOffensiveRangedEnergy();
case 1:
spell.onOffensiveMeleeRightClick(par1ItemStack, par2World, par3EntityPlayer);
return spell.getOffensiveMeleeEnergy();
case 2:
spell.onDefensiveRightClick(par1ItemStack, par2World, par3EntityPlayer);
return spell.getDefensiveEnergy();
case 3:
spell.onEnvironmentalRightClick(par1ItemStack, par2World, par3EntityPlayer);
return spell.getEnvironmentalEnergy();
}
}
return 0;
}
public HomSpell getSpell()
{
2015-07-29 08:23:01 -04:00
for(EnumFacing face : EnumFacing.HORIZONTALS)
{
TileEntity tileEntity = worldObj.getTileEntity(pos.offset(face));
2015-07-29 08:23:01 -04:00
if (tileEntity instanceof TEAltar)
{
2015-07-29 08:23:01 -04:00
ItemStack itemStack = ((TEAltar) tileEntity).getStackInSlot(0);
2015-07-29 08:23:01 -04:00
if (itemStack != null)
{
2015-07-29 08:23:01 -04:00
HomSpell spell = HomSpellRegistry.getSpellForItemStack(itemStack);
2015-07-29 08:23:01 -04:00
if (spell != null)
{
return spell;
}
}
}
2015-07-29 08:23:01 -04:00
}
return null;
}
public int getModifiedParadigm()
{
//TODO change so that it works with a Tile Entity for a custom head or whatnot
2015-07-29 08:23:01 -04:00
TileEntity tileEntity = worldObj.getTileEntity(pos.offsetUp());
if (tileEntity instanceof TileEntitySkull)
{
2015-07-29 08:23:01 -04:00
int skullType = ((TileEntitySkull) tileEntity).getSkullType();
switch (skullType)
{
case 0:
return 0;
case 1:
return 1;
case 2:
return 2;
case 4:
return 3;
}
}
return -1;
}
}