use of com.infinityraider.agricraft.api.v1.genetics.IAgriGenePair in project AgriCraft by AgriCraft.
the class AgriGenomeRenderer method drawHelix.
protected void drawHelix(List<IAgriGenePair<?>> genePairs, int active, float radius, float phase, float dHeight, float dAngle, int points, IRenderTypeBuffer buffer, Matrix4f matrix, boolean dominant, float alpha, boolean color) {
float x_1 = radius * MathHelper.cos(-phase);
float y_1 = dHeight * points;
float z_1 = radius * MathHelper.sin(-phase);
for (int i = 0; i < points; i++) {
// Determine color and width
int index = i / POINTS_PER_GENE;
int partial = i % POINTS_PER_GENE;
IAgriGene<?> gene = genePairs.get(index).getGene();
Vector3f colorVec = this.getColor(gene, index == active, dominant, color);
float r = colorVec.getX();
float g = colorVec.getY();
float b = colorVec.getZ();
float w = this.getLineWidth(index == active);
if (partial < POINTS_PER_GENE / 2) {
int prevIndex = (index - 1) < 0 ? index : index - 1;
IAgriGene<?> prevGene = genePairs.get(prevIndex).getGene();
Vector3f prevColor = this.getColor(prevGene, prevIndex == active, dominant, color);
float prevWidth = this.getLineWidth(prevIndex == active);
float f = (partial + ((POINTS_PER_GENE + 0.0F) / 2)) / POINTS_PER_GENE;
r = MathHelper.lerp(f, prevColor.getX(), r);
g = MathHelper.lerp(f, prevColor.getY(), g);
b = MathHelper.lerp(f, prevColor.getZ(), b);
w = MathHelper.lerp(f, prevWidth, w);
} else if (partial > POINTS_PER_GENE / 2) {
int nextIndex = (index + 1) >= genePairs.size() ? index : index + 1;
IAgriGene<?> nextGene = genePairs.get(nextIndex).getGene();
Vector3f nextColor = this.getColor(nextGene, nextIndex == active, dominant, color);
float nextWidth = this.getLineWidth(nextIndex == active);
float f = (partial - ((POINTS_PER_GENE + 0.0F) / 2)) / POINTS_PER_GENE;
r = MathHelper.lerp(f, r, nextColor.getX());
g = MathHelper.lerp(f, g, nextColor.getY());
b = MathHelper.lerp(f, b, nextColor.getZ());
w = MathHelper.lerp(f, w, nextWidth);
}
// Determine coordinates
float x_2 = radius * MathHelper.cos(-((1 + i) * dAngle + phase));
float y_2 = dHeight * (points - i);
float z_2 = radius * MathHelper.sin(-((1 + i) * dAngle + phase));
// Add vertices for line segment
this.addVertex(buffer, matrix, x_1, y_1, z_1, r, g, b, alpha, w);
this.addVertex(buffer, matrix, x_2, y_2, z_2, r, g, b, alpha, w);
// Update previous coordinates
x_1 = x_2;
y_1 = y_2;
z_1 = z_2;
}
}
use of com.infinityraider.agricraft.api.v1.genetics.IAgriGenePair in project AgriCraft by AgriCraft.
the class TileEntitySeedAnalyzerSeedRenderer method renderGenome.
protected void renderGenome(TileEntitySeedAnalyzer tile, float partialTick, MatrixStack transforms, IRenderTypeBuffer buffer) {
// fetch genes
List<IAgriGenePair<?>> genes = tile.getGenesToRender();
if (genes == null) {
// should never be possible
return;
}
// push a new matrix to the stack
transforms.push();
// fetch helpers
SeedAnalyzerViewPointHandler viewHandler = SeedAnalyzerViewPointHandler.getInstance();
AgriGenomeRenderer renderer = AgriGenomeRenderer.getInstance();
// fetch scroll position
int index = viewHandler.getScrollIndex();
float partial = viewHandler.getPartialScrollProgress(partialTick);
// fetch orientation
BlockState state = tile.getBlockState();
Direction dir = BlockSeedAnalyzer.ORIENTATION.fetch(state);
// helix dimensions
float h = Constants.HALF;
float r = h / 10;
// transform to the desired position
float dx = Constants.HALF + Constants.UNIT * dir.getXOffset();
float dy = 5 * Constants.UNIT;
float dz = Constants.HALF + Constants.UNIT * dir.getZOffset();
transforms.translate(dx, dy, dz);
transforms.rotate(new Quaternion(Vector3f.YP, tile.getHorizontalAngle(), true));
// render the helix
renderer.renderDoubleHelix(genes, transforms, buffer, index, partial, r, h, 1.0F, false);
// render the text
if (index >= 0 && index < genes.size()) {
transforms.push();
transforms.translate(0, 0, -3 * Constants.UNIT);
transforms.rotate(TEXT_ROTATION);
float scale = 2.0F / Math.max(this.getScaledWindowWidth(), this.getScaledWindowHeight());
transforms.scale(scale, scale, 1);
renderer.renderTextOverlay(transforms, genes.get(index));
transforms.pop();
}
// pop the matrix off the stack
transforms.pop();
}
use of com.infinityraider.agricraft.api.v1.genetics.IAgriGenePair in project AgriCraft by AgriCraft.
the class SeedAnalyzerScreen method drawGuiContainerBackgroundLayer.
@Override
protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
this.minecraft.getTextureManager().bindTexture(GUI);
int relX = (this.width - this.xSize) / 2;
int relY = (this.height - this.ySize) / 2;
// background
this.blit(matrixStack, relX, relY, 0, 0, this.xSize, this.ySize);
// journal slot
this.blit(matrixStack, relX + 25, relY + 70, 186, 73, 18, 18);
// magnifying glass
this.blit(matrixStack, relX + 13, relY + 25, 0, 186, 56, 56);
List<IAgriGenePair<?>> genes = container.getGeneToRender();
int geneSize = genes.size();
// up/down buttons
if (geneSize > 7) {
int upXOffset = hoverUpButton(relX, relY, mouseX, mouseY) ? 195 : 186;
this.blit(matrixStack, relX + 67, relY + 26, upXOffset, 91, 9, 9);
int downXOffset = hoverDownButton(relX, relY, mouseX, mouseY) ? 195 : 186;
this.blit(matrixStack, relX + 67, relY + 90, downXOffset, 100, 9, 9);
}
if (!genes.isEmpty()) {
int DNA_X = relX + 90;
int yy = relY + 26;
// species gene
for (int i = 0; i < geneSize; i++) {
if (genes.get(i).getGene() instanceof GeneSpecies) {
IAgriGenePair<?> pair = genes.remove(i);
ITextComponent domText = pair.getDominant().getTooltip();
ITextComponent recText = pair.getRecessive().getTooltip();
int domw = this.font.getStringWidth(domText.getString());
int middle = relX + this.xSize / 2;
int sepLength = this.font.getStringWidth(TEXT_SEPARATOR.getString());
this.font.drawText(matrixStack, TEXT_SEPARATOR, middle - sepLength / 2F, relY + 16, 0);
this.font.drawText(matrixStack, domText, middle - domw - sepLength / 2F - 1, relY + 16, 0);
this.font.drawText(matrixStack, recText, middle + sepLength / 2F + 1, relY + 16, 0);
break;
}
}
// stats genes
int[] lineAmount = { 3, 2, 2, 3, 2, 3 };
int[] lineStart = { 0, 15, 25, 35, 50, 60 };
for (int i = geneIndex, lineIndex = 0; i < geneIndex + 6; i++, lineIndex++) {
IAgriGenePair<?> pair = genes.get(i);
// color of the gene
Vector3f[] colors = { pair.getGene().getDominantColor(), pair.getGene().getRecessiveColor() };
for (int j = 0; j < 2; j++) {
int argb = ((0xFF) << 24) | ((((int) (colors[j].getX() * 255)) & 0xFF) << 16) | ((((int) (colors[j].getY() * 255)) & 0xFF) << 8) | ((((int) (colors[j].getZ() * 255)) & 0xFF));
for (int k = 0; k < lineAmount[lineIndex]; k++) {
hLine(matrixStack, DNA_X + 9 * j, DNA_X + 9 + 8 * j, relY + 26 + lineStart[lineIndex] + k * 5, argb);
}
}
// text of the gene
ITextComponent geneText = pair.getGene().getGeneDescription();
ITextComponent domText = pair.getDominant().getTooltip();
ITextComponent recText = pair.getRecessive().getTooltip();
int domw = this.font.getStringWidth(domText.getString());
this.font.drawText(matrixStack, geneText, DNA_X + 36, yy, 0);
this.font.drawText(matrixStack, domText, DNA_X - domw - 1, yy, 0);
this.font.drawText(matrixStack, recText, DNA_X + 21, yy, 0);
yy += this.font.FONT_HEIGHT + 4;
}
// shape of the dna
this.minecraft.getTextureManager().bindTexture(GUI);
this.blit(matrixStack, DNA_X, relY + 26, 186, 0, 19, 73);
}
}
Aggregations