Search in sources :

Example 21 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project BetterWithAddons by DaedalusGame.

the class RenderUtils method getQuadFaceMapFromState.

public static Map<EnumFacing, List<BakedQuad>> getQuadFaceMapFromState(IBlockState state) {
    HashMap<EnumFacing, List<BakedQuad>> map = new HashMap<EnumFacing, List<BakedQuad>>();
    IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getBlockModelShapes().getModelForState(state);
    Random rng = new Random();
    for (EnumFacing f : EnumFacing.values()) {
        map.put(f, model.getQuads(state, f, rng.nextLong()));
    }
    map.put(null, model.getQuads(state, null, rng.nextLong()));
    return map;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Random(java.util.Random) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) List(java.util.List) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 22 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method convertConnectionFromBlockstate.

public static List<BakedQuad>[] convertConnectionFromBlockstate(IExtendedBlockState s, TextureAtlasSprite t) {
    List<BakedQuad>[] ret = new List[2];
    ret[0] = new ArrayList<>();
    ret[1] = new ArrayList<>();
    Set<Connection> conns = s.getValue(IEProperties.CONNECTIONS);
    if (conns == null)
        return ret;
    Vector3f dir = new Vector3f();
    Vector3f cross = new Vector3f();
    Vector3f up = new Vector3f(0, 1, 0);
    BlockPos pos = null;
    for (Connection conn : conns) {
        if (pos == null)
            pos = conn.start;
        Vec3d[] f = conn.catenaryVertices;
        if (f == null || f.length < 1)
            continue;
        int color = conn.cableType.getColour(conn);
        float[] rgb = { (color >> 16 & 255) / 255f, (color >> 8 & 255) / 255f, (color & 255) / 255f, (color >> 24 & 255) / 255f };
        if (rgb[3] == 0)
            rgb[3] = 1;
        Vector3f start = new Vector3f(conn.start.getX(), conn.start.getY(), conn.start.getZ());
        float radius = (float) (conn.cableType.getRenderDiameter() / 2);
        List<Integer> crossings = new ArrayList<>();
        for (int i = 1; i < f.length; i++) if (crossesChunkBoundary(f[i], f[i - 1]))
            crossings.add(i);
        int index = crossings.size() / 2;
        boolean greater = conn.start.compareTo(conn.end) > 0;
        if (crossings.size() % 2 == 0 && greater)
            index--;
        int max = (crossings.size() > 0 ? (crossings.get(index) + (greater ? 1 : 2)) : (greater ? f.length + 1 : 0));
        for (int i = 1; i < max && i < f.length; i++) {
            boolean fading = i == max - 1;
            List<BakedQuad> curr = ret[fading ? 1 : 0];
            int j = i - 1;
            Vector3f here = new Vector3f((float) f[i].xCoord, (float) f[i].yCoord, (float) f[i].zCoord);
            Vector3f.sub(here, start, here);
            Vector3f there = new Vector3f((float) f[j].xCoord, (float) f[j].yCoord, (float) f[j].zCoord);
            Vector3f.sub(there, start, there);
            if (fading) {
                Vector3f.add(here, fadingOffset, here);
                Vector3f.add(there, fadingOffset, there);
            }
            boolean vertical = here.x == there.x && here.z == there.z;
            if (!vertical) {
                Vector3f.sub(here, there, dir);
                Vector3f.cross(up, dir, cross);
                cross.scale(radius / cross.length());
            } else
                cross.set(radius, 0, 0);
            Vector3f[] vertices = { Vector3f.add(here, cross, null), Vector3f.sub(here, cross, null), Vector3f.sub(there, cross, null), Vector3f.add(there, cross, null) };
            curr.add(createSmartLightingBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.DOWN, t, rgb, false, fading ? alphaFirst2Fading : alphaNoFading, pos));
            curr.add(createSmartLightingBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.UP, t, rgb, true, fading ? alphaFirst2Fading : alphaNoFading, pos));
            if (!vertical) {
                Vector3f.cross(cross, dir, cross);
                cross.scale(radius / cross.length());
            } else
                cross.set(0, 0, radius);
            vertices = new Vector3f[] { Vector3f.add(here, cross, null), Vector3f.sub(here, cross, null), Vector3f.sub(there, cross, null), Vector3f.add(there, cross, null) };
            curr.add(createSmartLightingBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.WEST, t, rgb, false, fading ? alphaFirst2Fading : alphaNoFading, pos));
            curr.add(createSmartLightingBakedQuad(DefaultVertexFormats.ITEM, vertices, EnumFacing.EAST, t, rgb, true, fading ? alphaFirst2Fading : alphaNoFading, pos));
        }
    }
    return ret;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) Vec3d(net.minecraft.util.math.Vec3d) Vector3f(org.lwjgl.util.vector.Vector3f) BlockPos(net.minecraft.util.math.BlockPos)

