2015-12-30 20:24:25 +00:00
|
|
|
package WayofTime.bloodmagic.api.ritual;
|
|
|
|
|
2016-03-17 20:00:44 +00:00
|
|
|
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
2015-12-30 20:24:25 +00:00
|
|
|
import java.util.ArrayList;
|
2015-12-31 16:16:13 +00:00
|
|
|
import java.util.Collections;
|
2016-02-02 23:16:55 +00:00
|
|
|
import java.util.Iterator;
|
2015-12-30 20:24:25 +00:00
|
|
|
import java.util.List;
|
2016-02-02 23:16:55 +00:00
|
|
|
import java.util.function.Consumer;
|
2015-12-30 20:24:25 +00:00
|
|
|
|
2016-02-02 23:16:55 +00:00
|
|
|
public abstract class AreaDescriptor implements Iterator<BlockPos>
|
2015-12-30 20:34:40 +00:00
|
|
|
{
|
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
|
|
|
|
2015-12-31 21:01:47 +00:00
|
|
|
public abstract void resetCache();
|
|
|
|
|
|
|
|
public abstract boolean isWithinArea(BlockPos pos);
|
|
|
|
|
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.
|
2016-02-02 23:16:55 +00:00
|
|
|
private BlockPos currentPosition;
|
2015-12-30 21:19:50 +00:00
|
|
|
|
2016-01-11 23:07:06 +00:00
|
|
|
private ArrayList<BlockPos> blockPosCache;
|
|
|
|
private BlockPos cachedPosition;
|
2015-12-31 13:01:39 +00:00
|
|
|
|
2015-12-31 21:01:47 +00:00
|
|
|
private boolean cache = true;
|
|
|
|
|
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).
|
2016-03-16 22:41:06 +00:00
|
|
|
*
|
|
|
|
* @param minimumOffset
|
|
|
|
* -
|
|
|
|
* @param maximumOffset
|
|
|
|
* -
|
2015-12-31 16:25:24 +00:00
|
|
|
*/
|
2015-12-30 21:19:50 +00:00
|
|
|
public Rectangle(BlockPos minimumOffset, BlockPos maximumOffset)
|
|
|
|
{
|
|
|
|
setOffsets(minimumOffset, maximumOffset);
|
|
|
|
}
|
2015-12-31 18:50:38 +00:00
|
|
|
|
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));
|
|
|
|
}
|
2015-12-31 18:50:38 +00:00
|
|
|
|
2015-12-31 16:25:24 +00:00
|
|
|
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 21:01:47 +00:00
|
|
|
if (!cache || !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>();
|
|
|
|
|
2016-01-09 21:35:47 +00:00
|
|
|
for (int j = minimumOffset.getY(); j < maximumOffset.getY(); j++)
|
2015-12-30 21:19:50 +00:00
|
|
|
{
|
2016-01-09 21:35:47 +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 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
|
2016-03-16 22:41:06 +00:00
|
|
|
*
|
|
|
|
* @param offset1
|
|
|
|
* -
|
|
|
|
* @param offset2
|
|
|
|
* -
|
2015-12-30 21:19:50 +00:00
|
|
|
*/
|
|
|
|
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-31 21:01:47 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resetCache()
|
|
|
|
{
|
|
|
|
this.blockPosCache = new ArrayList<BlockPos>();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isWithinArea(BlockPos pos)
|
|
|
|
{
|
|
|
|
int x = pos.getX();
|
|
|
|
int y = pos.getY();
|
|
|
|
int z = pos.getZ();
|
|
|
|
|
|
|
|
return x >= minimumOffset.getX() && x < maximumOffset.getX() && y >= minimumOffset.getY() && y < maximumOffset.getY() && z >= minimumOffset.getZ() && z < maximumOffset.getZ();
|
|
|
|
}
|
2016-02-02 23:16:55 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void forEachRemaining(Consumer<? super BlockPos> action)
|
|
|
|
{
|
|
|
|
while (hasNext())
|
|
|
|
{
|
|
|
|
action.accept(next());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext()
|
|
|
|
{
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockPos next()
|
|
|
|
{
|
|
|
|
if (currentPosition != null)
|
|
|
|
{
|
|
|
|
int nextX = currentPosition.getX() + 1 >= maximumOffset.getX() ? minimumOffset.getX() : currentPosition.getX() + 1;
|
|
|
|
int nextZ = nextX == minimumOffset.getX() ? currentPosition.getZ() : (currentPosition.getZ() + 1 >= maximumOffset.getZ() ? minimumOffset.getZ() : currentPosition.getZ() + 1);
|
|
|
|
int nextY = nextZ == minimumOffset.getZ() ? currentPosition.getY() : currentPosition.getY() + 1;
|
|
|
|
currentPosition = new BlockPos(nextX, nextY, nextZ);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
currentPosition = minimumOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cachedPosition.add(currentPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2015-12-30 21:19:50 +00:00
|
|
|
}
|
2016-01-11 23:07:06 +00:00
|
|
|
|
|
|
|
public static class HemiSphere extends AreaDescriptor
|
|
|
|
{
|
|
|
|
private BlockPos minimumOffset;
|
|
|
|
private int radius;
|
|
|
|
|
|
|
|
private ArrayList<BlockPos> blockPosCache;
|
|
|
|
private BlockPos cachedPosition;
|
|
|
|
|
|
|
|
private boolean cache = true;
|
|
|
|
|
|
|
|
public HemiSphere(BlockPos minimumOffset, int radius)
|
|
|
|
{
|
|
|
|
setRadius(minimumOffset, radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRadius(BlockPos minimumOffset, int radius)
|
|
|
|
{
|
|
|
|
this.minimumOffset = new BlockPos(Math.min(minimumOffset.getX(), minimumOffset.getX()), Math.min(minimumOffset.getY(), minimumOffset.getY()), Math.min(minimumOffset.getZ(), minimumOffset.getZ()));
|
|
|
|
this.radius = radius;
|
|
|
|
blockPosCache = new ArrayList<BlockPos>();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<BlockPos> getContainedPositions(BlockPos pos)
|
|
|
|
{
|
|
|
|
if (!cache || !pos.equals(cachedPosition) || blockPosCache.isEmpty())
|
|
|
|
{
|
|
|
|
ArrayList<BlockPos> posList = new ArrayList<BlockPos>();
|
|
|
|
|
|
|
|
int i = -radius;
|
|
|
|
int j = minimumOffset.getY();
|
|
|
|
int k = -radius;
|
|
|
|
|
|
|
|
//TODO For some reason the bottom of the hemisphere is not going up with the minOffset
|
|
|
|
|
|
|
|
while (i <= radius)
|
|
|
|
{
|
|
|
|
while (j <= radius)
|
|
|
|
{
|
|
|
|
while (k <= radius)
|
|
|
|
{
|
|
|
|
if (i * i + j * j + k * k >= (radius + 0.5F) * (radius + 0.5F))
|
|
|
|
{
|
|
|
|
k++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
posList.add(pos.add(i, j, k));
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
|
|
|
|
k = -radius;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
j = minimumOffset.getY();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
blockPosCache = posList;
|
|
|
|
cachedPosition = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Collections.unmodifiableList(blockPosCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Since you can't make a box using a sphere, this returns null
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getAABB(BlockPos pos)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resetCache()
|
|
|
|
{
|
|
|
|
this.blockPosCache = new ArrayList<BlockPos>();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isWithinArea(BlockPos pos)
|
|
|
|
{
|
|
|
|
return blockPosCache.contains(pos);
|
|
|
|
}
|
2016-02-02 23:16:55 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void forEachRemaining(Consumer<? super BlockPos> arg0)
|
|
|
|
{
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext()
|
|
|
|
{
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockPos next()
|
|
|
|
{
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove()
|
|
|
|
{
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
2016-01-11 23:07:06 +00:00
|
|
|
}
|
2016-02-18 16:25:11 +00:00
|
|
|
|
|
|
|
public static class Cross extends AreaDescriptor
|
|
|
|
{
|
|
|
|
|
|
|
|
private ArrayList<BlockPos> blockPosCache;
|
|
|
|
private BlockPos cachedPosition;
|
|
|
|
|
|
|
|
private BlockPos centerPos;
|
|
|
|
private int size;
|
|
|
|
|
|
|
|
private boolean cache = true;
|
|
|
|
|
|
|
|
public Cross(BlockPos center, int size)
|
|
|
|
{
|
|
|
|
this.centerPos = center;
|
|
|
|
this.size = size;
|
|
|
|
this.blockPosCache = new ArrayList<BlockPos>();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<BlockPos> getContainedPositions(BlockPos pos)
|
|
|
|
{
|
|
|
|
if (!cache || !pos.equals(cachedPosition) || blockPosCache.isEmpty())
|
|
|
|
{
|
|
|
|
resetCache();
|
|
|
|
|
|
|
|
blockPosCache.add(centerPos.add(pos));
|
|
|
|
for (int i = 1; i <= size; i++)
|
|
|
|
{
|
|
|
|
blockPosCache.add(centerPos.add(pos).add(i, 0, 0));
|
|
|
|
blockPosCache.add(centerPos.add(pos).add(0, 0, i));
|
|
|
|
blockPosCache.add(centerPos.add(pos).add(-i, 0, 0));
|
|
|
|
blockPosCache.add(centerPos.add(pos).add(0, 0, -i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cachedPosition = pos;
|
|
|
|
|
|
|
|
return Collections.unmodifiableList(blockPosCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resetCache()
|
|
|
|
{
|
|
|
|
blockPosCache = new ArrayList<BlockPos>();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isWithinArea(BlockPos pos)
|
|
|
|
{
|
|
|
|
return blockPosCache.contains(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockPos next()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2015-12-30 20:24:25 +00:00
|
|
|
}
|