Search in sources :

Example 6 with TRSRTransformation

use of net.minecraftforge.common.model.TRSRTransformation in project ImmersiveEngineering by BluSunrize.

the class ItemDrill method applyTransformations.

@SideOnly(Side.CLIENT)
@Override
public Optional<TRSRTransformation> applyTransformations(ItemStack stack, String group, Optional<TRSRTransformation> transform) {
    if (transform.isPresent()) {
        NBTTagCompound upgrades = this.getUpgrades(stack);
        if (group.equals("drill_head") && upgrades.getInteger("damage") <= 0) {
            Matrix4 mat = new Matrix4(transform.get().getMatrix());
            mat.translate(-.25f, 0, 0);
            return Optional.of(new TRSRTransformation(mat.toMatrix4f()));
        }
        if (group.equals("upgrade_damage1") || group.equals("upgrade_damage2") || group.equals("upgrade_damage3") || group.equals("upgrade_damage4")) {
            Matrix4 mat = new Matrix4(transform.get().getMatrix());
            mat.translate(.441f, 0, 0);
            return Optional.of(new TRSRTransformation(mat.toMatrix4f()));
        }
    }
    return transform;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 7 with TRSRTransformation

use of net.minecraftforge.common.model.TRSRTransformation in project MinecraftForge by MinecraftForge.

the class ItemLayerModel method bake.

public IBakedModel bake(IModelState state, final VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    Optional<TRSRTransformation> transform = state.apply(Optional.<IModelPart>absent());
    for (int i = 0; i < textures.size(); i++) {
        TextureAtlasSprite sprite = bakedTextureGetter.apply(textures.get(i));
        builder.addAll(getQuadsForSprite(i, sprite, format, transform));
    }
    TextureAtlasSprite particle = bakedTextureGetter.apply(textures.isEmpty() ? new ResourceLocation("missingno") : textures.get(0));
    ImmutableMap<TransformType, TRSRTransformation> map = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
    return new BakedItemModel(builder.build(), particle, map, overrides, null);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) ImmutableList(com.google.common.collect.ImmutableList) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)

Example 8 with TRSRTransformation

use of net.minecraftforge.common.model.TRSRTransformation in project MinecraftForge by MinecraftForge.

the class ModelDynBucket method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap<TransformType, TRSRTransformation> transformMap = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
    // if the fluid is a gas wi manipulate the initial state to be rotated 180° to turn it upside down
    if (flipGas && fluid != null && fluid.isGaseous()) {
        state = new ModelStateComposition(state, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(null, new Quat4f(0, 0, 1, 0), null, null)));
    }
    TRSRTransformation transform = state.apply(Optional.<IModelPart>absent()).or(TRSRTransformation.identity());
    TextureAtlasSprite fluidSprite = null;
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    if (fluid != null) {
        fluidSprite = bakedTextureGetter.apply(fluid.getStill());
    }
    if (baseLocation != null) {
        // build base (insidest)
        IBakedModel model = (new ItemLayerModel(ImmutableList.of(baseLocation))).bake(state, format, bakedTextureGetter);
        builder.addAll(model.getQuads(null, null, 0));
    }
    if (liquidLocation != null && fluidSprite != null) {
        TextureAtlasSprite liquid = bakedTextureGetter.apply(liquidLocation);
        // build liquid layer (inside)
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, NORTH_Z_FLUID, EnumFacing.NORTH, fluid.getColor()));
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, SOUTH_Z_FLUID, EnumFacing.SOUTH, fluid.getColor()));
    }
    if (coverLocation != null) {
        // cover (the actual item around the other two)
        TextureAtlasSprite base = bakedTextureGetter.apply(coverLocation);
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, NORTH_Z_BASE, base, EnumFacing.NORTH, 0xffffffff));
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, SOUTH_Z_BASE, base, EnumFacing.SOUTH, 0xffffffff));
    }
    return new BakedDynBucket(this, builder.build(), fluidSprite, format, Maps.immutableEnumMap(transformMap), Maps.<String, IBakedModel>newHashMap());
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ImmutableList(com.google.common.collect.ImmutableList) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType) IModelPart(net.minecraftforge.common.model.IModelPart) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Quat4f(javax.vecmath.Quat4f) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Example 9 with TRSRTransformation

use of net.minecraftforge.common.model.TRSRTransformation in project ImmersiveEngineering by BluSunrize.

the class TileEntityConnectorStructural method applyTransformations.

@Override
public Optional<TRSRTransformation> applyTransformations(IBlockState object, String group, Optional<TRSRTransformation> transform) {
    Matrix4 mat = transform.isPresent() ? new Matrix4(transform.get().getMatrix()) : new Matrix4();
    mat = mat.translate(.5, 0, .5).rotate(Math.toRadians(rotation), 0, 1, 0).translate(-.5, 0, -.5);
    transform = Optional.of(new TRSRTransformation(mat.toMatrix4f()));
    return transform;
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 10 with TRSRTransformation

use of net.minecraftforge.common.model.TRSRTransformation 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

TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)12 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)5 Matrix4f (javax.vecmath.Matrix4f)3 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)3 ImmutableList (com.google.common.collect.ImmutableList)2 Vector3f (javax.vecmath.Vector3f)2 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 OBJState (net.minecraftforge.client.model.obj.OBJModel.OBJState)2 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 ShaderWrapper (blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper)1 IShaderItem (blusunrize.immersiveengineering.api.shader.IShaderItem)1 ShaderCase (blusunrize.immersiveengineering.api.shader.ShaderCase)1 ShaderLayer (blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Nullable (javax.annotation.Nullable)1 Matrix3f (javax.vecmath.Matrix3f)1