Added getNewCopy() to Ritual to allow tiles to hold their own copy of a Ritual. Created caching in AreaDescriptor for faster BlockPos access.

This commit is contained in:
WayofTime 2015-12-31 08:01:39 -05:00
parent 69355f76fb
commit d7a96c061d
7 changed files with 72 additions and 14 deletions

View file

@ -23,6 +23,9 @@ public class AreaDescriptor
private BlockPos minimumOffset;
private BlockPos maximumOffset;
private ArrayList<BlockPos> blockPosCache = new ArrayList<BlockPos>();
private BlockPos cachedPosition = new BlockPos(0, 0, 0);
public Rectangle(BlockPos minimumOffset, BlockPos maximumOffset)
{
setOffsets(minimumOffset, maximumOffset);
@ -31,22 +34,29 @@ public class AreaDescriptor
@Override
public List<BlockPos> getContainedPositions(BlockPos pos)
{
ArrayList<BlockPos> posList = new ArrayList<BlockPos>();
for (int i = minimumOffset.getX(); i <= maximumOffset.getX(); i++)
if (!pos.equals(cachedPosition) || blockPosCache.isEmpty())
{
for (int j = minimumOffset.getY(); j <= maximumOffset.getY(); j++)
ArrayList<BlockPos> posList = new ArrayList<BlockPos>();
for (int i = minimumOffset.getX(); i <= maximumOffset.getX(); i++)
{
for (int k = minimumOffset.getZ(); k <= maximumOffset.getZ(); k++)
for (int j = minimumOffset.getY(); j <= maximumOffset.getY(); j++)
{
posList.add(pos.add(i, j, k));
for (int k = minimumOffset.getZ(); k <= maximumOffset.getZ(); k++)
{
posList.add(pos.add(i, j, k));
}
}
}
blockPosCache = posList;
cachedPosition = pos;
}
return posList;
return blockPosCache;
}
@Override
public AxisAlignedBB getAABB(BlockPos pos)
{
@ -65,6 +75,7 @@ public class AreaDescriptor
{
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()));
blockPosCache = new ArrayList<BlockPos>();
}
}
}

View file

@ -31,7 +31,7 @@ public abstract class Ritual
private final RitualRenderer renderer;
private final String unlocalizedName;
private final Map<String, AreaDescriptor> modableRangeMap = new HashMap<String, AreaDescriptor>();
protected final Map<String, AreaDescriptor> modableRangeMap = new HashMap<String, AreaDescriptor>();
/**
* @param name
@ -165,4 +165,6 @@ public abstract class Ritual
{
REDSTONE, BREAK_MRS, BREAK_STONE, ACTIVATE, DEACTIVATE, EXPLOSION,
}
public abstract Ritual getNewCopy();
}