Example 23 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method getSideTexture.

public static ResourceLocation getSideTexture(@Nonnull ItemStack stack, EnumFacing side) {
    IBakedModel model = mc().getRenderItem().getItemModelWithOverrides(stack, null, null);
    List<BakedQuad> quads = model.getQuads(null, side, 0);
    if (//no quads for the specified side D:
    quads == null || quads.isEmpty())
        quads = model.getQuads(null, null, 0);
    if (//no quads at all D:
    quads == null || quads.isEmpty())
        return null;
    return new ResourceLocation(quads.get(0).getSprite().getIconName());
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 24 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class ClientProxy method drawConveyorInGui.

@Override
public boolean drawConveyorInGui(String conveyor, EnumFacing facing) {
    IConveyorBelt con = ConveyorHandler.getConveyor(new ResourceLocation(conveyor), null);
    if (con != null) {
        GlStateManager.pushMatrix();
        Set<BakedQuad> quads = ModelConveyor.getBaseConveyor(facing, 1, new Matrix4(facing), ConveyorDirection.HORIZONTAL, ClientUtils.getSprite(con.getActiveTexture()), new boolean[] { true, true }, new boolean[] { true, true }, null, 0);
        //			GL11.glTranslatef(0, 0, 1);
        ClientUtils.renderQuads(quads, 1, 1, 1, 1);
        GlStateManager.popMatrix();
        return true;
    }
    return false;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IConveyorBelt(blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorBelt) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 25 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class IESmartObjModel method buildQuads.

private ImmutableList<BakedQuad> buildQuads() {
    List<BakedQuad> quads = Lists.newArrayList();
    ItemStack shader = null;
    ShaderCase sCase = null;
    IOBJModelCallback callback = null;
    Object callbackObject = null;
    if (this.tempStack != null && tempStack.hasCapability(CapabilityShader.SHADER_CAPABILITY, null)) {
        ShaderWrapper wrapper = tempStack.getCapability(CapabilityShader.SHADER_CAPABILITY, null);
        shader = wrapper.getShaderItem();
        if (shader != null && shader.getItem() instanceof IShaderItem)
            sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, tempStack, wrapper.getShaderType());
    } else if (this.tempState != null && this.tempState instanceof IExtendedBlockState && ((IExtendedBlockState) this.tempState).getUnlistedNames().contains(CapabilityShader.BLOCKSTATE_PROPERTY)) {
        ShaderWrapper wrapper = ((IExtendedBlockState) this.tempState).getValue(CapabilityShader.BLOCKSTATE_PROPERTY);
        shader = wrapper.getShaderItem();
        if (shader != null && shader.getItem() instanceof IShaderItem)
            sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, null, wrapper.getShaderType());
    }
    if (this.tempStack != null && tempStack.getItem() instanceof IOBJModelCallback) {
        callback = (IOBJModelCallback) tempStack.getItem();
        callbackObject = this.tempStack;
    } else if (this.tempState != null && this.tempState instanceof IExtendedBlockState && ((IExtendedBlockState) this.tempState).getUnlistedNames().contains(IOBJModelCallback.PROPERTY)) {
        callback = ((IExtendedBlockState) this.tempState).getValue(IOBJModelCallback.PROPERTY);
        callbackObject = this.tempState;
    }
    int maxPasses = 1;
    if (sCase != null)
        maxPasses = sCase.getLayers().length;
    for (int pass = 0; pass < maxPasses; pass++) {
        ShaderLayer shaderLayer = sCase != null ? sCase.getLayers()[pass] : null;
        for (Group g : getModel().getMatLib().getGroups().values()) {
            if (callback != null)
                if (!callback.shouldRenderGroup(callbackObject, g.getName()))
                    continue;
            if (sCase != null)
                if (!sCase.renderModelPartForPass(shader, tempStack, g.getName(), pass))
                    continue;
            Set<Face> faces = Collections.synchronizedSet(new LinkedHashSet<Face>());
            Optional<TRSRTransformation> transform = Optional.absent();
            if (this.getState() instanceof OBJState) {
                OBJState state = (OBJState) this.getState();
                if (state.parent != null)
                    transform = state.parent.apply(Optional.absent());
                if (callback != null)
                    transform = callback.applyTransformations(callbackObject, g.getName(), transform);
                if (state.getGroupsWithVisibility(true).contains(g.getName()))
                    faces.addAll(g.applyTransform(transform));
            } else {
                transform = getState().apply(Optional.absent());
                if (callback != null)
                    transform = callback.applyTransformations(callbackObject, g.getName(), transform);
                faces.addAll(g.applyTransform(transform));
            }
            int argb = 0xffffffff;
            if (sCase != null)
                argb = sCase.getARGBColourModifier(shader, tempStack, g.getName(), pass);
            else if (callback != null)
                argb = callback.getRenderColour(callbackObject, g.getName());
            float[] colour = { (argb >> 16 & 255) / 255f, (argb >> 8 & 255) / 255f, (argb & 255) / 255f, (argb >> 24 & 255) / 255f };
            for (Face f : faces) {
                tempSprite = null;
                if (this.getModel().getMatLib().getMaterial(f.getMaterialName()).isWhite() && !"null".equals(f.getMaterialName())) {
                    for (Vertex v : f.getVertices()) if (!v.getMaterial().equals(this.getModel().getMatLib().getMaterial(v.getMaterial().getName())))
                        v.setMaterial(this.getModel().getMatLib().getMaterial(v.getMaterial().getName()));
                    tempSprite = ModelLoader.White.INSTANCE;
                } else {
                    if (sCase != null) {
                        ResourceLocation rl = sCase.getReplacementSprite(shader, tempStack, g.getName(), pass);
                        if (rl != null)
                            tempSprite = ClientUtils.getSprite(rl);
                    }
                    if (tempSprite == null && callback != null)
                        tempSprite = callback.getTextureReplacement(callbackObject, f.getMaterialName());
                    if (tempSprite == null && tempState != null && texReplace != null) {
                        String s = texReplace.get(g.getName());
                        if (s != null)
                            tempSprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(s);
                    }
                    if (tempSprite == null && !"null".equals(f.getMaterialName()))
                        tempSprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(this.getModel().getMatLib().getMaterial(f.getMaterialName()).getTexture().getTextureLocation().toString());
                }
                if (tempSprite != null) {
                    UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(getFormat());
                    builder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
                    builder.setTexture(tempSprite);
                    builder.setQuadTint(pass);
                    Normal faceNormal = f.getNormal();
                    TextureCoordinate[] uvs = new TextureCoordinate[4];
                    boolean renderFace = true;
                    for (int i = 0; i < 4; i++) {
                        Vertex vertex = f.getVertices()[i];
                        //V-Flip is processed here already, rather than in the later method, since it's needed for easy UV comparissons on the Shader Layers
                        uvs[i] = vertex.hasTextureCoordinate() ? new TextureCoordinate(vertex.getTextureCoordinate().u, 1 - vertex.getTextureCoordinate().v, vertex.getTextureCoordinate().w) : TextureCoordinate.getDefaultUVs()[i];
                        if (shaderLayer != null) {
                            double[] texBounds = shaderLayer.getTextureBounds();
                            if (texBounds != null) {
                                if (//if any uvs are outside the layers bounds
                                texBounds[0] > uvs[i].u || uvs[i].u > texBounds[2] || texBounds[1] > uvs[i].v || uvs[i].v > texBounds[3]) {
                                    renderFace = false;
                                    break;
                                }
                                double dU = texBounds[2] - texBounds[0];
                                double dV = texBounds[3] - texBounds[1];
                                //Rescaling to the partial bounds that the texture represents
                                uvs[i].u = (float) ((uvs[i].u - texBounds[0]) / dU);
                                uvs[i].v = (float) ((uvs[i].v - texBounds[1]) / dV);
                            }
                            //Rescaling to the selective area of the texture that is used
                            double[] cutBounds = shaderLayer.getCutoutBounds();
                            if (cutBounds != null) {
                                double dU = cutBounds[2] - cutBounds[0];
                                double dV = cutBounds[3] - cutBounds[1];
                                uvs[i].u = (float) (cutBounds[0] + dU * uvs[i].u);
                                uvs[i].v = (float) (cutBounds[1] + dV * uvs[i].v);
                            }
                        }
                    }
                    if (renderFace) {
                        for (int i = 0; i < 4; i++) putVertexData(builder, f.getVertices()[i], faceNormal, uvs[i], tempSprite, colour);
                        quads.add(builder.build());
                    }
                }
            }
        }
    }
    if (callback != null)
        quads = callback.modifyQuads(callbackObject, quads);
    return ImmutableList.copyOf(quads);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) IShaderItem(blusunrize.immersiveengineering.api.shader.IShaderItem) ShaderLayer(blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer) ResourceLocation(net.minecraft.util.ResourceLocation) ShaderWrapper(blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ItemStack(net.minecraft.item.ItemStack) ComparableItemStack(blusunrize.immersiveengineering.api.ComparableItemStack)

Aggregations

BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)30 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)13 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)12 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)8 EnumFacing (net.minecraft.util.EnumFacing)8 Tessellator (net.minecraft.client.renderer.Tessellator)6 Vec3i (net.minecraft.util.math.Vec3i)6 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)5 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)5 Vector3f (org.lwjgl.util.vector.Vector3f)5 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)4 ImmutableList (com.google.common.collect.ImmutableList)4 IBlockState (net.minecraft.block.state.IBlockState)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 BlockPos (net.minecraft.util.math.BlockPos)4 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)4 HashMap (java.util.HashMap)3 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)3 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)2 ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)2