Redefined the bounding for AreaDescriptor - it is now inclusive for the minimumOffset but is exclusive for the maximumOffset.

This commit is contained in:
WayofTime 2015-12-31 11:25:24 -05:00
parent 63da257260
commit 417114b6f0
5 changed files with 28 additions and 11 deletions

View file

@ -21,16 +21,34 @@ public class AreaDescriptor
public static class Rectangle extends AreaDescriptor public static class Rectangle extends AreaDescriptor
{ {
private BlockPos minimumOffset; private BlockPos minimumOffset;
private BlockPos maximumOffset; private BlockPos maximumOffset; // Non-inclusive maximum offset.
private ArrayList<BlockPos> blockPosCache = new ArrayList<BlockPos>(); private ArrayList<BlockPos> blockPosCache = new ArrayList<BlockPos>();
private BlockPos cachedPosition = new BlockPos(0, 0, 0); private BlockPos cachedPosition = new BlockPos(0, 0, 0);
/**
* 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
*/
public Rectangle(BlockPos minimumOffset, BlockPos maximumOffset) public Rectangle(BlockPos minimumOffset, BlockPos maximumOffset)
{ {
setOffsets(minimumOffset, maximumOffset); setOffsets(minimumOffset, maximumOffset);
} }
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);
}
@Override @Override
public List<BlockPos> getContainedPositions(BlockPos pos) public List<BlockPos> getContainedPositions(BlockPos pos)
{ {
@ -38,11 +56,11 @@ public class AreaDescriptor
{ {
ArrayList<BlockPos> posList = new ArrayList<BlockPos>(); ArrayList<BlockPos> posList = new ArrayList<BlockPos>();
for (int i = minimumOffset.getX(); i <= maximumOffset.getX(); i++) for (int i = minimumOffset.getX(); i < maximumOffset.getX(); i++)
{ {
for (int j = minimumOffset.getY(); j <= maximumOffset.getY(); j++) for (int j = minimumOffset.getY(); j < maximumOffset.getY(); j++)
{ {
for (int k = minimumOffset.getZ(); k <= maximumOffset.getZ(); k++) for (int k = minimumOffset.getZ(); k < maximumOffset.getZ(); k++)
{ {
posList.add(pos.add(i, j, k)); posList.add(pos.add(i, j, k));
} }
@ -53,14 +71,13 @@ public class AreaDescriptor
cachedPosition = pos; cachedPosition = pos;
} }
return blockPosCache; return blockPosCache;
} }
@Override @Override
public AxisAlignedBB getAABB(BlockPos pos) public AxisAlignedBB getAABB(BlockPos pos)
{ {
AxisAlignedBB tempAABB = new AxisAlignedBB(minimumOffset.getX(), minimumOffset.getY(), minimumOffset.getZ(), maximumOffset.getX() + 1, maximumOffset.getY() + 1, maximumOffset.getZ() + 1); AxisAlignedBB tempAABB = new AxisAlignedBB(minimumOffset, maximumOffset);
return tempAABB.offset(pos.getX(), pos.getY(), pos.getZ()); return tempAABB.offset(pos.getX(), pos.getY(), pos.getZ());
} }

View file

@ -25,7 +25,7 @@ public class RitualGreenGrove extends Ritual
public RitualGreenGrove() public RitualGreenGrove()
{ {
super("ritualGreenGrove", 0, 1000, "ritual." + Constants.Mod.MODID + ".greenGroveRitual"); super("ritualGreenGrove", 0, 1000, "ritual." + Constants.Mod.MODID + ".greenGroveRitual");
addBlockRange(GROW_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-1, 2, -1), new BlockPos(1, 2, 1))); addBlockRange(GROW_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-1, 2, -1), 3, 1, 3));
} }
@Override @Override

View file

@ -24,7 +24,7 @@ public class RitualJumping extends Ritual
public RitualJumping() public RitualJumping()
{ {
super("ritualJump", 0, 1000, "ritual." + Constants.Mod.MODID + ".jumpRitual"); super("ritualJump", 0, 1000, "ritual." + Constants.Mod.MODID + ".jumpRitual");
addBlockRange(JUMP_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-1, 1, -1), new BlockPos(1, 2, 1))); addBlockRange(JUMP_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-1, 1, -1), 3, 1, 3));
} }
@Override @Override

View file

@ -17,7 +17,7 @@ public class RitualLava extends Ritual
public RitualLava() public RitualLava()
{ {
super("ritualLava", 0, 10000, "ritual." + Constants.Mod.MODID + ".lavaRitual"); super("ritualLava", 0, 10000, "ritual." + Constants.Mod.MODID + ".lavaRitual");
addBlockRange(LAVA_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 1, 0), new BlockPos(0, 1, 0))); addBlockRange(LAVA_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 1, 0), 1));
} }
@Override @Override

View file

@ -17,7 +17,7 @@ public class RitualWater extends Ritual
public RitualWater() public RitualWater()
{ {
super("ritualWater", 0, 500, "ritual." + Constants.Mod.MODID + ".waterRitual"); super("ritualWater", 0, 500, "ritual." + Constants.Mod.MODID + ".waterRitual");
addBlockRange(WATER_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 1, 0), new BlockPos(0, 1, 0))); addBlockRange(WATER_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 1, 0), 1));
} }
@Override @Override