Initial push of the Inversion Pillar before testing.

This commit is contained in:
WayofTime 2016-09-10 16:13:05 -04:00
parent abfc7b13b6
commit 4b54f6d94c
6 changed files with 319 additions and 1 deletions

View file

@ -304,7 +304,8 @@ public class Constants
DEMON_STAIRS_1("BlockStairs1"),
DEMON_STAIRS_2("BlockStairs2"),
DEMON_STAIRS_3("BlockStairs3"),
DEMON_LIGHT("BlockDemonLight");
DEMON_LIGHT("BlockDemonLight"),
INVERSION_PILLAR("BlockInversionPillar");
@Getter
private final String regName;

View file

@ -0,0 +1,51 @@
package WayofTime.bloodmagic.block;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.block.base.BlockStringContainer;
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.tile.TileInversionPillar;
public class BlockInversionPillar extends BlockStringContainer implements IVariantProvider
{
public static final String[] names = { "raw" };
public BlockInversionPillar()
{
super(Material.ROCK, names);
setUnlocalizedName(Constants.Mod.MODID + ".inversionpillar.");
setCreativeTab(BloodMagic.tabBloodMagic);
setHardness(2.0F);
setResistance(5.0F);
setSoundType(SoundType.STONE);
setHarvestLevel("pickaxe", 2);
}
@Override
public List<Pair<Integer, String>> getVariants()
{
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
for (int i = 0; i < names.length; i++)
ret.add(new ImmutablePair<Integer, String>(i, "type=" + names[i]));
return ret;
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileInversionPillar(EnumDemonWillType.values()[meta % 5]);
}
}

View file

@ -0,0 +1,84 @@
package WayofTime.bloodmagic.inversion;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.tile.TileInversionPillar;
public class InversionPillarHandler
{
public static Map<Integer, Map<EnumDemonWillType, List<BlockPos>>> pillarMap = new HashMap<Integer, Map<EnumDemonWillType, List<BlockPos>>>();
public static boolean addPillarToMap(World world, EnumDemonWillType type, BlockPos pos)
{
int dim = world.provider.getDimension();
if (pillarMap.containsKey(dim))
{
Map<EnumDemonWillType, List<BlockPos>> willMap = pillarMap.get(dim);
if (willMap.containsKey(type))
{
if (!willMap.get(type).contains(pos))
{
return willMap.get(type).add(pos);
} else
{
return false;
}
} else
{
List<BlockPos> posList = new ArrayList<BlockPos>();
posList.add(pos);
willMap.put(type, posList);
return true;
}
} else
{
Map<EnumDemonWillType, List<BlockPos>> willMap = new HashMap<EnumDemonWillType, List<BlockPos>>();
List<BlockPos> posList = new ArrayList<BlockPos>();
posList.add(pos);
willMap.put(type, posList);
pillarMap.put(dim, willMap);
return true;
}
}
public static List<BlockPos> getNearbyPillars(World world, EnumDemonWillType type, BlockPos pos)
{
int dim = world.provider.getDimension();
List<BlockPos> posList = new ArrayList<BlockPos>();
if (pillarMap.containsKey(dim))
{
Map<EnumDemonWillType, List<BlockPos>> willMap = pillarMap.get(dim);
posList = willMap.get(type);
}
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 (world.getTileEntity(newPos) instanceof TileInversionPillar) //Make this check... more efficient somehow.
{
newList.add(newPos);
}
}
return newList;
} else
{
return new ArrayList<BlockPos>();
}
}
}

View file

@ -32,6 +32,7 @@ import WayofTime.bloodmagic.block.BlockDemonWallBase;
import WayofTime.bloodmagic.block.BlockDimensionalPortal;
import WayofTime.bloodmagic.block.BlockIncenseAltar;
import WayofTime.bloodmagic.block.BlockInputRoutingNode;
import WayofTime.bloodmagic.block.BlockInversionPillar;
import WayofTime.bloodmagic.block.BlockItemRoutingNode;
import WayofTime.bloodmagic.block.BlockLifeEssence;
import WayofTime.bloodmagic.block.BlockMasterRoutingNode;
@ -73,6 +74,7 @@ import WayofTime.bloodmagic.tile.TileDemonPylon;
import WayofTime.bloodmagic.tile.TileDimensionalPortal;
import WayofTime.bloodmagic.tile.TileImperfectRitualStone;
import WayofTime.bloodmagic.tile.TileIncenseAltar;
import WayofTime.bloodmagic.tile.TileInversionPillar;
import WayofTime.bloodmagic.tile.TileMasterRitualStone;
import WayofTime.bloodmagic.tile.TileMimic;
import WayofTime.bloodmagic.tile.TilePhantomBlock;
@ -143,6 +145,8 @@ public class ModBlocks
public static Block demonStairs2;
public static Block demonStairs3;
public static Block inversionPillar;
public static void init()
{
FluidRegistry.registerFluid(BlockLifeEssence.getLifeEssence());
@ -199,6 +203,8 @@ public class ModBlocks
demonStairs2 = registerBlock(new ItemDemonStairsBase(new BlockDemonStairsBase("stairs2", Material.ROCK, new String[] { "destructive", "vengeful" })), Constants.BloodMagicBlock.DEMON_STAIRS_2.getRegName());
demonStairs3 = registerBlock(new ItemDemonStairsBase(new BlockDemonStairsBase("stairs3", Material.ROCK, new String[] { "steadfast" })), Constants.BloodMagicBlock.DEMON_STAIRS_3.getRegName());
inversionPillar = registerBlock(new ItemBlock(new BlockInversionPillar()), Constants.BloodMagicBlock.INVERSION_PILLAR.getRegName());
BloodMagicAPI.addToTeleposerBlacklist(inputRoutingNode);
BloodMagicAPI.addToTranspositionBlacklist(inputRoutingNode);
BloodMagicAPI.addToTeleposerBlacklist(outputRoutingNode);
@ -236,6 +242,7 @@ public class ModBlocks
GameRegistry.registerTileEntity(TileDimensionalPortal.class, Constants.Mod.MODID + ":" + TileDimensionalPortal.class.getSimpleName());
GameRegistry.registerTileEntity(TileBloodTank.class, Constants.Mod.MODID + ":" + TileBloodTank.class.getSimpleName());
GameRegistry.registerTileEntity(TileMimic.class, Constants.Mod.MODID + ":" + TileMimic.class.getSimpleName());
GameRegistry.registerTileEntity(TileInversionPillar.class, Constants.Mod.MODID + ":" + TileInversionPillar.class.getSimpleName());
}
@SideOnly(Side.CLIENT)

