2015-12-30 20:24:25 +00:00
|
|
|
package WayofTime.bloodmagic.api.ritual;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2015-12-31 16:16:13 +00:00
|
|
|
import java.util.Collections;
|
2015-12-30 20:24:25 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public class AreaDescriptor
|
|
|
|
{
|
2015-12-30 21:19:50 +00:00
|
|
|
public List<BlockPos> getContainedPositions(BlockPos pos)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
2015-12-30 21:19:50 +00:00
|
|
|
return new ArrayList<BlockPos>();
|
2015-12-30 20:34:40 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 21:19:50 +00:00
|
|
|
public AxisAlignedBB getAABB(BlockPos pos)
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2015-12-30 21:19:50 +00:00
|
|
|
|
|
|
|
public static class Rectangle extends AreaDescriptor
|
|
|
|
{
|
|
|
|
private BlockPos minimumOffset;
|
2015-12-31 16:25:24 +00:00
|
|
|
private BlockPos maximumOffset; // Non-inclusive maximum offset.
|
2015-12-30 21:19:50 +00:00
|
|
|
|
2015-12-31 13:01:39 +00:00
|
|
|
private ArrayList<BlockPos> blockPosCache = new ArrayList<BlockPos>();
|
|
|
|
private BlockPos cachedPosition = new BlockPos(0, 0, 0);
|
|
|
|
|
2015-12-31 16:25:24 +00:00
|
|
|
/**
|
|
|
|
* This constructor takes in the minimum and maximum BlockPos. The
|
|
|
|
* maximum offset is non-inclusive, meaning if you pass in (0,0,0) and
|
|
|
|
* (1,1,1), calling getContainedPositions() will only give (0,0,0).
|
|
|
|
*
|
|
|
|
* @param minimumOffset
|
|
|
|
* @param maximumOffset
|
|
|
|
*/
|
2015-12-30 21:19:50 +00:00
|
|
|
public Rectangle(BlockPos minimumOffset, BlockPos maximumOffset)
|
|
|
|
{
|
|
|
|
setOffsets(minimumOffset, maximumOffset);
|
|
|
|
}
|
2015-12-31 16:25:24 +00:00
|
|
|
|
|
|
|
public Rectangle(BlockPos minimumOffset, int sizeX, int sizeY, int sizeZ)
|
|
|
|
{
|
|
|
|
this(minimumOffset, minimumOffset.add(sizeX, sizeY, sizeZ));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Rectangle(BlockPos minimumOffset, int size)
|
|
|
|
{
|
|
|
|
this(minimumOffset, size, size, size);
|
|
|
|
}
|
2015-12-30 21:19:50 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<BlockPos> getContainedPositions(BlockPos pos)
|
|
|
|
{
|
2015-12-31 13:01:39 +00:00
|
|
|
if (!pos.equals(cachedPosition) || blockPosCache.isEmpty())
|
2015-12-30 21:19:50 +00:00
|
|
|
{
|
2015-12-31 13:01:39 +00:00
|
|
|
ArrayList<BlockPos> posList = new ArrayList<BlockPos>();
|
|
|
|
|
2015-12-31 16:25:24 +00:00
|
|
|
for (int i = minimumOffset.getX(); i < maximumOffset.getX(); i++)
|
2015-12-30 21:19:50 +00:00
|
|
|
{
|
2015-12-31 16:25:24 +00:00
|
|
|
for (int j = minimumOffset.getY(); j < maximumOffset.getY(); j++)
|
2015-12-30 21:19:50 +00:00
|
|
|
{
|
2015-12-31 16:25:24 +00:00
|
|
|
for (int k = minimumOffset.getZ(); k < maximumOffset.getZ(); k++)
|
2015-12-31 13:01:39 +00:00
|
|
|
{
|
|
|
|
posList.add(pos.add(i, j, k));
|
|
|
|
}
|
2015-12-30 21:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-31 16:25:24 +00:00
|
|
|
|
2015-12-31 13:01:39 +00:00
|
|
|
blockPosCache = posList;
|
|
|
|
cachedPosition = pos;
|
2015-12-30 21:19:50 +00:00
|
|
|
}
|
2015-12-31 13:01:39 +00:00
|
|
|
|
2015-12-31 16:16:13 +00:00
|
|
|
return Collections.unmodifiableList(blockPosCache);
|
2015-12-30 21:19:50 +00:00
|
|
|
}
|
2015-12-31 13:01:39 +00:00
|
|
|
|
2015-12-30 21:19:50 +00:00
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getAABB(BlockPos pos)
|
|
|
|
{
|
2015-12-31 16:25:24 +00:00
|
|
|
AxisAlignedBB tempAABB = new AxisAlignedBB(minimumOffset, maximumOffset);
|
2015-12-30 21:19:50 +00:00
|
|
|
return tempAABB.offset(pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the offsets of the AreaDescriptor in a safe way that will make
|
|
|
|
* minimumOffset the lowest corner
|
|
|
|
*
|
|
|
|
* @param offset1
|
|
|
|
* @param offset2
|
|
|
|
*/
|
|
|
|
public void setOffsets(BlockPos offset1, BlockPos offset2)
|
|
|
|
{
|
|
|
|
this.minimumOffset = new BlockPos(Math.min(offset1.getX(), offset2.getX()), Math.min(offset1.getY(), offset2.getY()), Math.min(offset1.getZ(), offset2.getZ()));
|
|
|
|
this.maximumOffset = new BlockPos(Math.max(offset1.getX(), offset2.getX()), Math.max(offset1.getY(), offset2.getY()), Math.max(offset1.getZ(), offset2.getZ()));
|
2015-12-31 13:01:39 +00:00
|
|
|
blockPosCache = new ArrayList<BlockPos>();
|
2015-12-30 21:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-30 20:24:25 +00:00
|
|
|
}
|