use of net.minecraft.util.math.vector.Vector3f in project Bookshelf by Darkhax-Minecraft.
the class SerializerVec3f method read.
@Override
public Vector3f read(INBT nbt) {
if (nbt instanceof CompoundNBT) {
final CompoundNBT tag = (CompoundNBT) nbt;
final float x = tag.getFloat("x");
final float y = tag.getFloat("y");
final float z = tag.getFloat("z");
return new Vector3f(x, y, z);
}
throw new IllegalArgumentException("Expected NBT to be a compound tag. Class was " + nbt.getClass() + " with ID " + nbt.getId() + " instead.");
}
use of net.minecraft.util.math.vector.Vector3f 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 net.minecraft.util.math.vector.Vector3f 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);
}
}
use of net.minecraft.util.math.vector.Vector3f in project AgriCraft by AgriCraft.
the class AgriGenomeRenderer method drawSpokes.
protected void drawSpokes(List<IAgriGenePair<?>> genePairs, int active, float radius, float phase1, float phase2, float dHeight, float dAngle, IRenderTypeBuffer buffer, Matrix4f matrix, float alpha, boolean color) {
for (int spoke = 0; spoke < genePairs.size(); spoke++) {
// Find equivalent point index
int i = spoke * POINTS_PER_GENE + POINTS_PER_GENE / 2;
float angle = i * dAngle;
// Find positions
float x1 = radius * MathHelper.cos(-(angle + phase1));
float x2 = radius * MathHelper.cos(-(angle + phase2));
float y = dHeight * (POINTS_PER_GENE * genePairs.size() - i);
float z1 = radius * MathHelper.sin(-(angle + phase1));
float z2 = radius * MathHelper.sin(-(angle + phase2));
// find colors
IAgriGene<?> gene = genePairs.get(spoke).getGene();
Vector3f dom = this.getColor(gene, active == spoke, true, color);
Vector3f rec = this.getColor(gene, active == spoke, false, color);
// find width
float w = this.getLineWidth(active == spoke);
// First vertex of the first segment
this.addVertex(buffer, matrix, x1, y, z1, dom.getX(), dom.getY(), dom.getZ(), alpha, w);
for (int j = 1; j < POINTS_PER_GENE; j++) {
float x = MathHelper.lerp((j + 0.0F) / POINTS_PER_GENE, x1, x2);
float z = MathHelper.lerp((j + 0.0F) / POINTS_PER_GENE, z1, z2);
float r = MathHelper.lerp((j + 0.0F) / POINTS_PER_GENE, dom.getX(), rec.getX());
float g = MathHelper.lerp((j + 0.0F) / POINTS_PER_GENE, dom.getY(), rec.getY());
float b = MathHelper.lerp((j + 0.0F) / POINTS_PER_GENE, dom.getZ(), rec.getZ());
// Second vertex of the previous segment
this.addVertex(buffer, matrix, x, y, z, r, g, b, alpha, w);
// First vertex of the next segment
this.addVertex(buffer, matrix, x, y, z, r, g, b, alpha, w);
}
// Second vertex of the last segment
this.addVertex(buffer, matrix, x2, y, z2, rec.getX(), rec.getY(), rec.getZ(), alpha, w);
}
}
Aggregations