BloodMagic/1.7.2/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEMasterStone.java

235 lines
6.6 KiB
Java
Raw Normal View History

2014-02-14 20:20:20 +00:00
package WayofTime.alchemicalWizardry.common.tileEntity;
2014-06-02 19:16:36 +00:00
import net.minecraft.entity.player.EntityPlayer;
2014-02-14 20:20:20 +00:00
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
2014-06-02 19:16:36 +00:00
import net.minecraft.util.ChatComponentText;
2014-02-14 20:20:20 +00:00
import net.minecraft.world.World;
2014-05-04 22:11:09 +00:00
import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone;
import WayofTime.alchemicalWizardry.api.rituals.Rituals;
import WayofTime.alchemicalWizardry.api.soulNetwork.LifeEssenceNetwork;
2014-02-14 20:20:20 +00:00
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
2014-05-04 22:11:09 +00:00
public class TEMasterStone extends TileEntity implements IMasterRitualStone
2014-02-14 20:20:20 +00:00
{
2014-06-02 19:16:36 +00:00
//private int currentRitual;
private String currentRitualString;
2014-02-14 20:20:20 +00:00
private boolean isActive;
private String owner;
private String varString1;
2014-02-14 20:20:20 +00:00
private int cooldown;
private int var1;
private int direction;
public TEMasterStone()
{
2014-06-02 19:16:36 +00:00
//currentRitual = 0;
2014-02-14 20:20:20 +00:00
isActive = false;
owner = "";
cooldown = 0;
var1 = 0;
direction = 0;
2014-05-04 22:11:09 +00:00
varString1 = "";
2014-06-02 19:16:36 +00:00
currentRitualString = "";
2014-02-14 20:20:20 +00:00
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
2014-06-02 19:16:36 +00:00
//currentRitual = par1NBTTagCompound.getInteger("currentRitual");
2014-02-14 20:20:20 +00:00
isActive = par1NBTTagCompound.getBoolean("isActive");
owner = par1NBTTagCompound.getString("owner");
cooldown = par1NBTTagCompound.getInteger("cooldown");
var1 = par1NBTTagCompound.getInteger("var1");
direction = par1NBTTagCompound.getInteger("direction");
2014-06-02 19:16:36 +00:00
currentRitualString = par1NBTTagCompound.getString("currentRitualString");
2014-05-04 22:11:09 +00:00
// varString1 = par1NBTTagCompound.getString("varString1");
2014-02-14 20:20:20 +00:00
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
2014-06-02 19:16:36 +00:00
//par1NBTTagCompound.setInteger("currentRitual", currentRitual);
2014-02-14 20:20:20 +00:00
par1NBTTagCompound.setBoolean("isActive", isActive);
par1NBTTagCompound.setString("owner", owner);
par1NBTTagCompound.setInteger("cooldown", cooldown);
par1NBTTagCompound.setInteger("var1", var1);
par1NBTTagCompound.setInteger("direction", direction);
2014-06-02 19:16:36 +00:00
par1NBTTagCompound.setString("currentRitualString", currentRitualString);
2014-05-04 22:11:09 +00:00
// par1NBTTagCompound.setString("varString1", varString1);
2014-02-14 20:20:20 +00:00
}
2014-06-02 19:16:36 +00:00
public void activateRitual(World world, int crystalLevel, EntityPlayer player)
2014-02-14 20:20:20 +00:00
{
2014-06-02 19:16:36 +00:00
if (world.isRemote)
{
return;
}
String testRitual = Rituals.checkValidRitual(world, xCoord, yCoord, zCoord);
2014-02-14 20:20:20 +00:00
2014-06-02 19:16:36 +00:00
if (testRitual.equals(""))
2014-02-14 20:20:20 +00:00
{
2014-06-02 19:16:36 +00:00
player.addChatMessage(new ChatComponentText("Nothing appears to have happened..."));
2014-02-14 20:20:20 +00:00
return;
}
boolean testLevel = Rituals.canCrystalActivate(testRitual, crystalLevel);
if (!testLevel)
{
2014-06-02 19:16:36 +00:00
player.addChatMessage(new ChatComponentText("Your crystal vibrates pathetically."));
2014-02-14 20:20:20 +00:00
return;
}
World worldSave = MinecraftServer.getServer().worldServers[0];
LifeEssenceNetwork data = (LifeEssenceNetwork) worldSave.loadItemData(LifeEssenceNetwork.class, owner);
if (data == null)
{
data = new LifeEssenceNetwork(owner);
worldSave.setItemData(owner, data);
}
int currentEssence = data.currentEssence;
if (currentEssence < Rituals.getCostForActivation(testRitual))
{
2014-06-02 19:16:36 +00:00
player.addChatMessage(new ChatComponentText("You feel a pull, but you are too weak to push any further."));
2014-02-14 20:20:20 +00:00
//TODO Bad stuff
return;
}
if (!world.isRemote)
{
data.currentEssence = currentEssence - Rituals.getCostForActivation(testRitual);
data.markDirty();
2014-06-02 19:16:36 +00:00
player.addChatMessage(new ChatComponentText("A rush of energy flows through the ritual!"));
2014-02-14 20:20:20 +00:00
for (int i = 0; i < 12; i++)
{
SpellHelper.sendIndexedParticleToAllAround(world, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
}
}
cooldown = Rituals.getInitialCooldown(testRitual);
var1 = 0;
2014-06-02 19:16:36 +00:00
currentRitualString = testRitual;
2014-02-14 20:20:20 +00:00
isActive = true;
direction = Rituals.getDirectionOfRitual(world, xCoord, yCoord, zCoord, testRitual);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
public void setOwner(String owner)
{
this.owner = owner;
}
@Override
public void updateEntity()
{
if (!isActive)
{
return;
}
int worldTime = (int) (worldObj.getWorldTime() % 24000);
if (worldObj.isRemote)
{
return;
}
if (worldTime % 100 == 0)
{
2014-06-02 19:16:36 +00:00
boolean testRunes = Rituals.checkDirectionOfRitualValid(worldObj, xCoord, yCoord, zCoord, currentRitualString, direction);
2014-02-14 20:20:20 +00:00
SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
if (!testRunes)
{
isActive = false;
2014-06-02 19:16:36 +00:00
currentRitualString = "";
2014-02-14 20:20:20 +00:00
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
//PacketDispatcher.sendPacketToAllPlayers(TEAltar.getParticlePacket(xCoord, yCoord, zCoord, (short)3));
return;
}
}
if (worldObj.getBlockPowerInput(xCoord, yCoord, zCoord) > 0)
{
return;
}
2014-06-02 19:16:36 +00:00
performRitual(worldObj, xCoord, yCoord, zCoord, currentRitualString);
2014-02-14 20:20:20 +00:00
}
2014-06-02 19:16:36 +00:00
public void performRitual(World world, int x, int y, int z, String currentRitualString2)
2014-02-14 20:20:20 +00:00
{
2014-06-02 19:16:36 +00:00
Rituals.performEffect(this, currentRitualString2);
2014-02-14 20:20:20 +00:00
}
public String getOwner()
{
return owner;
}
public void setCooldown(int newCooldown)
{
this.cooldown = newCooldown;
}
public int getCooldown()
{
return this.cooldown;
}
public void setVar1(int newVar1)
{
this.var1 = newVar1;
}
public int getVar1()
{
return this.var1;
}
public void setActive(boolean active)
{
this.isActive = active;
}
public int getDirection()
{
return this.direction;
}
2014-05-04 22:11:09 +00:00
@Override
public World getWorld()
{
return this.getWorldObj();
}
@Override
public int getXCoord()
{
return xCoord;
}
@Override
public int getYCoord()
{
return yCoord;
}
@Override
public int getZCoord()
{
return zCoord;
}
2014-02-14 20:20:20 +00:00
}