{
NBTTagCompound nbt = NBTUtility.getNBTTagCompound(itemStack);
if (nbt != null)
{
Vector3 point1 = new Vector3(nbt.getCompoundTag(NBT_POINT_1));
Vector3 point2 = new Vector3(nbt.getCompoundTag(NBT_POINT_2));
if (nbt.hasKey(NBT_POINT_1) && nbt.hasKey(NBT_POINT_2) && !point1.equals(point2))
{
if (point1.distance(point2) < Settings.MAX_FORCE_FIELD_SCALE)
{
// Clear NBT Data
nbt.removeTag(NBT_POINT_1);
nbt.removeTag(NBT_POINT_2);
Vector3 midPoint = new Vector3();
midPoint.x = (point1.x + point2.x) / 2;
midPoint.y = (point1.y + point2.y) / 2;
midPoint.z = (point1.z + point2.z) / 2;
midPoint = midPoint.floor();
// Center the two coords to origin.
point1.subtract(midPoint);
point2.subtract(midPoint);
Vector3 minPoint = new Vector3(Math.min(point1.x, point2.x), Math.min(point1.y, point2.y), Math.min(point1.z, point2.z));
Vector3 maxPoint = new Vector3(Math.max(point1.x, point2.x), Math.max(point1.y, point2.y), Math.max(point1.z, point2.z));
NBTTagCompound saveNBT = NBTUtility.loadData(this.getSaveDirectory(), NBT_FILE_SAVE_PREFIX + getModeID(itemStack));
if (saveNBT == null)
{
saveNBT = new NBTTagCompound();
}
NBTTagList list;
if (saveNBT.hasKey(NBT_FIELD_BLOCK_LIST))
{
list = (NBTTagList) saveNBT.getTag(NBT_FIELD_BLOCK_LIST);
}
else
{
list = new NBTTagList();
}
for (int x = minPoint.intX(); x <= maxPoint.intX(); x++)
{
for (int y = minPoint.intY(); y <= maxPoint.intY(); y++)
{
for (int z = minPoint.intZ(); z <= maxPoint.intZ(); z++)
{
Vector3 position = new Vector3(x, y, z);
Vector3 targetCheck = midPoint.clone().translate(position);
int blockID = targetCheck.getBlockID(world);
if (blockID > 0)
{
if (!nbt.getBoolean(NBT_MODE))
{
NBTTagCompound vectorTag = new NBTTagCompound();
position.writeToNBT(vectorTag);
vectorTag.setInteger(NBT_FIELD_BLOCK_ID, blockID);
vectorTag.setInteger(NBT_FIELD_BLOCK_METADATA, targetCheck.getBlockMetadata(world));
list.appendTag(vectorTag);
}
else
{
for (int i = 0; i < list.tagCount(); i++)
{
Vector3 vector = new Vector3((NBTTagCompound) list.tagAt(i));
if (vector.equals(position))
{
list.removeTag(i);
}
}
}