use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.
the class FacadeRenderer method applyItemTint.
public static List<CCQuad> applyItemTint(List<CCQuad> quads, ItemStack stack) {
List<CCQuad> retQuads = new LinkedList<>();
for (CCQuad quad : quads) {
int colour = -1;
if (quad.hasTint()) {
colour = Minecraft.getMinecraft().getItemColors().colorMultiplier(stack, quad.tintIndex);
if (EntityRenderer.anaglyphEnable) {
colour = TextureUtil.anaglyphColor(colour);
}
colour = colour | 0xFF000000;
}
CCQuad copyQuad = quad.copy();
Colour c = new ColourARGB(colour);
for (Colour qC : copyQuad.colours) {
qC.multiply(c);
}
retQuads.add(copyQuad);
}
return retQuads;
}
use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.
the class FacadeRenderer method sliceQuads.
public static List<CCQuad> sliceQuads(List<CCQuad> quads, int side, Cuboid6 bounds) {
boolean flag, flag2;
double[][] quadPos = new double[4][3];
boolean[] flat = new boolean[3];
int verticesPerFace = 4;
List<CCQuad> finalQuads = new LinkedList<>();
for (CCQuad quad : quads) {
flag = flag2 = false;
for (int i = 0; i < 3; i++) {
flat[i] = true;
}
Vector3 first = quad.vertices[0].vec;
for (int v = 0; v < 4; v++) {
quadPos[v] = quad.vertices[v].vec.toArrayD();
flag = flag || quadPos[v][sideOffsets[side]] != sideSoftBounds[side];
flag2 = flag2 || quadPos[v][sideOffsets[side]] != (1 - sideSoftBounds[side]);
if (v != 0) {
flat[0] = flat[0] && quad.vertices[v].vec.x == first.x;
flat[1] = flat[1] && quad.vertices[v].vec.y == first.y;
flat[2] = flat[2] && quad.vertices[v].vec.z == first.z;
}
}
int s = -1;
if (flag && flag2) {
for (int vi = 0; vi < 3; vi++) {
if (flat[vi]) {
if (vi != sideOffsets[side]) {
s = vi;
break;
} else {
flag = false;
}
}
}
}
for (int k2 = 0; k2 < verticesPerFace; k2++) {
boolean flag3 = quadPos[k2][sideOffsets[side]] != sideSoftBounds[side];
for (int j = 0; j < 3; j++) {
if (j == sideOffsets[side]) {
quadPos[k2][j] = clampF(quadPos[k2][j], bounds, j);
} else {
if (flag && flag2 && flag3) {
quadPos[k2][j] = MathHelper.clamp(quadPos[k2][j], FACADE_RENDER_OFFSET, FACADE_RENDER_OFFSET2);
}
}
}
if (s != -1) {
double u, v;
if (s == 0) {
u = quadPos[k2][1];
v = quadPos[k2][2];
} else if (s == 1) {
u = quadPos[k2][0];
v = quadPos[k2][2];
} else {
u = quadPos[k2][0];
v = quadPos[k2][1];
}
u = MathHelper.clamp(u, 0, 1) * 16;
v = MathHelper.clamp(v, 0, 1) * 16;
TextureAtlasSprite sideTexture = quad.sprite;
u = sideTexture.getInterpolatedU(u);
v = sideTexture.getInterpolatedV(v);
quad.vertices[k2].uv.set(u, v);
quad.tintIndex = -1;
}
quad.vertices[k2].vec.set(quadPos[k2]);
}
finalQuads.add(quad);
}
return finalQuads;
}
use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.
the class FacadeRenderer method renderBlockQuads.
public static boolean renderBlockQuads(VertexLighterFlat lighter, IBlockAccess access, IBlockState state, List<CCQuad> quads, BlockPos pos) {
if (!quads.isEmpty()) {
lighter.setWorld(access);
lighter.setState(state);
lighter.setBlockPos(pos);
lighter.updateBlockInfo();
for (CCQuad quad : quads) {
quad.pipe(lighter);
}
return true;
}
return false;
}
use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.
the class FacadeRenderer method renderBlockCover.
public static boolean renderBlockCover(CCRenderState ccrs, Matrix4 translation, IBlockAccess world, BlockPos pos, int side, IBlockState state, Cuboid6 bounds) {
EnumFacing face = EnumFacing.VALUES[side];
IBlockAccess coverAccess = new FacadeBlockAccess(world, pos, face, state);
BlockRendererDispatcher dispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
try {
state = state.getActualState(coverAccess, pos);
} catch (Exception ignored) {
}
IBakedModel model = dispatcher.getModelForState(state);
try {
state = state.getBlock().getExtendedState(state, coverAccess, pos);
} catch (Exception ignored) {
}
long posRand = net.minecraft.util.math.MathHelper.getPositionRandom(pos);
List<BakedQuad> bakedQuads = new LinkedList<>(model.getQuads(state, null, posRand));
for (EnumFacing face2 : EnumFacing.VALUES) {
bakedQuads.addAll(model.getQuads(state, face2, posRand));
}
List<CCQuad> quads = CCQuad.fromArray(bakedQuads);
quads = sliceQuads(quads, side, bounds);
if (!quads.isEmpty()) {
VertexLighterFlat lighter = setupLighter(ccrs, translation, state, coverAccess, pos, model);
return renderBlockQuads(lighter, coverAccess, state, quads, pos);
}
return false;
}
use of codechicken.lib.render.CCQuad in project GregTech by GregTechCE.
the class FacadeRenderer method renderItemCover.
public static void renderItemCover(CCRenderState ccrs, int side, ItemStack renderStack, Cuboid6 bounds) {
Minecraft minecraft = Minecraft.getMinecraft();
RenderItem renderItem = minecraft.getRenderItem();
IBakedModel model = renderItem.getItemModelWithOverrides(renderStack, null, null);
IBlockState state = FacadeHelper.lookupBlockForItem(renderStack);
String cacheKey = state.getBlock().getRegistryName() + "|" + state.getBlock().getMetaFromState(state);
List<CCQuad> renderQuads = itemQuadCache.getIfPresent(cacheKey);
if (renderQuads == null) {
List<BakedQuad> quads = new ArrayList<>(model.getQuads(null, null, 0));
for (EnumFacing face : EnumFacing.VALUES) {
quads.addAll(model.getQuads(null, face, 0));
}
renderQuads = applyItemTint(sliceQuads(CCQuad.fromArray(quads), side, bounds), renderStack);
itemQuadCache.put(cacheKey, renderQuads);
}
AdvCCRSConsumer consumer = new AdvCCRSConsumer(ccrs);
consumer.setTranslation(new Matrix4().translate(Vector3.center.copy().subtract(bounds.center())).scale(1.05, 1.05, 1.05));
for (CCQuad quad : renderQuads) {
quad.pipe(consumer);
}
}
Aggregations