View file

@ -0,0 +1,156 @@
package WayofTime.bloodmagic.tile;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.block.state.IBlockState;
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;
import WayofTime.bloodmagic.inversion.InversionPillarHandler;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.tile.base.TileTicking;
@Getter
@Setter
public class TileInversionPillar extends TileTicking
{
public static double willPerOperation = 2.5;
public static double inversionPerOperation = 5;
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 counter = 0;
public boolean isRegistered = false;
public static final double maxWillForChunk = 200;
public TileInversionPillar()
{
this(EnumDemonWillType.DEFAULT);
}
public TileInversionPillar(EnumDemonWillType type)
{
this.type = type;
}
@Override
public void onUpdate()
{
if (worldObj.isRemote)
{
return;
}
if (!isRegistered)
{
isRegistered = InversionPillarHandler.addPillarToMap(worldObj, getType(), getPos());
}
counter++;
double currentWill = WorldDemonWillHandler.getCurrentWill(worldObj, pos, type);
if (counter % 20 == 0)
{
List<BlockPos> pillarList = getNearbyPillarsExcludingThis();
generateWillForNearbyPillars(currentWill, pillarList);
}
}
public List<BlockPos> getNearbyPillarsExcludingThis()
{
return InversionPillarHandler.getNearbyPillars(worldObj, type, pos);
}
@Override
public void deserialize(NBTTagCompound tag)
{
super.deserialize(tag);
if (!tag.hasKey(Constants.NBT.WILL_TYPE))
{
type = EnumDemonWillType.DEFAULT;
}
type = EnumDemonWillType.valueOf(tag.getString(Constants.NBT.WILL_TYPE));
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
super.serialize(tag);
tag.setString(Constants.NBT.WILL_TYPE, type.toString());
return tag;
}
public void generateWillForNearbyPillars(double currentWillInChunk, List<BlockPos> offsetPositions)
{
double totalGeneratedWill = 0;
double willFactor = currentWillInChunk / 100;
for (BlockPos offsetPos : offsetPositions)
{
double distanceSquared = offsetPos.distanceSq(pos);
totalGeneratedWill += willFactor * 350 / (350 + Math.pow(distanceSquared, 3 / 2));
}
if (totalGeneratedWill > 0)
{
WorldDemonWillHandler.fillWillToMaximum(worldObj, pos, type, totalGeneratedWill, maxWillForChunk, true);
}
}
public void generateInversionForNearbyPillars(double currentWillInChunk, List<BlockPos> offsetPositions)
{
double totalGeneratedInversion = 0;
double willFactor = currentWillInChunk / 100;
for (BlockPos offsetPos : offsetPositions)
{
double distanceSquared = offsetPos.distanceSq(pos);
totalGeneratedInversion += 3000 / (3000 + Math.pow(distanceSquared, 5 / 2)) + willFactor;
}
currentInversion = Math.max(0, totalGeneratedInversion);
}
public boolean polluteNearbyBlocks(double currentWillInChunk)
{
if (currentWillInChunk < operationThreshold || currentInversion < inversionPerOperation)
{
return false;
}
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;
}
IBlockState state = worldObj.getBlockState(offsetPos);
if (!state.getBlock().isAir(state, worldObj, offsetPos))
{
//Consume Will and set this block
return worldObj.setBlockState(offsetPos, ModBlocks.demonExtras.getStateFromMeta(0));
}
return false;
}
}

View file

@ -0,0 +1,19 @@
{
"forge_marker": 1,
"defaults": {
"textures": { },
"model": "cube_all",
"uvlock": true
},
"variants": {
"type": {
"raw": {
"textures": {
"all": "bloodmagic:blocks/WoodBrickPath"
}
}
}
}
}