use of net.minecraft.client.renderer.vertex.VertexFormat in project MinecraftForge by MinecraftForge.
the class VertexBufferConsumer method put.
public void put(int e, float... data) {
VertexFormat format = getVertexFormat();
if (renderer.isColorDisabled() && format.getElement(e).getUsage() == EnumUsage.COLOR) {
data = dummyColor;
}
LightUtil.pack(data, quadData, format, v, e);
if (e == format.getElementCount() - 1) {
v++;
if (v == 4) {
renderer.addVertexData(quadData);
renderer.putPosition(offset.getX(), offset.getY(), offset.getZ());
//Arrays.fill(quadData, 0);
v = 0;
}
}
}
use of net.minecraft.client.renderer.vertex.VertexFormat in project MinecraftForge by MinecraftForge.
the class VertexLighterFlat method processQuad.
@Override
protected void processQuad() {
float[][] position = quadData[posIndex];
float[][] normal = null;
float[][] lightmap = quadData[lightmapIndex];
float[][] color = quadData[colorIndex];
if (normalIndex != -1 && (quadData[normalIndex][0][0] != -1 || quadData[normalIndex][0][1] != -1 || quadData[normalIndex][0][2] != -1)) {
normal = quadData[normalIndex];
} else {
normal = new float[4][4];
Vector3f v1 = new Vector3f(position[3]);
Vector3f t = new Vector3f(position[1]);
Vector3f v2 = new Vector3f(position[2]);
v1.sub(t);
t.set(position[0]);
v2.sub(t);
v1.cross(v2, v1);
v1.normalize();
for (int v = 0; v < 4; v++) {
normal[v][0] = v1.x;
normal[v][1] = v1.y;
normal[v][2] = v1.z;
normal[v][3] = 0;
}
}
int multiplier = -1;
if (tint != -1) {
multiplier = blockInfo.getColorMultiplier(tint);
}
VertexFormat format = parent.getVertexFormat();
int count = format.getElementCount();
for (int v = 0; v < 4; v++) {
position[v][0] += blockInfo.getShx();
position[v][1] += blockInfo.getShy();
position[v][2] += blockInfo.getShz();
float x = position[v][0] - .5f;
float y = position[v][1] - .5f;
float z = position[v][2] - .5f;
//if(blockInfo.getBlock().isFullCube())
{
x += normal[v][0] * .5f;
y += normal[v][1] * .5f;
z += normal[v][2] * .5f;
}
float blockLight = lightmap[v][0], skyLight = lightmap[v][1];
updateLightmap(normal[v], lightmap[v], x, y, z);
if (dataLength[lightmapIndex] > 1) {
if (blockLight > lightmap[v][0])
lightmap[v][0] = blockLight;
if (skyLight > lightmap[v][1])
lightmap[v][1] = skyLight;
}
updateColor(normal[v], color[v], x, y, z, tint, multiplier);
if (diffuse) {
float d = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
for (int i = 0; i < 3; i++) {
color[v][i] *= d;
}
}
if (EntityRenderer.anaglyphEnable) {
applyAnaglyph(color[v]);
}
// no need for remapping cause all we could've done is add 1 element to the end
for (int e = 0; e < count; e++) {
VertexFormatElement element = format.getElement(e);
switch(element.getUsage()) {
case POSITION:
// position adding moved to VertexBufferConsumer due to x and z not fitting completely into a float
/*float[] pos = new float[4];
System.arraycopy(position[v], 0, pos, 0, position[v].length);
pos[0] += blockInfo.getBlockPos().getX();
pos[1] += blockInfo.getBlockPos().getY();
pos[2] += blockInfo.getBlockPos().getZ();*/
parent.put(e, position[v]);
break;
case NORMAL:
if (normalIndex != -1) {
parent.put(e, normal[v]);
break;
}
case COLOR:
parent.put(e, color[v]);
break;
case UV:
if (element.getIndex() == 1) {
parent.put(e, lightmap[v]);
break;
}
default:
parent.put(e, quadData[e][v]);
}
}
}
tint = -1;
}
use of net.minecraft.client.renderer.vertex.VertexFormat in project Charset by CharsetMC.
the class ProxyClient method bakeModels.
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void bakeModels(ModelBakeEvent event) {
if (prismModel != null) {
for (Orientation o : Orientation.values()) {
ModelResourceLocation location = new ModelResourceLocation("charset:laser_prism", "orientation=" + o.name().toLowerCase());
IBakedModel model = prismModel.bake(o.toTransformation(), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());
event.getModelRegistry().putObject(location, model);
}
}
// Patch jars to glow
for (EnumFacing facing : EnumFacing.VALUES) {
for (LaserColor color : LaserColor.VALUES) {
if (color == LaserColor.NONE)
continue;
IBlockState state = CharsetLaser.blockJar.getDefaultState().withProperty(CharsetLaser.LASER_COLOR, color).withProperty(Properties.FACING, facing);
ModelResourceLocation location = new ModelResourceLocation("charset:light_jar", "color=" + color.getName() + ",facing=" + facing.getName());
IBakedModel model = event.getModelRegistry().getObject(location);
VertexFormat format = new VertexFormat(DefaultVertexFormats.ITEM);
format.addElement(DefaultVertexFormats.TEX_2S);
if (model != null) {
SimpleMultiLayerBakedModel result = new SimpleMultiLayerBakedModel(model);
BlockRenderLayer layerPre = MinecraftForgeClient.getRenderLayer();
for (BlockRenderLayer layer : BlockRenderLayer.values()) {
if (CharsetLaser.blockJar.canRenderInLayer(CharsetLaser.blockJar.getDefaultState(), layer)) {
ForgeHooksClient.setRenderLayer(layer);
for (int i = 0; i <= 6; i++) {
EnumFacing facingIn = (i < 6) ? EnumFacing.getFront(i) : null;
for (BakedQuad quadIn : model.getQuads(state, facingIn, 0)) {
result.addQuad(layer, facingIn, ModelTransformer.transform(quadIn, (quad, element, data) -> {
if (quad.getTintIndex() == 1 && element == DefaultVertexFormats.TEX_2S) {
return new float[] { 15f * 0x20 / 0xFFFF, 0, 0, 0 };
}
return data;
}, (bakedQuad -> {
if (bakedQuad.getTintIndex() == 1) {
return format;
} else {
return bakedQuad.getFormat();
}
})));
}
}
}
}
ForgeHooksClient.setRenderLayer(layerPre);
event.getModelRegistry().putObject(location, result);
}
}
}
}
use of net.minecraft.client.renderer.vertex.VertexFormat in project Charset by CharsetMC.
the class ModelTransformer method transform.
public static BakedQuad transform(BakedQuad quad, IVertexTransformer transformer, @Nullable Function<BakedQuad, VertexFormat> format2) {
VertexFormat format = format2 != null ? format2.apply(quad) : quad.getFormat();
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
LightUtil.putBakedQuad(new VertexTransformerWrapper(builder, quad, transformer), quad);
return builder.build();
}
use of net.minecraft.client.renderer.vertex.VertexFormat in project EnderIO by SleepyTrousers.
the class HalfBakedQuad method putVertexData.
private void putVertexData(@Nonnull Builder builder, @Nonnull Vertex v, float w) {
VertexFormat format = builder.getVertexFormat();
for (int e = 0; e < format.getElementCount(); e++) {
switch(format.getElement(e).getUsage()) {
case POSITION:
builder.put(e, (float) v.x(), (float) v.y(), (float) v.z(), 1);
break;
case COLOR:
float d = LightUtil.diffuseLight(v.nx(), v.ny(), v.nz());
builder.put(e, d * color.x, d * color.y, d * color.z, color.w);
break;
case UV:
builder.put(e, tex.getInterpolatedU(v.u() * 16) * w, tex.getInterpolatedV(v.v() * 16) * w, 0, w);
break;
case NORMAL:
builder.put(e, v.nx(), v.ny(), v.nz(), 0);
break;
default:
builder.put(e);
}
}
}
Aggregations