use of net.minecraft.client.renderer.block.model.BakedQuad in project Charset by CharsetMC.
the class RenderTileEntityStacks method getQuads.
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if (side != null || !(state instanceof IExtendedBlockState)) {
return Collections.emptyList();
}
TileEntityStacks stacks = ((IExtendedBlockState) state).getValue(BlockStacks.PROPERTY_TILE);
if (stacks == null || stacks.stacks.isEmpty()) {
return Collections.emptyList();
}
List<BakedQuad> list = new ArrayList<>();
int i = 0;
for (ItemMaterial material : stacks.stacks) {
Vec3d[] vecs = INGOT_POSITIONS[i];
ItemMaterial blockMaterial = material.getRelated("block");
TextureAtlasSprite sprite;
int c;
if (blockMaterial == null) {
ItemStack ingotStack = material.getStack();
sprite = RenderUtils.getItemSprite(new ItemStack(Blocks.IRON_BLOCK));
c = ColorLookupHandler.INSTANCE.getColor(ingotStack, RenderUtils.AveragingMode.FULL) | 0xFF000000;
} else {
sprite = RenderUtils.getItemSprite(blockMaterial.getStack());
c = Minecraft.getMinecraft().getItemColors().colorMultiplier(blockMaterial.getStack(), 0);
}
float[] color = new float[] { MathHelper.clamp(((c >> 16) & 0xFF) / 255.0f, 0, 1), MathHelper.clamp(((c >> 8) & 0xFF) / 255.0f, 0, 1), MathHelper.clamp(((c) & 0xFF) / 255.0f, 0, 1), 1.0f };
int j = 0;
int yOff = (i >> 3) & 1;
for (int[] vecOrder : QUAD_ORDERS[yOff]) {
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(DefaultVertexFormats.ITEM);
EnumFacing face = QUAD_FACES[yOff][j];
builder.setTexture(sprite);
builder.setApplyDiffuseLighting(isAmbientOcclusion());
builder.setContractUVs(false);
builder.setQuadOrientation(face);
int uv_offset = j < 4 ? 1 : 0;
if (yOff == 1)
uv_offset = 1 - uv_offset;
for (int k = 0; k < vecOrder.length; k++) {
Vec3d vec = vecs[vecOrder[k]];
int[] uv = QUAD_UVS[(k + uv_offset) & 3];
for (int e = 0; e < builder.getVertexFormat().getElementCount(); e++) {
VertexFormatElement el = builder.getVertexFormat().getElement(e);
switch(el.getUsage()) {
case POSITION:
builder.put(e, (float) vec.x / 16f, (float) vec.y / 16f, (float) vec.z / 16f, 1);
break;
case COLOR:
builder.put(e, color);
break;
case NORMAL:
builder.put(e, face.getFrontOffsetX(), face.getFrontOffsetY(), face.getFrontOffsetZ(), 0);
break;
case UV:
float u = sprite.getInterpolatedU(uv[0]);
float v = sprite.getInterpolatedV(uv[1]);
builder.put(e, u, v, 0, 1);
break;
default:
builder.put(e);
}
}
}
list.add(builder.build());
j++;
}
i++;
}
return list;
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project Galacticraft by micdoodle8.
the class ClientUtil method drawBakedModel.
public static void drawBakedModel(IFlexibleBakedModel model) {
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
worldrenderer.begin(GL11.GL_QUADS, model.getFormat());
for (BakedQuad bakedquad : model.getGeneralQuads()) {
worldrenderer.addVertexData(bakedquad.getVertexData());
}
tessellator.draw();
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project Galacticraft by micdoodle8.
the class ClientUtil method drawBakedModelColored.
public static void drawBakedModelColored(IFlexibleBakedModel model, int color) {
Tessellator tessellator = Tessellator.getInstance();
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
worldrenderer.begin(GL11.GL_QUADS, model.getFormat());
for (BakedQuad bakedquad : model.getGeneralQuads()) {
int[] data = bakedquad.getVertexData();
data[3] = color;
data[10] = color;
data[17] = color;
data[24] = color;
worldrenderer.addVertexData(data);
}
tessellator.draw();
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project BuildCraft by BuildCraft.
the class VariablePartTextureExpand method addQuads.
@Override
public void addQuads(List<MutableQuad> addTo, ITextureGetter spriteLookup) {
if (visible.evaluate()) {
float[] f = bakePosition(from);
float[] t = bakePosition(to);
float[] size = { t[0] - f[0], t[1] - f[1], t[2], f[2] };
boolean s = shade.evaluate();
int l = (int) (light.evaluate() & 15);
int rgba = RenderUtil.swapARGBforABGR((int) colour.evaluate());
VariableFaceData data = faceUv.evaluate(spriteLookup);
// TODO: Use the UV data! (only take part of the texture)
ItemLayerModel model = new ItemLayerModel(ImmutableList.of(new ResourceLocation(".")));
IBakedModel baked = model.bake(ModelRotation.X0_Y0, DefaultVertexFormats.ITEM, (loc) -> data.sprite);
List<BakedQuad> quads = baked.getQuads(null, null, 0);
for (BakedQuad q : quads) {
MutableQuad mut = new MutableQuad();
mut.fromBakedItem(q);
mut.translated(0, 0, -(7.5 / 16.0));
mut.scaled(1, 1, 16);
mut.rotate(EnumFacing.SOUTH, evaluateFace(this.face), 0.5f, 0.5f, 0.5f);
mut.scalef(size[0], size[1], size[2]);
mut.translated(f[0], f[1], f[2]);
mut.setCalculatedNormal();
mut.setShade(s);
mut.lighti(l, 0);
mut.colouri(rgba);
mut.setSprite(data.sprite);
addTo.add(mut);
}
}
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project BuildCraft by BuildCraft.
the class PlugBakerSimple method bake.
@Override
public List<BakedQuad> bake(K key) {
MutableQuad[] quads = provider.getCutoutQuads();
if (quads != lastSeen) {
cached.clear();
MutableQuad copy = new MutableQuad();
for (EnumFacing to : EnumFacing.VALUES) {
List<BakedQuad> list = new ArrayList<>();
for (MutableQuad q : quads) {
copy.copyFrom(q);
copy.rotate(EnumFacing.WEST, to, 0.5f, 0.5f, 0.5f);
copy.multShade();
list.add(copy.toBakedBlock());
}
cached.put(to, list);
}
lastSeen = quads;
}
return cached.get(key.side);
}
Aggregations