Added growth method for the crystals.
This commit is contained in:
parent
ea24e7edd8
commit
70f4c117d7
4 changed files with 147 additions and 6 deletions
|
@ -2,16 +2,25 @@ package WayofTime.bloodmagic.tile;
|
|||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import WayofTime.bloodmagic.api.soul.DemonWillHolder;
|
||||
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
|
||||
import WayofTime.bloodmagic.api.soul.IDemonWillConduit;
|
||||
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
|
||||
import WayofTime.bloodmagic.registry.ModBlocks;
|
||||
|
||||
public class TileDemonCrystallizer extends TileEntity implements ITickable, IDemonWillConduit
|
||||
{
|
||||
//The whole purpose of this block is to grow a crystal initially. The acceleration and crystal growing is up to the crystal itself afterwards.
|
||||
public DemonWillHolder holder = new DemonWillHolder();
|
||||
public final int maxWill = 100;
|
||||
public final double drainRate = 1;
|
||||
public static final int maxWill = 100;
|
||||
public static final double drainRate = 1;
|
||||
|
||||
public static final double willToFormCrystal = 100;
|
||||
public static final double totalFormationTime = 1000;
|
||||
public double internalCounter = 0;
|
||||
|
||||
public TileDemonCrystallizer()
|
||||
{
|
||||
|
@ -21,7 +30,60 @@ public class TileDemonCrystallizer extends TileEntity implements ITickable, IDem
|
|||
@Override
|
||||
public void update()
|
||||
{
|
||||
if (worldObj.isRemote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BlockPos offsetPos = pos.offset(EnumFacing.UP);
|
||||
if (worldObj.isAirBlock(offsetPos)) //Room for a crystal to grow
|
||||
{
|
||||
EnumDemonWillType highestType = WorldDemonWillHandler.getHighestDemonWillType(worldObj, pos);
|
||||
double amount = WorldDemonWillHandler.getCurrentWill(worldObj, pos, highestType);
|
||||
if (amount >= willToFormCrystal)
|
||||
{
|
||||
internalCounter += getCrystalFormationRate(amount);
|
||||
if (internalCounter >= totalFormationTime)
|
||||
{
|
||||
if (WorldDemonWillHandler.drainWill(worldObj, getPos(), highestType, willToFormCrystal, false) >= willToFormCrystal)
|
||||
{
|
||||
if (highestType == EnumDemonWillType.DEFAULT && formRandomSpecialCrystal(offsetPos) || formCrystal(highestType, offsetPos))
|
||||
{
|
||||
WorldDemonWillHandler.drainWill(worldObj, getPos(), highestType, willToFormCrystal, true);
|
||||
internalCounter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean formCrystal(EnumDemonWillType type, BlockPos position)
|
||||
{
|
||||
worldObj.setBlockState(position, ModBlocks.demonCrystal.getStateFromMeta(type.ordinal()));
|
||||
TileEntity tile = worldObj.getTileEntity(position);
|
||||
if (tile instanceof TileDemonCrystal)
|
||||
{
|
||||
((TileDemonCrystal) tile).setPlacement(EnumFacing.UP);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean formRandomSpecialCrystal(BlockPos position)
|
||||
{
|
||||
if (worldObj.rand.nextDouble() > 0.1)
|
||||
{
|
||||
return formCrystal(EnumDemonWillType.DEFAULT, position);
|
||||
}
|
||||
EnumDemonWillType crystalType = EnumDemonWillType.values()[worldObj.rand.nextInt(EnumDemonWillType.values().length - 1) + 1];
|
||||
return formCrystal(crystalType, position);
|
||||
}
|
||||
|
||||
public double getCrystalFormationRate(double currentWill)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +92,7 @@ public class TileDemonCrystallizer extends TileEntity implements ITickable, IDem
|
|||
super.readFromNBT(tag);
|
||||
|
||||
holder.readFromNBT(tag, "Will");
|
||||
internalCounter = tag.getDouble("internalCounter");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,6 +101,7 @@ public class TileDemonCrystallizer extends TileEntity implements ITickable, IDem
|
|||
super.writeToNBT(tag);
|
||||
|
||||
holder.writeToNBT(tag, "Will");
|
||||
tag.setDouble("internalCounter", internalCounter);
|
||||
}
|
||||
|
||||
// IDemonWillConduit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue