Did some work on the Inversion Pillar

This commit is contained in:
WayofTime 2016-09-10 20:15:17 -04:00
parent 24b4c4b8d1
commit aad1b541f8
2 changed files with 84 additions and 20 deletions

View file

@ -61,14 +61,16 @@ public class InversionPillarHandler
if (posList != null)
{
posList.remove(pos);
List<BlockPos> newList = new ArrayList<BlockPos>();
Iterator<BlockPos> itr = posList.iterator();
while (itr.hasNext())
{
BlockPos newPos = itr.next();
if (newPos.equals(pos))
{
continue;
}
if (world.getTileEntity(newPos) instanceof TileInversionPillar) //Make this check... more efficient somehow.
{
newList.add(newPos);

View file

@ -4,10 +4,11 @@ import java.util.List;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
@ -20,13 +21,15 @@ import WayofTime.bloodmagic.tile.base.TileTicking;
public class TileInversionPillar extends TileTicking
{
public static double willPerOperation = 2.5;
public static double inversionPerOperation = 5;
public static double inversionPerOperation = 2;
public static double inversionToIncreaseRadius = 100;
public static double inversionToAddPillar = 200;
public static double operationThreshold = 20;
public EnumDemonWillType type;
public double currentInversion = 0;
public int consecutiveFailedChecks = 0; //If you fail enough checks, increase the radius.
public int currentInfectionRadius = 3;
public int currentInfectionRadius = 1;
public int counter = 0;
@ -60,10 +63,32 @@ public class TileInversionPillar extends TileTicking
counter++;
double currentWill = WorldDemonWillHandler.getCurrentWill(worldObj, pos, type);
if (counter % 20 == 0)
if (counter % 1 == 0)
{
List<BlockPos> pillarList = getNearbyPillarsExcludingThis();
generateWillForNearbyPillars(currentWill, pillarList);
generateInversionForNearbyPillars(currentWill, pillarList);
int pollute = polluteNearbyBlocks(currentWill);
if (pollute == 1)
{
consecutiveFailedChecks++;
} else if (pollute == 0)
{
consecutiveFailedChecks = 0;
}
if (consecutiveFailedChecks > 5 * currentInfectionRadius && currentInversion >= inversionToIncreaseRadius)
{
currentInfectionRadius++;
consecutiveFailedChecks = 0;
currentInversion -= inversionToIncreaseRadius;
System.out.println("Increasing radius!");
}
if (currentInversion >= inversionToAddPillar)
{
}
}
}
@ -83,6 +108,9 @@ public class TileInversionPillar extends TileTicking
}
type = EnumDemonWillType.valueOf(tag.getString(Constants.NBT.WILL_TYPE));
currentInversion = tag.getDouble("currentInversion");
currentInfectionRadius = tag.getInteger("currentInfectionRadius");
consecutiveFailedChecks = tag.getInteger("consecutiveFailedChecks");
}
@Override
@ -91,6 +119,9 @@ public class TileInversionPillar extends TileTicking
super.serialize(tag);
tag.setString(Constants.NBT.WILL_TYPE, type.toString());
tag.setDouble("currentInversion", currentInversion);
tag.setInteger("currentInfectionRadius", currentInfectionRadius);
tag.setInteger("consecutiveFailedChecks", consecutiveFailedChecks);
return tag;
}
@ -98,13 +129,13 @@ public class TileInversionPillar extends TileTicking
public void generateWillForNearbyPillars(double currentWillInChunk, List<BlockPos> offsetPositions)
{
double totalGeneratedWill = 0;
double willFactor = currentWillInChunk / 100;
double willFactor = currentWillInChunk / 200;
for (BlockPos offsetPos : offsetPositions)
{
double distanceSquared = offsetPos.distanceSq(pos);
totalGeneratedWill += willFactor * 350 / (350 + Math.pow(distanceSquared, 3 / 2));
totalGeneratedWill += willFactor * 343 / (343 + Math.pow(distanceSquared, 3 / 2));
}
if (totalGeneratedWill > 0)
@ -115,42 +146,73 @@ public class TileInversionPillar extends TileTicking
public void generateInversionForNearbyPillars(double currentWillInChunk, List<BlockPos> offsetPositions)
{
double totalGeneratedInversion = 0;
double willFactor = currentWillInChunk / 100;
double willFactor = currentWillInChunk / 400;
double totalGeneratedInversion = willFactor;
for (BlockPos offsetPos : offsetPositions)
{
double distanceSquared = offsetPos.distanceSq(pos);
totalGeneratedInversion += 3000 / (3000 + Math.pow(distanceSquared, 5 / 2)) + willFactor;
totalGeneratedInversion += 3125 / (3125 + Math.pow(distanceSquared, 5 / 2));
}
currentInversion = Math.max(0, totalGeneratedInversion);
currentInversion = Math.max(0, currentInversion + totalGeneratedInversion);
}
public boolean polluteNearbyBlocks(double currentWillInChunk)
/**
*
* @param currentWillInChunk
* @return 0 if the block is successfully placed, 1 if the block is not
* placed due to the selected place being invalid, 2 if the block is
* not placed due to there not being enough Will or Inversion
*/
public int polluteNearbyBlocks(double currentWillInChunk)
{
// System.out.println("Hai! :D Current Inversion: " + currentInversion + ", Current Will: " + currentWillInChunk);
if (currentWillInChunk < operationThreshold || currentInversion < inversionPerOperation)
{
return false;
return 2;
}
double xOff = worldObj.rand.nextGaussian() * currentInfectionRadius;
double yOff = worldObj.rand.nextGaussian() * currentInfectionRadius;
double zOff = worldObj.rand.nextGaussian() * currentInfectionRadius;
double r2 = xOff * xOff + yOff * yOff + zOff * zOff;
int maxInfectionRadius2 = (4 * currentInfectionRadius * currentInfectionRadius);
if (r2 > maxInfectionRadius2)
{
double factor = Math.sqrt(maxInfectionRadius2 / r2);
xOff *= factor;
yOff *= factor;
zOff *= factor;
}
double xOff = MathHelper.clamp_double(worldObj.rand.nextGaussian() * currentInfectionRadius, -currentInfectionRadius, currentInfectionRadius);
double yOff = MathHelper.clamp_double(worldObj.rand.nextGaussian() * currentInfectionRadius, -currentInfectionRadius, currentInfectionRadius);
double zOff = MathHelper.clamp_double(worldObj.rand.nextGaussian() * currentInfectionRadius, -currentInfectionRadius, currentInfectionRadius);
BlockPos offsetPos = pos.add(xOff + 0.5, yOff + 0.5, zOff + 0.5);
if (offsetPos.equals(pos))
{
return false;
return 1;
}
IBlockState state = worldObj.getBlockState(offsetPos);
if (!state.getBlock().isAir(state, worldObj, offsetPos))
{
//Consume Will and set this block
return worldObj.setBlockState(offsetPos, ModBlocks.DEMON_EXTRAS.getStateFromMeta(0));
// System.out.println("I am polluting you at: " + offsetPos);
Block block = state.getBlock();
if (block == Blocks.DIRT || block == Blocks.STONE || block == Blocks.GRASS)
{
if (worldObj.setBlockState(offsetPos, ModBlocks.DEMON_EXTRAS.getStateFromMeta(0)))
{
WorldDemonWillHandler.drainWill(worldObj, pos, type, willPerOperation, true);
currentInversion -= inversionPerOperation;
return 0;
}
}
return false;
return 1;
}
return 1;
}
}