use of net.minecraft.client.renderer.block.model.BakedQuad in project MinecraftForge by MinecraftForge.
the class ItemLayerModel method getQuadsForSprite.
public static ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional<TRSRTransformation> transform) {
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
int uMax = sprite.getIconWidth();
int vMax = sprite.getIconHeight();
BitSet faces = new BitSet((uMax + 1) * (vMax + 1) * 4);
for (int f = 0; f < sprite.getFrameCount(); f++) {
int[] pixels = sprite.getFrameTextureData(f)[0];
boolean ptu;
boolean[] ptv = new boolean[uMax];
Arrays.fill(ptv, true);
for (int v = 0; v < vMax; v++) {
ptu = true;
for (int u = 0; u < uMax; u++) {
boolean t = isTransparent(pixels, uMax, vMax, u, v);
if (// left - transparent, right - opaque
ptu && !t) {
addSideQuad(builder, faces, format, transform, EnumFacing.WEST, tint, sprite, uMax, vMax, u, v);
}
if (// left - opaque, right - transparent
!ptu && t) {
addSideQuad(builder, faces, format, transform, EnumFacing.EAST, tint, sprite, uMax, vMax, u, v);
}
if (// up - transparent, down - opaque
ptv[u] && !t) {
addSideQuad(builder, faces, format, transform, EnumFacing.UP, tint, sprite, uMax, vMax, u, v);
}
if (// up - opaque, down - transparent
!ptv[u] && t) {
addSideQuad(builder, faces, format, transform, EnumFacing.DOWN, tint, sprite, uMax, vMax, u, v);
}
ptu = t;
ptv[u] = t;
}
if (// last - opaque
!ptu) {
addSideQuad(builder, faces, format, transform, EnumFacing.EAST, tint, sprite, uMax, vMax, uMax, v);
}
}
// last line
for (int u = 0; u < uMax; u++) {
if (!ptv[u]) {
addSideQuad(builder, faces, format, transform, EnumFacing.DOWN, tint, sprite, uMax, vMax, u, vMax);
}
}
}
// front
builder.add(buildQuad(format, transform, EnumFacing.NORTH, sprite, tint, 0, 0, 7.5f / 16f, sprite.getMinU(), sprite.getMaxV(), 0, 1, 7.5f / 16f, sprite.getMinU(), sprite.getMinV(), 1, 1, 7.5f / 16f, sprite.getMaxU(), sprite.getMinV(), 1, 0, 7.5f / 16f, sprite.getMaxU(), sprite.getMaxV()));
// back
builder.add(buildQuad(format, transform, EnumFacing.SOUTH, sprite, tint, 0, 0, 8.5f / 16f, sprite.getMinU(), sprite.getMaxV(), 1, 0, 8.5f / 16f, sprite.getMaxU(), sprite.getMaxV(), 1, 1, 8.5f / 16f, sprite.getMaxU(), sprite.getMinV(), 0, 1, 8.5f / 16f, sprite.getMinU(), sprite.getMinV()));
return builder.build();
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project MinecraftForge by MinecraftForge.
the class ForgeBlockModelRenderer method render.
public static boolean render(VertexLighterFlat lighter, IBlockAccess world, IBakedModel model, IBlockState state, BlockPos pos, VertexBuffer wr, boolean checkSides, long rand) {
lighter.setWorld(world);
lighter.setState(state);
lighter.setBlockPos(pos);
boolean empty = true;
List<BakedQuad> quads = model.getQuads(state, null, rand);
if (!quads.isEmpty()) {
lighter.updateBlockInfo();
empty = false;
for (BakedQuad quad : quads) {
quad.pipe(lighter);
}
}
for (EnumFacing side : EnumFacing.values()) {
quads = model.getQuads(state, side, rand);
if (!quads.isEmpty()) {
if (!checkSides || state.shouldSideBeRendered(world, pos, side)) {
if (empty)
lighter.updateBlockInfo();
empty = false;
for (BakedQuad quad : quads) {
quad.pipe(lighter);
}
}
}
}
return !empty;
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project Overloaded by CJ-MC-Mods.
the class ModelUtils method renderQuadsRGB.
public static void renderQuadsRGB(List<BakedQuad> listQuads, float r, float g, float b) {
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexbuffer = tessellator.getBuffer();
int i = 0;
for (int j = listQuads.size(); i < j; ++i) {
BakedQuad bakedquad = (BakedQuad) listQuads.get(i);
vertexbuffer.begin(7, DefaultVertexFormats.ITEM);
vertexbuffer.addVertexData(bakedquad.getVertexData());
vertexbuffer.putColorRGB_F4(r, g, b);
Vec3i vec3i = bakedquad.getFace().getDirectionVec();
vertexbuffer.putNormal((float) vec3i.getX(), (float) vec3i.getY(), (float) vec3i.getZ());
tessellator.draw();
}
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class TileRenderBelljar method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntityBelljar tile, double x, double y, double z, float partialTicks, int destroyStage) {
if (tile.dummy != 0 || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
return;
final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
BlockPos blockPos = tile.getPos();
if (!quads.containsKey(tile.getFacing())) {
IBlockState state = getWorld().getBlockState(blockPos);
if (state.getBlock() != IEContent.blockMetalDevice1)
return;
state = state.getActualState(getWorld(), blockPos);
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
if (state instanceof IExtendedBlockState)
state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Arrays.asList("glass"), true));
quads.put(tile.getFacing(), model.getQuads(state, null, 0));
}
ClientUtils.bindAtlas();
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
RenderHelper.disableStandardItemLighting();
GlStateManager.blendFunc(770, 771);
GlStateManager.enableBlend();
GlStateManager.disableCull();
if (Minecraft.isAmbientOcclusionEnabled())
GlStateManager.shadeModel(7425);
else
GlStateManager.shadeModel(7424);
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
VertexBuffer worldRenderer = Tessellator.getInstance().getBuffer();
GlStateManager.enableCull();
IPlantHandler plantHandler = tile.getCurrentPlantHandler();
if (plantHandler != null) {
GlStateManager.pushMatrix();
GlStateManager.translate(0, 1.0625, 0);
GlStateManager.color(1, 1, 1, 1);
float scale = plantHandler.getRenderSize(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile);
GlStateManager.translate((1 - scale) / 2, 0, (1 - scale) / 2);
GlStateManager.scale(scale, scale, scale);
if (!plantHandler.overrideRender(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile, blockRenderer)) {
IBlockState[] states = plantHandler.getRenderedPlant(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile);
if (states == null || states.length < 1)
return;
for (IBlockState s : states) {
List<BakedQuad> plantQuadList = plantQuads.get(s);
if (plantQuadList == null) {
IBakedModel plantModel = blockRenderer.getModelForState(s);
plantQuadList = plantModel.getQuads(s, null, 0);
for (EnumFacing f : EnumFacing.values()) plantQuadList.addAll(plantModel.getQuads(s, f, 0));
plantQuads.put(s, plantQuadList);
}
if (plantQuadList != null) {
GlStateManager.pushMatrix();
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
ClientUtils.renderModelTESR(plantQuadList, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
Tessellator.getInstance().draw();
GlStateManager.popMatrix();
GlStateManager.translate(0, 1, 0);
}
}
}
GlStateManager.popMatrix();
}
GlStateManager.depthMask(false);
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
ClientUtils.renderModelTESR(quads.get(tile.getFacing()), worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
Tessellator.getInstance().draw();
RenderHelper.enableStandardItemLighting();
GlStateManager.disableBlend();
GlStateManager.depthMask(true);
GlStateManager.popMatrix();
RenderHelper.enableStandardItemLighting();
}
use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.
the class TileRenderBucketWheel method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntityBucketWheel tile, double x, double y, double z, float f, int destroyStage) {
if (!tile.formed || !tile.getWorld().isBlockLoaded(tile.getPos(), false) || tile.isDummy())
return;
final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
IBlockState state = tile.getWorld().getBlockState(tile.getPos());
if (state.getBlock() != IEContent.blockMetalMultiblock)
return;
if (model == null) {
state = state.withProperty(IEProperties.DYNAMICRENDER, true);
model = blockRenderer.getModelForState(state);
}
OBJState objState = null;
HashMap<String, String> texMap = new HashMap<>();
if (state instanceof IExtendedBlockState) {
ArrayList<String> list = Lists.newArrayList("bucketWheel");
synchronized (tile.digStacks) {
for (int i = 0; i < tile.digStacks.length; i++) if (tile.digStacks[i] != null) {
list.add("dig" + i);
Block b = Block.getBlockFromItem(tile.digStacks[i].getItem());
IBlockState digState = b != null ? b.getStateFromMeta(tile.digStacks[i].getMetadata()) : Blocks.STONE.getDefaultState();
IBakedModel digModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(digState);
if (digModel != null && digModel.getParticleTexture() != null)
texMap.put("dig" + i, digModel.getParticleTexture().getIconName());
}
}
objState = new OBJState(list, true);
}
Tessellator tessellator = Tessellator.getInstance();
GlStateManager.pushMatrix();
GlStateManager.translate(x + .5, y + .5, z + .5);
GlStateManager.blendFunc(770, 771);
GlStateManager.enableBlend();
GlStateManager.disableCull();
EnumFacing facing = tile.facing;
if (tile.mirrored) {
GlStateManager.scale(facing.getAxis() == Axis.X ? -1 : 1, 1, facing.getAxis() == Axis.Z ? -1 : 1);
GlStateManager.disableCull();
}
float dir = tile.facing == EnumFacing.SOUTH ? 90 : tile.facing == EnumFacing.NORTH ? -90 : tile.facing == EnumFacing.EAST ? 180 : 0;
GlStateManager.rotate(dir, 0, 1, 0);
float rot = tile.rotation + (float) (tile.active ? IEConfig.Machines.excavator_speed * f : 0);
GlStateManager.rotate(rot, 1, 0, 0);
RenderHelper.disableStandardItemLighting();
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
VertexBuffer worldRenderer = tessellator.getBuffer();
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
worldRenderer.setTranslation(-.5, -.5, -.5);
List<BakedQuad> quads;
if (model instanceof IESmartObjModel)
quads = ((IESmartObjModel) model).getQuads(state, null, 0, objState, texMap, true);
else
quads = model.getQuads(state, null, 0);
ClientUtils.renderModelTESR(quads, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
worldRenderer.setTranslation(0, 0, 0);
tessellator.draw();
GlStateManager.popMatrix();
RenderHelper.enableStandardItemLighting();
GlStateManager.disableBlend();
GlStateManager.enableCull();
if (tile.mirrored) {
GlStateManager.enableCull();
}
}
Aggregations