use of net.minecraft.util.EnumFacing.Axis in project BuildCraft by BuildCraft.
the class RenderResizableCuboid method getUVArray.
private static float[] getUVArray(TextureAtlasSprite sprite, int flips, EnumFacing face, Vec3d start, Vec3d end) {
Axis u = face.getAxis() == Axis.X ? Axis.Z : Axis.X;
Axis v = face.getAxis() == Axis.Y ? Axis.Z : Axis.Y;
float minU = sprite.getInterpolatedU(VecUtil.getValue(start, u) * 16);
float maxU = sprite.getInterpolatedU(VecUtil.getValue(end, u) * 16);
float minV = sprite.getInterpolatedV(VecUtil.getValue(start, v) * 16);
float maxV = sprite.getInterpolatedV(VecUtil.getValue(end, v) * 16);
float[] uvarray = new float[] { minU, maxU, minV, maxV };
if (flips % 2 == 1) {
float holder = uvarray[0];
uvarray[0] = uvarray[1];
uvarray[1] = holder;
}
if (flips >> 1 % 2 == 1) {
float holder = uvarray[2];
uvarray[2] = uvarray[3];
uvarray[3] = holder;
}
return uvarray;
}
use of net.minecraft.util.EnumFacing.Axis in project BuildCraft by BuildCraft.
the class RenderResizableCuboid method renderCuboidFace.
private static void renderCuboidFace(VertexBuffer vb, EnumFacing face, TextureAtlasSprite[] sprites, int[] flips, Vec3d textureStart, Vec3d textureSize, Vec3d size, Vec3d textureOffset, EnumShadeArgument shadeTypes, IBlockLocation locationFormula, IFacingLocation faceFormula, IBlockAccess access, boolean out, boolean in) {
int ordinal = face.ordinal();
if (sprites[ordinal] == null) {
return;
}
Vec3d textureEnd = textureStart.add(textureSize);
float[] uv = getUVArray(sprites[ordinal], flips[ordinal], face, textureStart, textureEnd);
List<RenderInfo> renderInfoList = getRenderInfos(uv, face, size, textureSize, textureOffset);
Axis u = face.getAxis() == Axis.X ? Axis.Z : Axis.X;
Axis v = face.getAxis() == Axis.Y ? Axis.Z : Axis.Y;
double other = face.getAxisDirection() == AxisDirection.POSITIVE ? VecUtil.getValue(size, face.getAxis()) : 0;
boolean flip = ModelUtil.shouldInvertForRender(face);
// Flip it to be negative as the light renderer doesn't handle light proeprly
face = face.getAxisDirection() == AxisDirection.NEGATIVE ? face : face.getOpposite();
EnumFacing opposite = face.getOpposite();
for (RenderInfo ri : renderInfoList) {
if (flip ? out : in) {
renderPoint(vb, face, u, v, other, ri, true, false, locationFormula, faceFormula, access, shadeTypes);
renderPoint(vb, face, u, v, other, ri, true, true, locationFormula, faceFormula, access, shadeTypes);
renderPoint(vb, face, u, v, other, ri, false, true, locationFormula, faceFormula, access, shadeTypes);
renderPoint(vb, face, u, v, other, ri, false, false, locationFormula, faceFormula, access, shadeTypes);
}
if (flip ? in : out) {
renderPoint(vb, opposite, u, v, other, ri, false, false, locationFormula, faceFormula, access, shadeTypes);
renderPoint(vb, opposite, u, v, other, ri, false, true, locationFormula, faceFormula, access, shadeTypes);
renderPoint(vb, opposite, u, v, other, ri, true, true, locationFormula, faceFormula, access, shadeTypes);
renderPoint(vb, opposite, u, v, other, ri, true, false, locationFormula, faceFormula, access, shadeTypes);
}
}
}
use of net.minecraft.util.EnumFacing.Axis in project BuildCraft by BuildCraft.
the class RenderResizableCuboid method getRenderInfos.
private static List<RenderInfo> getRenderInfos(float[] uv, EnumFacing face, Vec3d size, Vec3d texSize, Vec3d texOffset) {
Axis u = face.getAxis() == Axis.X ? Axis.Z : Axis.X;
Axis v = face.getAxis() == Axis.Y ? Axis.Z : Axis.Y;
double sizeU = VecUtil.getValue(size, u);
double sizeV = VecUtil.getValue(size, v);
double textureSizeU = VecUtil.getValue(texSize, u);
double textureSizeV = VecUtil.getValue(texSize, v);
double textureOffsetU = VecUtil.getValue(texOffset, u);
double textureOffsetV = VecUtil.getValue(texOffset, v);
return getRenderInfos(uv, sizeU, sizeV, textureSizeU, textureSizeV, textureOffsetU, textureOffsetV);
}
use of net.minecraft.util.EnumFacing.Axis in project BuildCraft by BuildCraft.
the class PatternSpherePart method fillTemplate.
@Override
public boolean fillTemplate(IFilledTemplate filledTemplate, IStatementParameter[] params) {
PatternParameterFacing facing = getParam(1, params, PatternParameterFacing.DOWN);
PatternParameterRotation rotation = getParam(2, params, PatternParameterRotation.NONE);
PatternParameterHollow hollow = getParam(0, params, PatternParameterHollow.FILLED_INNER);
Vec3d center;
Vec3d radius;
Set<EnumFacing> innerSides = EnumSet.noneOf(EnumFacing.class);
Vec3d max = new Vec3d(filledTemplate.getMax().getX(), filledTemplate.getMax().getY(), filledTemplate.getMax().getZ());
center = VecUtil.scale(max, 0.5);
radius = center.addVector(0.5, 0.5, 0.5);
innerSides.add(facing.face);
Axis axis = facing.face.getAxis();
Vec3d offset = VecUtil.offset(Vec3d.ZERO, facing.face, VecUtil.getValue(radius, axis));
center = center.add(offset);
radius = VecUtil.replaceValue(radius, axis, VecUtil.getValue(radius, axis) * 2);
if (type.openFaces > 1) {
Axis secondaryAxis;
if (rotation.rotationCount % 2 == 1) {
secondaryAxis = axis == Axis.X ? Axis.Y : axis == Axis.Y ? Axis.Z : Axis.X;
} else {
secondaryAxis = axis == Axis.X ? Axis.Z : axis == Axis.Y ? Axis.X : Axis.Y;
}
EnumFacing secondaryFace = VecUtil.getFacing(secondaryAxis, rotation.rotationCount >= 2);
innerSides.add(secondaryFace);
offset = VecUtil.offset(Vec3d.ZERO, secondaryFace, VecUtil.getValue(radius, secondaryAxis));
center = center.add(offset);
radius = VecUtil.replaceValue(radius, secondaryAxis, VecUtil.getValue(radius, secondaryAxis) * 2);
if (type.openFaces > 2) {
Axis tertiaryAxis;
int rotationCount = (rotation.rotationCount + 1) & 3;
if (rotationCount % 2 == 1) {
tertiaryAxis = axis == Axis.X ? Axis.Y : axis == Axis.Y ? Axis.Z : Axis.X;
} else {
tertiaryAxis = axis == Axis.X ? Axis.Z : axis == Axis.Y ? Axis.X : Axis.Y;
}
EnumFacing tertiaryFace = VecUtil.getFacing(tertiaryAxis, rotationCount >= 2);
innerSides.add(tertiaryFace);
offset = VecUtil.offset(Vec3d.ZERO, tertiaryFace, VecUtil.getValue(radius, tertiaryAxis));
center = center.add(offset);
radius = VecUtil.replaceValue(radius, tertiaryAxis, VecUtil.getValue(radius, tertiaryAxis) * 2);
}
}
double cx = center.x;
double cy = center.y;
double cz = center.z;
double rx = radius.x;
double ry = radius.y;
double rz = radius.z;
BitSet data = null;
if (hollow != PatternParameterHollow.FILLED_INNER) {
data = new BitSet(Snapshot.getDataSize(filledTemplate.getSize()));
}
for (int x = 0; x <= filledTemplate.getMax().getX(); x++) {
double dx = Math.abs(x - cx) / rx;
double dxx = dx * dx;
for (int y = 0; y <= filledTemplate.getMax().getY(); y++) {
double dy = Math.abs(y - cy) / ry;
double dyy = dy * dy;
for (int z = 0; z <= filledTemplate.getMax().getZ(); z++) {
double dz = Math.abs(z - cz) / rz;
double dzz = dz * dz;
if (dxx + dyy + dzz < 1) {
if (hollow != PatternParameterHollow.FILLED_INNER) {
// noinspection ConstantConditions
data.set(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z), true);
} else {
filledTemplate.set(x, y, z, true);
}
}
}
}
}
boolean outerFilled = hollow.outerFilled;
if (hollow != PatternParameterHollow.FILLED_INNER) {
// Z iteration
for (int x = 0; x <= filledTemplate.getMax().getX(); x++) {
for (int y = 0; y <= filledTemplate.getMax().getY(); y++) {
if (!innerSides.contains(EnumFacing.NORTH)) {
for (int z = 0; z <= filledTemplate.getMax().getZ(); z++) {
if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
filledTemplate.set(x, y, z, true);
break;
}
if (outerFilled) {
filledTemplate.set(x, y, z, true);
}
}
}
if (!innerSides.contains(EnumFacing.SOUTH)) {
for (int z = filledTemplate.getMax().getZ(); z >= 0; z--) {
if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
filledTemplate.set(x, y, z, true);
break;
}
if (outerFilled) {
filledTemplate.set(x, y, z, true);
}
}
}
}
}
// Y iteration
for (int x = 0; x <= filledTemplate.getMax().getX(); x++) {
for (int z = 0; z <= filledTemplate.getMax().getZ(); z++) {
if (!innerSides.contains(EnumFacing.DOWN)) {
for (int y = 0; y <= filledTemplate.getMax().getY(); y++) {
if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
filledTemplate.set(x, y, z, true);
break;
}
if (outerFilled) {
filledTemplate.set(x, y, z, true);
}
}
}
if (!innerSides.contains(EnumFacing.UP)) {
for (int y = filledTemplate.getMax().getY(); y >= 0; y--) {
if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
filledTemplate.set(x, y, z, true);
break;
}
if (outerFilled) {
filledTemplate.set(x, y, z, true);
}
}
}
}
}
// X iteration
for (int y = 0; y <= filledTemplate.getMax().getY(); y++) {
for (int z = 0; z <= filledTemplate.getMax().getZ(); z++) {
if (!innerSides.contains(EnumFacing.WEST)) {
for (int x = 0; x <= filledTemplate.getMax().getX(); x++) {
if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
filledTemplate.set(x, y, z, true);
break;
}
if (outerFilled) {
filledTemplate.set(x, y, z, true);
}
}
}
if (!innerSides.contains(EnumFacing.EAST)) {
for (int x = filledTemplate.getMax().getX(); x >= 0; x--) {
if (data.get(Snapshot.posToIndex(filledTemplate.getSize(), x, y, z))) {
filledTemplate.set(x, y, z, true);
break;
}
if (outerFilled) {
filledTemplate.set(x, y, z, true);
}
}
}
}
}
}
return true;
}
use of net.minecraft.util.EnumFacing.Axis in project BuildCraft by BuildCraft.
the class PipeModelCacheWire method generate.
private static ImmutableList<MutableQuad> generate(PipeWireKeySingle key) {
PipeWire wire = key.type;
Vec3d pos = wirePosMap.get(wire);
boolean isLit = key.on;
// BCLog.logger.info("generate[" + wire + ", " + isLit + ", " + key.connections + "]");
TextureAtlasSprite sprite = BuildCraftTransport.instance.wireIconProvider.getIcon(wire, isLit);
List<MutableQuad> unprocessed = new ArrayList<>();
Vec3d center = pos;
Vec3d centerSize = new Vec3d(WIRE_WIDTH, WIRE_WIDTH, WIRE_WIDTH);
AxisDirection[] directions = wireDirectionMap.get(wire);
int numFaces = 0;
for (EnumFacing face : EnumFacing.values()) {
boolean positive = face.getAxisDirection() == AxisDirection.POSITIVE;
Axis axis = face.getAxis();
AxisDirection wireCenter = directions[axis.ordinal()];
if (key.connections.contains(face)) {
if (wireCenter == face.getAxisDirection()) {
numFaces++;
}
numFaces++;
Vec3d start = pos;
Vec3d end = pos.add(centerSize);
if (positive) {
start = VecUtil.replaceValue(start, axis, VecUtil.getValue(start, axis) + WIRE_WIDTH);
end = VecUtil.replaceValue(end, axis, (double) 1);
} else {
start = VecUtil.replaceValue(start, axis, (double) 0);
end = VecUtil.replaceValue(end, axis, VecUtil.getValue(end, axis) - WIRE_WIDTH);
}
renderCuboid(unprocessed, start, end.subtract(start), sprite);
} else {
boolean anyOther = false;
for (EnumFacing face2 : EnumFacing.values()) {
if (face2.getOpposite() == face) {
continue;
}
anyOther |= key.connections.contains(face2);
}
if (anyOther) {
continue;
}
Vec3d start = pos;
Vec3d end = pos.add(centerSize);
if (positive) {
start = VecUtil.replaceValue(start, axis, VecUtil.getValue(start, axis) + WIRE_WIDTH);
end = VecUtil.replaceValue(end, axis, (double) CoreConstants.PIPE_MAX_POS);
} else {
start = VecUtil.replaceValue(start, axis, (double) CoreConstants.PIPE_MIN_POS);
end = VecUtil.replaceValue(end, axis, VecUtil.getValue(end, axis) - WIRE_WIDTH);
}
Vec3d size = end.subtract(start);
if (size.lengthVector() > WIRE_WIDTH * 2) {
renderCuboid(unprocessed, start, size, sprite);
}
}
}
if (numFaces != 1) {
renderCuboid(unprocessed, center, centerSize, sprite);
}
ImmutableList.Builder<MutableQuad> builder = ImmutableList.builder();
for (MutableQuad quad : unprocessed) {
if (isLit)
quad.lightf(1, 0);
quad.colourf(1, 1, 1, 1);
// quad.setCalculatedDiffuse();
builder.add(quad);
}
return builder.build();
}
Aggregations