Added growth method for the crystals.

This commit is contained in:
WayofTime 2016-02-26 22:11:28 -05:00
parent ea24e7edd8
commit 70f4c117d7
4 changed files with 147 additions and 6 deletions

View file

@ -16,7 +16,7 @@ public class WorldDemonWillHandler
public static ConcurrentHashMap<Integer, CopyOnWriteArrayList<PosXY>> dirtyChunks = new ConcurrentHashMap<Integer, CopyOnWriteArrayList<PosXY>>();
public static ConcurrentHashMap<Integer, BlockPos> taintTrigger = new ConcurrentHashMap<Integer, BlockPos>();
public static WillWorld getAuraWorld(int dim)
public static WillWorld getWillWorld(int dim)
{
return containedWills.get(dim);
}
@ -71,6 +71,26 @@ public class WorldDemonWillHandler
}
}
public static EnumDemonWillType getHighestDemonWillType(World world, BlockPos pos)
{
double currentMax = 0;
EnumDemonWillType currentHighest = EnumDemonWillType.DEFAULT;
WillChunk willChunk = getWillChunk(world, pos);
DemonWillHolder currentWill = willChunk.getCurrentWill();
for (EnumDemonWillType type : EnumDemonWillType.values())
{
if (currentWill.getWill(type) > currentMax)
{
currentMax = currentWill.getWill(type);
currentHighest = type;
}
}
return currentHighest;
}
public static double drainWill(World world, BlockPos pos, EnumDemonWillType type, double amount, boolean doDrain)
{
WillChunk willChunk = getWillChunk(world, pos);

View file

@ -146,6 +146,11 @@ public class ItemSoulGem extends Item implements IDemonWillGem
@Override
public double drainWill(EnumDemonWillType type, ItemStack soulGemStack, double drainAmount)
{
EnumDemonWillType currentType = this.getCurrentType(soulGemStack);
if (currentType != type)
{
return 0;
}
double souls = getWill(type, soulGemStack);
double soulsDrained = Math.min(drainAmount, souls);

View file

@ -16,12 +16,18 @@ import net.minecraft.world.World;
import WayofTime.bloodmagic.api.soul.DemonWillHolder;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWillConduit;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
public class TileDemonCrystal extends TileEntity implements ITickable, IDemonWillConduit
{
public DemonWillHolder holder = new DemonWillHolder();
public final int maxWill = 100;
public final double drainRate = 1;
public static final double sameWillConversionRate = 5;
public static final double defaultWillConversionRate = 50;
public double progressToNextCrystal = 0;
public int internalCounter = 0;
@Getter
@Setter
@ -43,11 +49,55 @@ public class TileDemonCrystal extends TileEntity implements ITickable, IDemonWil
return;
}
if (worldObj.getWorldTime() % 200 == 0)
internalCounter++;
if (internalCounter % 20 == 0 && crystalCount < 7)
{
crystalCount = Math.min(crystalCount + 1, 7);
worldObj.markBlockForUpdate(pos);
EnumDemonWillType type = EnumDemonWillType.values()[this.getBlockMetadata()];
double value = WorldDemonWillHandler.getCurrentWill(worldObj, pos, type);
if (type != EnumDemonWillType.DEFAULT)
{
if (value >= 100)
{
double nextProgress = getCrystalGrowthPerSecond(value);
progressToNextCrystal += WorldDemonWillHandler.drainWill(worldObj, getPos(), type, nextProgress * sameWillConversionRate, true) / sameWillConversionRate;
} else
{
value = WorldDemonWillHandler.getCurrentWill(worldObj, pos, EnumDemonWillType.DEFAULT);
if (value > 0.5)
{
double nextProgress = getCrystalGrowthPerSecond(value);
progressToNextCrystal += WorldDemonWillHandler.drainWill(worldObj, getPos(), EnumDemonWillType.DEFAULT, nextProgress * defaultWillConversionRate, true) / defaultWillConversionRate;
}
}
} else
{
if (value > 0.5)
{
double nextProgress = getCrystalGrowthPerSecond(value);
progressToNextCrystal += WorldDemonWillHandler.drainWill(worldObj, getPos(), type, nextProgress * sameWillConversionRate, true) / sameWillConversionRate;
}
}
if (progressToNextCrystal >= 1)
{
progressToNextCrystal--;
crystalCount++;
worldObj.markBlockForUpdate(pos);
}
}
// if (worldObj.getWorldTime() % 200 == 0)
// {
// crystalCount = Math.min(crystalCount + 1, 7);
// worldObj.markBlockForUpdate(pos);
// }
}
public double getCrystalGrowthPerSecond(double will)
{
return 1.0 / 80 * Math.sqrt(will / 200);
}
public int getCrystalCountForRender()
@ -63,6 +113,7 @@ public class TileDemonCrystal extends TileEntity implements ITickable, IDemonWil
holder.readFromNBT(tag, "Will");
crystalCount = tag.getInteger("crystalCount");
placement = EnumFacing.getFront(tag.getInteger("placement"));
progressToNextCrystal = tag.getDouble("progress");
}
@Override
@ -73,6 +124,7 @@ public class TileDemonCrystal extends TileEntity implements ITickable, IDemonWil
holder.writeToNBT(tag, "Will");
tag.setInteger("crystalCount", crystalCount);
tag.setInteger("placement", placement.getIndex());
tag.setDouble("progress", progressToNextCrystal);
}
// IDemonWillConduit

View file

@ -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