Vect cleanup

This commit is contained in:
mezz committed 2015-07-20 21:51:27 -07:00
1 parent e04bbcba84
commit d24eb693e9
13 files changed
+46 -29

No files matched your search

@@ -47,8 +47,8 @@ public class AlleleEffectGlacial extends AlleleEffectThrottled {
}
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
Vect area = new Vect(areaAr);
Vect offset = area.multiply(-1 / 2.0f);
Vect housingCoords = new Vect(housing.getCoordinates());
for (int i = 0; i < 10; i++) {
@@ -48,8 +48,8 @@ public class AlleleEffectRadioactive extends AlleleEffectThrottled {
}
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0] * 2, areaAr[1] * 2, areaAr[2] * 2);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
Vect area = new Vect(areaAr).multiply(2);
Vect offset = area.multiply(-1 / 2.0f);
// Radioactivity hurts players and mobs
Vect min = new Vect(housing.getCoordinates()).add(offset);
@@ -89,7 +89,7 @@ public class AlleleEffectRadioactive extends AlleleEffectThrottled {
// Radioactivity destroys environment
for (int i = 0; i < 20; i++) {
Vect randomPos = new Vect(rand.nextInt(area.x), rand.nextInt(area.y), rand.nextInt(area.z));
Vect randomPos = Vect.getRandomPositionInArea(rand, area);
Vect posHousing = new Vect(housing.getCoordinates());
Vect posBlock = randomPos.add(posHousing);
@@ -50,12 +50,12 @@ public class AlleleEffectSnowing extends AlleleEffectThrottled {
}
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
Vect area = new Vect(areaAr);
Vect offset = area.multiply(-1 / 2.0f);
for (int i = 0; i < 1; i++) {
Vect randomPos = new Vect(world.rand.nextInt(area.x), world.rand.nextInt(area.y), world.rand.nextInt(area.z));
Vect randomPos = Vect.getRandomPositionInArea(world.rand, area);
Vect posBlock = randomPos.add(new Vect(housing.getCoordinates()));
posBlock = posBlock.add(offset);
@@ -106,8 +106,8 @@ public abstract class AlleleEffectThrottled extends AlleleCategorized implements
protected AxisAlignedBB getBounding(IBeeGenome genome, IBeeHousing housing, float modifier) {
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(modifier);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
Vect area = new Vect(areaAr).multiply(modifier);
Vect offset = area.multiply(-1 / 2.0f);
Vect min = new Vect(housing.getCoordinates()).add(offset);
Vect max = min.add(area);
@@ -37,8 +37,8 @@ public class JubilanceProviderHermit extends JubilanceDefault {
private static AxisAlignedBB getBounding(IBeeGenome genome, IBeeHousing housing, float modifier) {
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(modifier);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
Vect area = new Vect(areaAr).multiply(modifier);
Vect offset = area.multiply(-1 / 2.0f);
ChunkCoordinates housingCoordinates = housing.getCoordinates();
@@ -49,11 +49,11 @@ public class AlleleLeafEffectNone extends AlleleCategorized implements IAlleleLe
protected static AxisAlignedBB getBounding(int x, int y, int z, float modifier) {
int[] areaAr = DEFAULT_EFFECT_AREA;
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(modifier);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
Vect area = new Vect(areaAr).multiply(modifier);
Vect offset = area.multiply(-1 / 2.0f);
Vect min = new Vect(x + offset.x, y + offset.y, y + offset.z);
Vect max = new Vect(x + offset.x + area.x, y + offset.y + area.y, y + offset.z + area.z);
Vect min = offset.add(x, y, z);
Vect max = min.add(area);
return AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
}
@@ -18,7 +18,6 @@ import com.mojang.authlib.GameProfile;
import forestry.api.world.ITreeGenData;
import forestry.arboriculture.gadgets.TileSapling;
import forestry.core.utils.Utils;
import forestry.core.vect.Vect;
import forestry.core.worldgen.BlockType;
import forestry.core.worldgen.WorldGenBase;
@@ -85,10 +84,6 @@ public abstract class WorldGenArboriculture extends WorldGenBase {
public abstract BlockType getWood();
public final Vect getStartVector() {
return new Vect(startX, startY, startZ);
}
protected void generateTreeTrunk(int height, int girth) {
generateTreeTrunk(height, girth, 0);
}
@@ -30,6 +30,12 @@ public class MutableVect implements IVect {
this.z = z;
}
public MutableVect(ForgeDirection direction) {
this.x = direction.offsetX;
this.y = direction.offsetY;
this.z = direction.offsetZ;
}
public MutableVect(int[] dim) {
if (dim.length != 3) {
throw new RuntimeException("Cannot instantiate a vector with less or more than 3 points.");
+20 -1
View File
@@ -13,6 +13,7 @@ package forestry.core.vect;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraftforge.common.util.ForgeDirection;
@@ -38,7 +39,15 @@ public class Vect implements IVect {
}
public Vect(IVect vect) {
this(vect.getX(), vect.getY(), vect.getZ());
this.x = vect.getX();
this.y = vect.getY();
this.z = vect.getZ();
}
public Vect(ForgeDirection direction) {
this.x = direction.offsetX;
this.y = direction.offsetY;
this.z = direction.offsetZ;
}
public Vect(int x, int y, int z) {
@@ -53,6 +62,12 @@ public class Vect implements IVect {
this.z = coordinates.posZ;
}
public Vect(TileEntity entity) {
this.x = entity.xCoord;
this.y = entity.yCoord;
this.z = entity.zCoord;
}
public Vect(Entity entity) {
this.x = (int) Math.round(entity.posX);
this.y = (int) Math.round(entity.posY);
@@ -103,6 +118,10 @@ public class Vect implements IVect {
return new int[]{x, y, z};
}
public Vect multiply(int factor) {
return new Vect(x * factor, y * factor, z * factor);
}
public Vect multiply(float factor) {
return new Vect(Math.round(x * factor), Math.round(y * factor), Math.round(z * factor));
}
@@ -16,8 +16,6 @@ import net.minecraft.init.Blocks;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmLogic;
@@ -59,8 +57,7 @@ public abstract class FarmLogic implements IFarmLogic {
}
protected final Vect translateWithOffset(int x, int y, int z, FarmDirection farmDirection, int step) {
ForgeDirection direction = farmDirection.getForgeDirection();
return new Vect(x + direction.offsetX * step, y + direction.offsetY * step, z + direction.offsetZ * step);
return new Vect(farmDirection.getForgeDirection()).multiply(step).add(x, y, z);
}
protected final void setBlock(Vect position, Block block, int meta) {
@@ -199,7 +199,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
for (int i = -1; i < 2; i++) {
for (int j = yOffset; j < 2; j++) {
for (int k = -1; k < 2; k++) {
Vect candidate = new Vect(position.x + i, position.y + j, position.z + k);
Vect candidate = position.add(i, j, k);
if (candidate.equals(position)) {
continue;
}
@@ -200,7 +200,7 @@ public class FarmLogicCocoa extends FarmLogic {
for (int i = -1; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = -1; k < 2; k++) {
Vect candidate = new Vect(position.x + i, position.y + j, position.z + k);
Vect candidate = position.add(i, j, k);
if (candidate.equals(position)) {
continue;
}
@@ -158,7 +158,7 @@ public class FarmLogicOrchard extends FarmLogic {
for (int i = -2; i < 3; i++) {
for (int j = 0; j < 2; j++) {
for (int k = -1; k < 2; k++) {
Vect candidate = new Vect(position.x + i, position.y + j, position.z + k);
Vect candidate = position.add(i, j, k);
if (Math.abs(candidate.x - start.x) > 5) {
continue;
}