use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class ClientUtils method renderModelTESRFancy.
/**
* Renders the given quads. Uses the local and neighbour brightnesses to calculate lighting
*
* @param quads the quads to render
* @param renderer the BufferBuilder to render to
* @param world the world the model is in. Will be used to obtain lighting information
* @param pos the position that this model is in. Use the position the the quads are actually in, not the rendering block
* @param useCached Whether to use cached information for world local data. Set to true if the previous call to this method was in the same tick and for the same world+pos
*/
public static void renderModelTESRFancy(List<BakedQuad> quads, BufferBuilder renderer, World world, BlockPos pos, boolean useCached) {
// TODO include matrix transformations?, cache normals?
if (Config.IEConfig.disableFancyTESR)
renderModelTESRFast(quads, renderer, world, pos);
else {
if (!useCached) {
// Calculate surrounding brighness and split into block and sky light
for (EnumFacing f : EnumFacing.VALUES) {
int val = world.getCombinedLight(pos.offset(f), 0);
neighbourBrightness[0][f.getIndex()] = (val >> 16) & 255;
neighbourBrightness[1][f.getIndex()] = val & 255;
}
// calculate the different correction factors for all 8 possible light vectors
for (int type = 0; type < 2; type++) for (int i = 0; i < 8; i++) {
float sSquared = 0;
if ((i & 1) != 0)
sSquared += scaledSquared(neighbourBrightness[type][5], 255F);
else
sSquared += scaledSquared(neighbourBrightness[type][4], 255F);
if ((i & 2) != 0)
sSquared += scaledSquared(neighbourBrightness[type][1], 255F);
else
sSquared += scaledSquared(neighbourBrightness[type][0], 255F);
if ((i & 4) != 0)
sSquared += scaledSquared(neighbourBrightness[type][3], 255F);
else
sSquared += scaledSquared(neighbourBrightness[type][2], 255F);
normalizationFactors[type][i] = (float) Math.sqrt(sSquared);
}
}
int localBrightness = world.getCombinedLight(pos, 0);
for (BakedQuad quad : quads) {
int[] vData = quad.getVertexData();
VertexFormat format = quad.getFormat();
int size = format.getIntegerSize();
int uv = format.getUvOffsetById(0) / 4;
// extract position info from the quad
for (int i = 0; i < 4; i++) {
quadCoords[i][0] = Float.intBitsToFloat(vData[size * i]);
quadCoords[i][1] = Float.intBitsToFloat(vData[size * i + 1]);
quadCoords[i][2] = Float.intBitsToFloat(vData[size * i + 2]);
}
// generate the normal vector
side1.x = quadCoords[1][0] - quadCoords[3][0];
side1.y = quadCoords[1][1] - quadCoords[3][1];
side1.z = quadCoords[1][2] - quadCoords[3][2];
side2.x = quadCoords[2][0] - quadCoords[0][0];
side2.y = quadCoords[2][1] - quadCoords[0][1];
side2.z = quadCoords[2][2] - quadCoords[0][2];
Vector3f.cross(side1, side2, normal);
normal.normalise();
// calculate the final light values and do the rendering
int l1 = getLightValue(neighbourBrightness[0], normalizationFactors[0], (localBrightness >> 16) & 255);
int l2 = getLightValue(neighbourBrightness[1], normalizationFactors[1], localBrightness & 255);
for (int i = 0; i < 4; ++i) {
renderer.pos(quadCoords[i][0], quadCoords[i][1], quadCoords[i][2]).color(255, 255, 255, 255).tex(Float.intBitsToFloat(vData[size * i + uv]), Float.intBitsToFloat(vData[size * i + uv + 1])).lightmap(l1, l2).endVertex();
}
}
}
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class ClientUtils method getSideTexture.
public static ResourceLocation getSideTexture(@Nonnull IBlockState state, EnumFacing side) {
IBakedModel model = mc().getBlockRendererDispatcher().getModelForState(state);
List<BakedQuad> quads = model.getQuads(state, side, 0);
if (// no quads for the specified side D:
quads == null || quads.isEmpty())
quads = model.getQuads(state, null, 0);
if (// no quads at all D:
quads == null || quads.isEmpty())
return null;
return new ResourceLocation(quads.get(0).getSprite().getIconName());
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class ClientUtils method createBakedBox.
@Nonnull
public static Set<BakedQuad> createBakedBox(Vector3f from, Vector3f to, Matrix4 matrix, EnumFacing facing, Function<Vector3f[], Vector3f[]> vertexTransformer, Function<EnumFacing, TextureAtlasSprite> textureGetter, float[] colour) {
HashSet<BakedQuad> quads = new HashSet<>();
if (vertexTransformer == null)
vertexTransformer = v -> v;
Vector3f[] vertices = { new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, from.y, to.z), new Vector3f(to.x, from.y, to.z), new Vector3f(to.x, from.y, from.z) };
TextureAtlasSprite sprite = textureGetter.apply(EnumFacing.DOWN);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.DOWN, facing), sprite, new double[] { from.x * 16, 16 - from.z * 16, to.x * 16, 16 - to.z * 16 }, colour, true));
for (Vector3f v : vertices) v.setY(to.y);
sprite = textureGetter.apply(EnumFacing.UP);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), sprite, new double[] { from.x * 16, from.z * 16, to.x * 16, to.z * 16 }, colour, false));
vertices = new Vector3f[] { new Vector3f(to.x, to.y, from.z), new Vector3f(to.x, from.y, from.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
sprite = textureGetter.apply(EnumFacing.NORTH);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.NORTH, facing), sprite, new double[] { 16 - to.x * 16, 16 - to.y * 16, 16 - from.x * 16, 16 - from.y * 16 }, colour, false));
for (Vector3f v : vertices) v.setZ(to.z);
sprite = textureGetter.apply(EnumFacing.SOUTH);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.SOUTH, facing), sprite, new double[] { to.x * 16, 16 - to.y * 16, from.x * 16, 16 - from.y * 16 }, colour, true));
vertices = new Vector3f[] { new Vector3f(from.x, to.y, to.z), new Vector3f(from.x, from.y, to.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
sprite = textureGetter.apply(EnumFacing.WEST);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), sprite, new double[] { to.z * 16, 16 - to.y * 16, from.z * 16, 16 - from.y * 16 }, colour, true));
for (Vector3f v : vertices) v.setX(to.x);
sprite = textureGetter.apply(EnumFacing.EAST);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), sprite, new double[] { 16 - to.z * 16, 16 - to.y * 16, 16 - from.z * 16, 16 - from.y * 16 }, colour, false));
return quads;
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class ClientUtils method renderModelTESRFast.
public static void renderModelTESRFast(List<BakedQuad> quads, BufferBuilder renderer, World world, BlockPos pos) {
int brightness = world.getCombinedLight(pos, 0);
int l1 = (brightness >> 0x10) & 0xFFFF;
int l2 = brightness & 0xFFFF;
for (BakedQuad quad : quads) {
int[] vData = quad.getVertexData();
VertexFormat format = quad.getFormat();
int size = format.getIntegerSize();
int uv = format.getUvOffsetById(0) / 4;
for (int i = 0; i < 4; ++i) {
renderer.pos(Float.intBitsToFloat(vData[size * i]), Float.intBitsToFloat(vData[size * i + 1]), Float.intBitsToFloat(vData[size * i + 2])).color(255, 255, 255, 255).tex(Float.intBitsToFloat(vData[size * i + uv]), Float.intBitsToFloat(vData[size * i + uv + 1])).lightmap(l1, l2).endVertex();
}
}
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class ClientUtils method renderQuads.
public static void renderQuads(Collection<BakedQuad> quads, float brightness, float red, float green, float blue) {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder BufferBuilder = tessellator.getBuffer();
for (BakedQuad bakedquad : quads) {
BufferBuilder.begin(7, DefaultVertexFormats.ITEM);
BufferBuilder.addVertexData(bakedquad.getVertexData());
if (bakedquad.hasTintIndex())
BufferBuilder.putColorRGB_F4(red * brightness, green * brightness, blue * brightness);
else
BufferBuilder.putColorRGB_F4(brightness, brightness, brightness);
Vec3i vec3i = bakedquad.getFace().getDirectionVec();
BufferBuilder.putNormal((float) vec3i.getX(), (float) vec3i.getY(), (float) vec3i.getZ());
tessellator.draw();
}
}
Aggregations