This commit is contained in:
WayofTime 2016-09-11 17:58:54 -04:00
parent f110402169
commit 1e77b16bd7
4 changed files with 127 additions and 0 deletions

View file

@ -20,6 +20,7 @@ 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.TileAltar;
import WayofTime.bloodmagic.tile.TileInversionPillar;
public class BlockInversionPillar extends BlockStringContainer implements IVariantProvider
@ -38,6 +39,19 @@ public class BlockInversionPillar extends BlockStringContainer implements IVaria
setHarvestLevel("pickaxe", 2);
}
@Override
public void breakBlock(World world, BlockPos blockPos, IBlockState blockState)
{
TileEntity tile = world.getTileEntity(blockPos);
if (tile instanceof TileInversionPillar)
{
TileInversionPillar tilePillar = (TileInversionPillar) world.getTileEntity(blockPos);
tilePillar.removePillarFromMap();
}
super.breakBlock(world, blockPos, blockState);
}
@Override
public boolean isOpaqueCube(IBlockState state)
{

View file

@ -13,7 +13,9 @@ import WayofTime.bloodmagic.tile.TileInversionPillar;
public class InversionPillarHandler
{
public static final double farthestDistanceSquared = 16 * 16;
public static Map<Integer, Map<EnumDemonWillType, List<BlockPos>>> pillarMap = new HashMap<Integer, Map<EnumDemonWillType, List<BlockPos>>>();
public static Map<Integer, Map<EnumDemonWillType, Map<BlockPos, List<BlockPos>>>> nearPillarMap = new HashMap<Integer, Map<EnumDemonWillType, Map<BlockPos, List<BlockPos>>>>();
public static boolean addPillarToMap(World world, EnumDemonWillType type, BlockPos pos)
{
@ -49,6 +51,61 @@ public class InversionPillarHandler
}
}
public static boolean removePillarFromMap(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).remove(pos);
} else
{
return false;
}
} else
{
return false;
}
} else
{
return false;
}
}
private static void onPillarRemoved(World world, EnumDemonWillType type, BlockPos pos)
{
int dim = world.provider.getDimension();
if (nearPillarMap.containsKey(dim))
{
Map<EnumDemonWillType, Map<BlockPos, List<BlockPos>>> willMap = nearPillarMap.get(dim);
if (willMap.containsKey(type))
{
Map<BlockPos, List<BlockPos>> posMap = willMap.get(type);
List<BlockPos> posList = posMap.get(pos);
if (posList != null)
{
Iterator<BlockPos> itr = posList.iterator();
while (itr.hasNext())
{
BlockPos checkPos = itr.next();
List<BlockPos> checkPosList = posMap.get(checkPos);
if (checkPosList != null)
{
checkPosList.remove(pos);
}
}
posMap.remove(pos);
}
}
}
}
//TODO: Change to use the nearPillarMap.
public static List<BlockPos> getNearbyPillars(World world, EnumDemonWillType type, BlockPos pos)
{
int dim = world.provider.getDimension();

View file

@ -1,9 +1,15 @@
package WayofTime.bloodmagic.item.block;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import WayofTime.bloodmagic.block.BlockInversionPillar;
import WayofTime.bloodmagic.registry.ModBlocks;
public class ItemBlockInversionPillar extends ItemBlock
{
@ -13,6 +19,51 @@ public class ItemBlockInversionPillar extends ItemBlock
setHasSubtypes(true);
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState)
{
if (!isBlockPillarBase(world.getBlockState(pos.offset(EnumFacing.DOWN)), newState) || !isBlockPillarCap(world.getBlockState(pos.offset(EnumFacing.UP)), newState))
{
return false;
}
return super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState);
}
public boolean isBlockPillarBase(IBlockState baseState, IBlockState newState)
{
Block block = baseState.getBlock();
if (block == ModBlocks.INVERSION_PILLAR_END)
{
int baseMeta = block.getMetaFromState(baseState);
int pillarMeta = newState.getBlock().getMetaFromState(newState);
if (pillarMeta == baseMeta / 2 && baseMeta % 2 == 0)
{
return true;
}
}
return false;
}
public boolean isBlockPillarCap(IBlockState capState, IBlockState newState)
{
Block block = capState.getBlock();
if (block == ModBlocks.INVERSION_PILLAR_END)
{
int capMeta = block.getMetaFromState(capState);
int pillarMeta = newState.getBlock().getMetaFromState(newState);
if (pillarMeta == capMeta / 2 && capMeta % 2 == 1)
{
return true;
}
}
return false;
}
@Override
public String getUnlocalizedName(ItemStack stack)
{

View file

@ -92,6 +92,11 @@ public class TileInversionPillar extends TileTicking
}
}
public void removePillarFromMap()
{
}
public List<BlockPos> getNearbyPillarsExcludingThis()
{
return InversionPillarHandler.getNearbyPillars(worldObj, type, pos);