use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class ProgWidgetArea method getArea.
@Override
public void getArea(Set<ChunkPosition> area) {
ChunkPosition[] areaPoints = getAreaPoints();
if (areaPoints[0] == null && areaPoints[1] == null)
return;
int minX;
int minY;
int minZ;
int maxX;
int maxY;
int maxZ;
if (areaPoints[1] != null) {
minX = Math.min(areaPoints[0].chunkPosX, areaPoints[1].chunkPosX);
minY = Math.min(areaPoints[0].chunkPosY, areaPoints[1].chunkPosY);
minZ = Math.min(areaPoints[0].chunkPosZ, areaPoints[1].chunkPosZ);
maxX = Math.max(areaPoints[0].chunkPosX, areaPoints[1].chunkPosX);
maxY = Math.max(areaPoints[0].chunkPosY, areaPoints[1].chunkPosY);
maxZ = Math.max(areaPoints[0].chunkPosZ, areaPoints[1].chunkPosZ);
} else {
minX = maxX = areaPoints[0].chunkPosX;
minY = maxY = areaPoints[0].chunkPosY;
minZ = maxZ = areaPoints[0].chunkPosZ;
}
int size = (maxX - minX) * (maxY - minY) * (maxZ - minZ);
if (size > 100000) {
//Prevent memory problems when getting to ridiculous areas.
if (aiManager != null)
aiManager.getDrone().overload();
return;
}
switch(type) {
case FILL:
for (int x = minX; x <= maxX; x++) {
for (int y = Math.min(255, maxY); y >= minY && y >= 0; y--) {
for (int z = minZ; z <= maxZ; z++) {
area.add(new ChunkPosition(x, y, z));
}
}
}
break;
case FRAME:
for (int x = minX; x <= maxX; x++) {
for (int y = Math.max(0, minY); y <= maxY && y < 256; y++) {
for (int z = minZ; z <= maxZ; z++) {
int axisRight = 0;
if (x == minX || x == maxX)
axisRight++;
if (y == minY || y == maxY)
axisRight++;
if (z == minZ || z == maxZ)
axisRight++;
if (axisRight > 1) {
area.add(new ChunkPosition(x, y, z));
}
}
}
}
break;
case WALL:
for (int x = minX; x <= maxX; x++) {
for (int y = Math.max(0, minY); y <= maxY && y < 256; y++) {
for (int z = minZ; z <= maxZ; z++) {
if (x == minX || x == maxX || y == minY || y == maxY || z == minZ || z == maxZ) {
area.add(new ChunkPosition(x, y, z));
}
}
}
}
break;
case SPHERE:
double radius = areaPoints[1] != null ? PneumaticCraftUtils.distBetween(areaPoints[0], areaPoints[1]) : 0;
minX = (int) (areaPoints[0].chunkPosX - radius - 1);
minY = (int) (areaPoints[0].chunkPosY - radius - 1);
minZ = (int) (areaPoints[0].chunkPosZ - radius - 1);
maxX = (int) (areaPoints[0].chunkPosX + radius + 1);
maxY = (int) (areaPoints[0].chunkPosY + radius + 1);
maxZ = (int) (areaPoints[0].chunkPosZ + radius + 1);
for (int x = minX; x <= maxX; x++) {
for (int y = Math.max(0, minY); y <= maxY && y < 256; y++) {
for (int z = minZ; z <= maxZ; z++) {
if (PneumaticCraftUtils.distBetween(areaPoints[0], x + 0.5, y + 0.5, z + 0.5) <= radius) {
area.add(new ChunkPosition(x, y, z));
}
}
}
}
break;
case LINE:
if (areaPoints[1] != null) {
Vec3 lineVec = Vec3.createVectorHelper(areaPoints[1].chunkPosX - areaPoints[0].chunkPosX, areaPoints[1].chunkPosY - areaPoints[0].chunkPosY, areaPoints[1].chunkPosZ - areaPoints[0].chunkPosZ).normalize();
lineVec.xCoord /= 10;
lineVec.yCoord /= 10;
lineVec.zCoord /= 10;
double curX = areaPoints[0].chunkPosX + 0.5;
double curY = areaPoints[0].chunkPosY + 0.5;
double curZ = areaPoints[0].chunkPosZ + 0.5;
double totalDistance = 0;
double maxDistance = PneumaticCraftUtils.distBetween(areaPoints[0], areaPoints[1]);
while (totalDistance <= maxDistance) {
totalDistance += 0.1;
curX += lineVec.xCoord;
curY += lineVec.yCoord;
curZ += lineVec.zCoord;
if (curY >= 0 && curY < 256) {
ChunkPosition pos = new ChunkPosition((int) curX, (int) curY, (int) curZ);
if (!area.contains(pos))
area.add(pos);
}
}
}
break;
case X_WALL:
if (areaPoints[1] != null) {
Vec3 lineVec = Vec3.createVectorHelper(0, areaPoints[1].chunkPosY - areaPoints[0].chunkPosY, areaPoints[1].chunkPosZ - areaPoints[0].chunkPosZ).normalize();
lineVec.yCoord /= 10;
lineVec.zCoord /= 10;
double curY = areaPoints[0].chunkPosY + 0.5;
double curZ = areaPoints[0].chunkPosZ + 0.5;
double totalDistance = 0;
double maxDistance = Math.sqrt(Math.pow(areaPoints[0].chunkPosY - areaPoints[1].chunkPosY, 2) + Math.pow(areaPoints[0].chunkPosZ - areaPoints[1].chunkPosZ, 2));
while (totalDistance <= maxDistance) {
totalDistance += 0.1;
curY += lineVec.yCoord;
curZ += lineVec.zCoord;
for (int i = minX; i <= maxX; i++) {
if (curY >= 0 && curY < 256) {
ChunkPosition pos = new ChunkPosition(i, (int) curY, (int) curZ);
if (!area.contains(pos))
area.add(pos);
}
}
}
}
break;
case Y_WALL:
if (areaPoints[1] != null) {
Vec3 lineVec = Vec3.createVectorHelper(areaPoints[1].chunkPosX - areaPoints[0].chunkPosX, 0, areaPoints[1].chunkPosZ - areaPoints[0].chunkPosZ).normalize();
lineVec.xCoord /= 10;
lineVec.zCoord /= 10;
double curX = areaPoints[0].chunkPosX + 0.5;
double curZ = areaPoints[0].chunkPosZ + 0.5;
double totalDistance = 0;
double maxDistance = Math.sqrt(Math.pow(areaPoints[0].chunkPosX - areaPoints[1].chunkPosX, 2) + Math.pow(areaPoints[0].chunkPosZ - areaPoints[1].chunkPosZ, 2));
while (totalDistance <= maxDistance) {
totalDistance += 0.1;
curX += lineVec.xCoord;
curZ += lineVec.zCoord;
for (int i = Math.max(0, minY); i <= Math.min(maxY, 255); i++) {
ChunkPosition pos = new ChunkPosition((int) curX, i, (int) curZ);
if (!area.contains(pos))
area.add(pos);
}
}
}
break;
case Z_WALL:
if (areaPoints[1] != null) {
Vec3 lineVec = Vec3.createVectorHelper(areaPoints[1].chunkPosX - areaPoints[0].chunkPosX, areaPoints[1].chunkPosY - areaPoints[0].chunkPosY, 0).normalize();
lineVec.xCoord /= 10;
lineVec.yCoord /= 10;
double curX = areaPoints[0].chunkPosX + 0.5;
double curY = areaPoints[0].chunkPosY + 0.5;
double totalDistance = 0;
double maxDistance = Math.sqrt(Math.pow(areaPoints[0].chunkPosX - areaPoints[1].chunkPosX, 2) + Math.pow(areaPoints[0].chunkPosY - areaPoints[1].chunkPosY, 2));
while (totalDistance <= maxDistance) {
totalDistance += 0.1;
curX += lineVec.xCoord;
curY += lineVec.yCoord;
for (int i = minZ; i <= maxZ; i++) {
if (curY >= 0 && curY < 256) {
ChunkPosition pos = new ChunkPosition((int) curX, (int) curY, i);
if (!area.contains(pos))
area.add(pos);
}
}
}
}
break;
case X_CYLINDER:
if (areaPoints[1] != null) {
double rad = areaPoints[1] != null ? PneumaticCraftUtils.distBetween(areaPoints[0].chunkPosY, areaPoints[0].chunkPosZ, areaPoints[1].chunkPosY, areaPoints[1].chunkPosZ) : 0;
minY = (int) (areaPoints[0].chunkPosY - rad - 1);
minZ = (int) (areaPoints[0].chunkPosZ - rad - 1);
maxY = (int) (areaPoints[0].chunkPosY + rad + 1);
maxZ = (int) (areaPoints[0].chunkPosZ + rad + 1);
for (int y = Math.max(0, minY); y <= maxY && y < 256; y++) {
for (int z = minZ; z <= maxZ; z++) {
if (PneumaticCraftUtils.distBetween(areaPoints[0].chunkPosY, areaPoints[0].chunkPosZ, y, z) <= rad) {
for (int x = minX; x <= maxX; x++) {
area.add(new ChunkPosition(x, y, z));
}
}
}
}
}
break;
case Y_CYLINDER:
if (areaPoints[1] != null) {
double rad = areaPoints[1] != null ? PneumaticCraftUtils.distBetween(areaPoints[0].chunkPosX, areaPoints[0].chunkPosZ, areaPoints[1].chunkPosX, areaPoints[1].chunkPosZ) : 0;
minX = (int) (areaPoints[0].chunkPosX - rad - 1);
minZ = (int) (areaPoints[0].chunkPosZ - rad - 1);
maxX = (int) (areaPoints[0].chunkPosX + rad + 1);
maxZ = (int) (areaPoints[0].chunkPosZ + rad + 1);
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
if (PneumaticCraftUtils.distBetween(areaPoints[0].chunkPosX, areaPoints[0].chunkPosZ, x, z) <= rad) {
for (int y = Math.max(0, minY); y <= maxY && y < 256; y++) {
area.add(new ChunkPosition(x, y, z));
}
}
}
}
}
break;
case Z_CYLINDER:
if (areaPoints[1] != null) {
double rad = areaPoints[1] != null ? PneumaticCraftUtils.distBetween(areaPoints[0].chunkPosX, areaPoints[0].chunkPosY, areaPoints[1].chunkPosX, areaPoints[1].chunkPosY) : 0;
minX = (int) (areaPoints[0].chunkPosX - rad - 1);
minY = (int) (areaPoints[0].chunkPosY - rad - 1);
maxX = (int) (areaPoints[0].chunkPosX + rad + 1);
maxY = (int) (areaPoints[0].chunkPosY + rad + 1);
for (int x = minX; x <= maxX; x++) {
for (int y = Math.max(0, minY); y <= maxY && y < 256; y++) {
if (PneumaticCraftUtils.distBetween(areaPoints[0].chunkPosX, areaPoints[0].chunkPosY, x, y) <= rad) {
for (int z = minZ; z <= maxZ; z++) {
area.add(new ChunkPosition(x, y, z));
}
}
}
}
}
break;
case X_PYRAMID:
if (areaPoints[1] != null && areaPoints[1].chunkPosX != areaPoints[0].chunkPosX) {
Vec3 lineVec = Vec3.createVectorHelper(areaPoints[1].chunkPosX - areaPoints[0].chunkPosX, areaPoints[1].chunkPosY - areaPoints[0].chunkPosY, areaPoints[1].chunkPosZ - areaPoints[0].chunkPosZ).normalize();
lineVec.yCoord /= lineVec.xCoord;
lineVec.zCoord /= lineVec.xCoord;
double curY = areaPoints[0].chunkPosY - lineVec.yCoord;
int x = areaPoints[0].chunkPosX + (areaPoints[1].chunkPosX > areaPoints[0].chunkPosX ? -1 : 1);
double curZ = areaPoints[0].chunkPosZ - lineVec.zCoord;
while (x != areaPoints[1].chunkPosX) {
x += areaPoints[1].chunkPosX > areaPoints[0].chunkPosX ? 1 : -1;
curY += lineVec.yCoord;
curZ += lineVec.zCoord;
int dY = Math.abs((int) (curY - areaPoints[0].chunkPosY));
int dZ = Math.abs((int) (curZ - areaPoints[0].chunkPosZ));
for (int y = areaPoints[0].chunkPosY - dY; y <= areaPoints[0].chunkPosY + dY; y++) {
for (int z = areaPoints[0].chunkPosZ - dZ; z <= areaPoints[0].chunkPosZ + dZ; z++) {
if (y > 0 && y < 256)
area.add(new ChunkPosition(x, y, z));
}
}
}
}
break;
case Y_PYRAMID:
if (areaPoints[1] != null && areaPoints[1].chunkPosY != areaPoints[0].chunkPosY) {
Vec3 lineVec = Vec3.createVectorHelper(areaPoints[1].chunkPosX - areaPoints[0].chunkPosX, areaPoints[1].chunkPosY - areaPoints[0].chunkPosY, areaPoints[1].chunkPosZ - areaPoints[0].chunkPosZ).normalize();
lineVec.xCoord /= lineVec.yCoord;
lineVec.zCoord /= lineVec.yCoord;
double curX = areaPoints[0].chunkPosX - lineVec.xCoord;
int y = areaPoints[0].chunkPosY + (areaPoints[1].chunkPosY > areaPoints[0].chunkPosY ? -1 : 1);
double curZ = areaPoints[0].chunkPosZ - lineVec.zCoord;
while (y != areaPoints[1].chunkPosY) {
y += areaPoints[1].chunkPosY > areaPoints[0].chunkPosY ? 1 : -1;
curX += lineVec.xCoord;
curZ += lineVec.zCoord;
int dX = Math.abs((int) (curX - areaPoints[0].chunkPosX));
int dZ = Math.abs((int) (curZ - areaPoints[0].chunkPosZ));
for (int x = areaPoints[0].chunkPosX - dX; x <= areaPoints[0].chunkPosX + dX; x++) {
for (int z = areaPoints[0].chunkPosZ - dZ; z <= areaPoints[0].chunkPosZ + dZ; z++) {
if (y > 0 && y < 256)
area.add(new ChunkPosition(x, y, z));
}
}
}
}
break;
case Z_PYRAMID:
if (areaPoints[1] != null && areaPoints[1].chunkPosZ != areaPoints[0].chunkPosZ) {
Vec3 lineVec = Vec3.createVectorHelper(areaPoints[1].chunkPosX - areaPoints[0].chunkPosX, areaPoints[1].chunkPosY - areaPoints[0].chunkPosY, areaPoints[1].chunkPosZ - areaPoints[0].chunkPosZ).normalize();
lineVec.xCoord /= lineVec.zCoord;
lineVec.yCoord /= lineVec.zCoord;
double curX = areaPoints[0].chunkPosX - lineVec.xCoord;
int z = areaPoints[0].chunkPosZ + (areaPoints[1].chunkPosZ > areaPoints[0].chunkPosZ ? -1 : 1);
double curY = areaPoints[0].chunkPosY - lineVec.yCoord;
while (z != areaPoints[1].chunkPosZ) {
z += areaPoints[1].chunkPosZ > areaPoints[0].chunkPosZ ? 1 : -1;
curX += lineVec.xCoord;
curY += lineVec.yCoord;
int dX = Math.abs((int) (curX - areaPoints[0].chunkPosX));
int dY = Math.abs((int) (curY - areaPoints[0].chunkPosY));
for (int x = areaPoints[0].chunkPosX - dX; x <= areaPoints[0].chunkPosX + dX; x++) {
for (int y = areaPoints[0].chunkPosY - dY; y <= areaPoints[0].chunkPosY + dY; y++) {
if (y > 0 && y < 256)
area.add(new ChunkPosition(x, y, z));
}
}
}
}
break;
case GRID:
if (areaPoints[1] == null || areaPoints[0].equals(areaPoints[1]) || typeInfo <= 0) {
area.add(areaPoints[0]);
} else {
int interval = typeInfo;
for (int x = areaPoints[0].chunkPosX; areaPoints[0].chunkPosX < areaPoints[1].chunkPosX ? x <= areaPoints[1].chunkPosX : x >= areaPoints[1].chunkPosX; x += (areaPoints[0].chunkPosX < areaPoints[1].chunkPosX ? 1 : -1) * interval) {
for (int y = areaPoints[0].chunkPosY; areaPoints[0].chunkPosY < areaPoints[1].chunkPosY ? y <= areaPoints[1].chunkPosY : y >= areaPoints[1].chunkPosY; y += (areaPoints[0].chunkPosY < areaPoints[1].chunkPosY ? 1 : -1) * interval) {
for (int z = areaPoints[0].chunkPosZ; areaPoints[0].chunkPosZ < areaPoints[1].chunkPosZ ? z <= areaPoints[1].chunkPosZ : z >= areaPoints[1].chunkPosZ; z += (areaPoints[0].chunkPosZ < areaPoints[1].chunkPosZ ? 1 : -1) * interval) {
if (y > 0 && y < 256)
area.add(new ChunkPosition(x, y, z));
}
}
}
}
break;
case RANDOM:
type = EnumAreaType.FILL;
Set<ChunkPosition> filledArea = new HashSet<ChunkPosition>();
getArea(filledArea);
type = EnumAreaType.RANDOM;
if (typeInfo >= filledArea.size()) {
area.addAll(filledArea);
return;
}
Random rand = new Random();
Set<Integer> randomIndexes = new HashSet<Integer>();
while (randomIndexes.size() < typeInfo) {
randomIndexes.add(rand.nextInt(filledArea.size()));
}
int curIndex = 0;
for (ChunkPosition pos : filledArea) {
if (randomIndexes.contains(curIndex))
area.add(pos);
curIndex++;
}
break;
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class ItemAmadronTablet method getItemProvider.
public static IInventory getItemProvider(ItemStack tablet) {
ChunkPosition pos = getItemProvidingLocation(tablet);
if (pos != null) {
int dimension = getItemProvidingDimension(tablet);
TileEntity te = PneumaticCraftUtils.getTileEntity(pos, dimension);
return IOHelper.getInventoryForTE(te);
}
return null;
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class ItemAmadronTablet method addInformation.
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List infoList, boolean par4) {
super.addInformation(stack, player, infoList, par4);
ChunkPosition pos = getItemProvidingLocation(stack);
if (pos != null) {
int dim = getItemProvidingDimension(stack);
infoList.add(I18n.format("gui.tooltip.amadronTablet.itemLocation", pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, dim));
} else {
infoList.add(I18n.format("gui.tooltip.amadronTablet.selectItemLocation"));
}
pos = getLiquidProvidingLocation(stack);
if (pos != null) {
int dim = getLiquidProvidingDimension(stack);
infoList.add(I18n.format("gui.tooltip.amadronTablet.fluidLocation", pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ, dim));
} else {
infoList.add(I18n.format("gui.tooltip.amadronTablet.selectFluidLocation"));
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class ItemAmadronTablet method getLiquidProvidingLocation.
public static ChunkPosition getLiquidProvidingLocation(ItemStack tablet) {
NBTTagCompound compound = tablet.getTagCompound();
if (compound != null) {
int x = compound.getInteger("liquidX");
int y = compound.getInteger("liquidY");
int z = compound.getInteger("liquidZ");
if (x != 0 || y != 0 || z != 0) {
return new ChunkPosition(x, y, z);
} else {
return null;
}
} else {
return null;
}
}
use of net.minecraft.world.ChunkPosition in project PneumaticCraft by MineMaarten.
the class PacketCommandGetGlobalVariableOutput method fromBytes.
@Override
public void fromBytes(ByteBuf buf) {
varName = ByteBufUtils.readUTF8String(buf);
pos = new ChunkPosition(buf.readInt(), buf.readInt(), buf.readInt());
stack = ByteBufUtils.readItemStack(buf);
}
Aggregations