Search in sources :

Example 16 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project AgriCraft by AgriCraft.

the class BlockWaterPad method getExtendedState.

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
    SidedConnection connection = new SidedConnection();
    for (EnumFacing facing : EnumFacing.HORIZONTALS) {
        IBlockState stateAt = world.getBlockState(pos.offset(facing));
        connection.setConnected(facing, stateAt.getBlock() == state.getBlock());
    }
    return ((IExtendedBlockState) state).withProperty(AgriProperties.CONNECTIONS, connection);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) SidedConnection(com.infinityraider.infinitylib.block.blockstate.SidedConnection) EnumFacing(net.minecraft.util.EnumFacing)

Example 17 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project AgriCraft by AgriCraft.

the class RenderCrop method renderWorldBlockStatic.

@Override
public void renderWorldBlockStatic(ITessellator tessellator, IBlockState state, BlockCrop block, EnumFacing side) {
    TextureAtlasSprite sprite = RenderCrop.getIcon(TEXTURE);
    this.renderBaseQuads(tessellator, side, sprite);
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState extendedState = (IExtendedBlockState) state;
        IAgriPlant plant = extendedState.getValue(AgriProperties.CROP_PLANT);
        int growthstage = extendedState.getValue(AgriProperties.GROWTH_STAGE);
        if (extendedState.getValue(AgriProperties.CROSS_CROP)) {
            tessellator.drawScaledPrism(0, 10, 2, 16, 11, 3, sprite);
            tessellator.drawScaledPrism(0, 10, 13, 16, 11, 14, sprite);
            tessellator.drawScaledPrism(2, 10, 0, 3, 11, 16, sprite);
            tessellator.drawScaledPrism(13, 10, 0, 14, 11, 16, sprite);
        }
        if (plant != null) {
            tessellator.addQuads(plant.getPlantQuads(extendedState, growthstage, side, tessellator));
        }
    }
}
Also used : IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState)

Example 18 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project AgriCraft by AgriCraft.

the class RenderSprinkler method renderWorldBlockStatic.

@Override
public void renderWorldBlockStatic(ITessellator tessellator, IBlockState state, BlockSprinkler block, EnumFacing side) {
    tessellator.translate(0, 4 * Constants.UNIT, 0);
    CustomWoodType type;
    if (state instanceof IExtendedBlockState) {
        type = ((IExtendedBlockState) state).getValue(AgriProperties.CUSTOM_WOOD_TYPE);
    } else {
        type = CustomWoodTypeRegistry.DEFAULT;
    }
    tessellator.drawScaledPrism(4, 8, 4, 12, 16, 12, type.getIcon());
}
Also used : IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) CustomWoodType(com.infinityraider.agricraft.utility.CustomWoodType)

Example 19 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState in project AgriCraft by AgriCraft.

the class RenderWaterPad method renderWorldBlockStatic.

@Override
public void renderWorldBlockStatic(ITessellator tessellator, IBlockState state, BlockWaterPad block, EnumFacing side) {
    // Icon
    final TextureAtlasSprite matIcon = BaseIcons.DIRT.getIcon();
    final TextureAtlasSprite waterIcon = BaseIcons.WATER_STILL.getIcon();
    // Check Full
    SidedConnection connection = state instanceof IExtendedBlockState ? ((IExtendedBlockState) state).getValue(AgriProperties.CONNECTIONS) : DEFAULT;
    // Draw Base
    renderBase(tessellator, matIcon);
    // Render Sides
    for (EnumFacing dir : EnumFacing.HORIZONTALS) {
        if (!connection.isConnected(dir)) {
            renderSide(tessellator, dir, matIcon);
        }
    }
    // Render Water
    if (AgriProperties.POWERED.getValue(state)) {
        renderWater(tessellator, waterIcon);
    }
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) SidedConnection(com.infinityraider.infinitylib.block.blockstate.SidedConnection) EnumFacing(net.minecraft.util.EnumFacing)

Example 20 with IExtendedBlockState

use of net.minecraftforge.common.property.IExtendedBlockState 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

IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)29 IBlockState (net.minecraft.block.state.IBlockState)8 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)8 OBJState (net.minecraftforge.client.model.obj.OBJModel.OBJState)8 TileEntity (net.minecraft.tileentity.TileEntity)6 EnumFacing (net.minecraft.util.EnumFacing)6 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)5 BlockPos (net.minecraft.util.math.BlockPos)5 TileEntityImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable)4 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)4 CustomWoodType (com.infinityraider.agricraft.utility.CustomWoodType)2 SidedConnection (com.infinityraider.infinitylib.block.blockstate.SidedConnection)2 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)2 IModelState (net.minecraftforge.common.model.IModelState)2 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 SideConfig (blusunrize.immersiveengineering.api.IEEnums.SideConfig)1 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)1 ShaderWrapper (blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper)1 IShaderItem (blusunrize.immersiveengineering.api.shader.IShaderItem)1 ShaderCase (blusunrize.immersiveengineering.api.shader.ShaderCase)1