Jump to content

Recommended Posts

Posted

Hello

 

Is there a way to create a block which has a texture composed of multiple layers and color overlays?

 

i.e for items, I have a background and a foreground texture, both white, which are rendered with a different color (see below). I would like to do the same with a block. is that possible?

in the Item class

@Override
    public IIcon getIconFromDamageForRenderPass(int meta, int pass){
    	if(hasCustomIcon)return this.itemIcon;
        if(pass == 0){
            return icon_foreground;
        }else {
            return icon_background;
        }
    }
@Override
    public boolean requiresMultipleRenderPasses()
    {
        return true;
    }
    /** sets the item's color based on the itemstack
     * 
     */
    @Override
    @SideOnly(Side.CLIENT)
    public int getColorFromItemStack(ItemStack stack, int pass)
    {
        //if there is a custom icon registered, return the same thing as Item
        if(hasCustomIcon)return 16777215;
        //otherwise, return the colors of the dust
        IDust dust = DustRegistry.getDustFromItemStack(stack);
        return pass == 0 ? dust.getPrimaryColor(stack) : dust.getSecondaryColor(stack);
       
    }
    /** sets the icon of the dust.
     * default is based on the primary and secondary colors. 
     * override for custom icon
     * 
     * @param ireg 
     */
    @SideOnly(Side.CLIENT)
    @Override
    public void registerIcons(IIconRegister ireg){
    	hasCustomIcon=false;
        //just the plain one for now
        icon_foreground = ireg.registerIcon(References.texture_path + "dust_item_fore");
        icon_background = ireg.registerIcon(References.texture_path + "dust_item_sub");
    }

thaks.

 

also, sorry for the undescriptive title, I find this problem hard to explain for some reason.

Posted

Its probably possible, but I don't know how to do it. Just try looking at the vanilla class files. Vanilla Minecraft does that with various items like potions and spawn eggs.

Posted

Its probably possible, but I don't know how to do it. Just try looking at the vanilla class files. Vanilla Minecraft does that with various items like potions and spawn eggs.

 

I think he's trying to do it for blocks :P

 

I would take a look at the BlockGrass file, seeing as how the actual "grassy" part of the texture is layered onto a dirt texture and then color-changed depending on its biome.

Kain

Posted

thanks, although I don't see where to set the textures/colors in that. also, will i need one renderer per block?

 

the goal is to simplify adding "dusts" to my mod, making it so the dusts are created by specifying background and foreground colors, and the item and storage block are automatically created.

Posted

Hi

 

In your ISimpleBlockRenderingHandler, use the Tessellator to render your first layer, then the second layer, then the third, etc.

You can use the same ISimpleBlockRenderingHandler for multiple blocks, just register it for each one and check for the block type in your renderer.

 

You can use two passes for blocks, but they are handled differently to "passes" in items.  pass 0 is for fully opaque, pass1 is for translucent (partially opaque).  That might not be what you want...

 

-TGG

 

Posted

Hi

 

There's a bit about the Tessellator here

http://greyminecraftcoder.blogspot.com.au/2013/08/the-tessellator.html

 

Here's an old example from 1.6.4 which should give you the idea of how an ISBRH works

https://github.com/TheGreyGhost/ItemRendering/blob/master/src/TestItemRendering/blocks/BlockPyramidRenderer.java

and

https://github.com/TheGreyGhost/ItemRendering/blob/master/src/TestItemRendering/blocks/BlockPyramid.java

 

register it with

    RenderingRegistry.registerBlockHandler(new BlockPyramidRenderer());

 

I think it still works in 1.7.10... but I haven't tried it.  It should get you most of the way there at least.

 

-TGG

Posted

Thanks. things look like they should work in 1.7, although I am still unsure of how to render the texture in layers (I should be able to figure it out eventually). I did hope I could create the final texture directly in the block class, but it does not look possible without using "regular" Java image modification (which can be painful/slow) unless there are methods to modify/create IIcons directly

 

EDIT: also, is block metadata passed to renderWorldBlock ? I need it to get the right colors forget that, I got it (world.getBlockMetadata).

Posted

I think I figured part of it out, but the results I get are not what I'd expect, and I can't find what I'm doing wrong. probably related to vertex position and normals though.

 

ISimpleBlockRenderingHandler: (look at the last method. I also commented most faces out to try to get it right one face at a time)

package com.zpig333.runesofwizardry.client.render;

import com.zpig333.runesofwizardry.api.IDust;
import com.zpig333.runesofwizardry.api.IDustStorageBlock;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;

import org.lwjgl.opengl.GL11;


public class DustStorageRenderer implements ISimpleBlockRenderingHandler{
    private static int dustStorageRenderID;
    //following a "singleton" pattern since I don't like having a public constructor changing a static variable (could mess stuff up)
    private static DustStorageRenderer instance = null;
    private DustStorageRenderer(){
        dustStorageRenderID = RenderingRegistry.getNextAvailableRenderId();
    }
    public static int getRenderID(){
        return dustStorageRenderID;
    }
    public static DustStorageRenderer getInstance(){
        if(instance==null){
            instance=new DustStorageRenderer();
        }
        return instance;
    }
    @Override
    public void renderInventoryBlock(Block ablock, int metadata, int modelId, RenderBlocks renderer) {
        if (ablock instanceof IDustStorageBlock) {
            IDustStorageBlock block = (IDustStorageBlock) ablock;

            //thanks to TheGreyGhost for this https://github.com/TheGreyGhost/ItemRendering/blob/master/src/TestItemRendering/blocks/BlockPyramidRenderer.java
            Tessellator tes = Tessellator.instance;
            // if you don't perform this translation, the item won't sit in the player's hand properly in 3rd person view
            GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
            // for "inventory" blocks (actually for items which are equipped, dropped, or in inventory), should render in [0,0,0] to [1,1,1]
            tes.startDrawingQuads();
            renderDustBlock(tes, 0.0, 0.0, 0.0, metadata, block);
            tes.draw();
            // don't forget to undo the translation you made at the start
            GL11.glTranslatef(0.5F, 0.5F, 0.5F);
        }
    }

    @Override
    public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block ablock, int modelId, RenderBlocks renderer) {
        if (ablock instanceof IDustStorageBlock) {
            IDustStorageBlock block = (IDustStorageBlock) ablock;
            Tessellator tessellator = Tessellator.instance;
            // world blocks should render in [x,y,z] to [x+1, y+1, z+1]
            // tessellator.startDrawingQuads() has already been called by the caller
            int lightValue = block.getMixedBrightnessForBlock(world, x, y, z);
            tessellator.setBrightness(lightValue);
            tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
            renderDustBlock(tessellator, (double)x, (double)y, (double) z, world.getBlockMetadata(x, y, z), block);
            // tessellator.draw() will be called by the caller after return
            return true;
        }
        return false;
    }
    

    @Override
    public boolean shouldRender3DInInventory(int modelId) {
        return true;
    }

    @Override
    public int getRenderId() {
        return dustStorageRenderID;
    }

    private void renderDustBlock(Tessellator tessellator, double x, double y, double z, int meta, IDustStorageBlock block) {
        //TODO most of the work: renderDustBlock
        IDust dust = block.getIDust();
        ItemStack dustStack = new ItemStack(dust,1);
        IIcon bgIcon = block.getBackgroundIcon();
        IIcon fgIcon = block.getForegroundIcon();
        bgIcon = Blocks.lapis_block.getIcon(0, 0);
        fgIcon = Blocks.bedrock.getIcon(0, 0);
        double minUBG = (double) bgIcon.getMinU();
        double minVBG = (double) bgIcon.getMinV();
        double maxUBG = (double) bgIcon.getMaxU();
        double maxVBG = (double) bgIcon.getMaxV();
        //foreground texture
        double minUFG = (double) fgIcon.getMinU();
        double minVFG = (double) fgIcon.getMinV();
        double maxUFG = (double) fgIcon.getMaxU();
        double maxVFG = (double) fgIcon.getMaxV();
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        // east face
        //background color
        tessellator.setNormal(1F, 0F, 0.0F);
        tessellator.setColorRGBA_I(dust.getPrimaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 1.0, z + 0.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 1.0, z + 0, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 0, z + 0, minUBG, maxVBG);
        /*
        //fg color
        tessellator.setColorRGBA_I(dust.getSecondaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 1.0, z + 0.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 1.0, z + 0, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 0, z + 0, minUBG, maxVBG);
        tessellator.draw();
        // west face
        tessellator.startDrawingQuads();
        tessellator.setNormal(-1, 0, 0.0F);
        tessellator.setColorRGBA_I(dust.getPrimaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 0.0, y + 0.0, z + 1.0, minUBG, maxVBG);
        tessellator.addVertexWithUV(x + 0.0, y + 0.0, z + 1.0, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 0.0, y + 0.0, z + 0.0, maxUBG, maxVBG);
        tessellator.setColorRGBA_I(dust.getSecondaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1.0, minUFG, maxVFG);
        tessellator.draw();
        // north face
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        //background color
        tessellator.startDrawingQuads();
        tessellator.setNormal(0, 0F, 1);
        tessellator.setColorRGBA_I(dust.getPrimaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1.0, minUBG, maxVBG);
        //fg color
        tessellator.setColorRGBA_I(dust.getSecondaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1.0, minUFG, maxVFG);
        tessellator.draw();
        // south face
        tessellator.startDrawingQuads();
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        //background color
        tessellator.setNormal(0, 0F, 1);
        tessellator.setColorRGBA_I(dust.getPrimaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1.0, minUBG, maxVBG);
        //fg color
        tessellator.setColorRGBA_I(dust.getSecondaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1.0, minUFG, maxVFG);
        tessellator.draw();
        // bottom face
        tessellator.startDrawingQuads();
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        //background color
        tessellator.setNormal(0, -1F, 0.0F);
        tessellator.setColorRGBA_I(dust.getPrimaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1.0, minUBG, maxVBG);
        //fg color
        tessellator.setColorRGBA_I(dust.getSecondaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1.0, minUFG, maxVFG);
        tessellator.draw();
        // UP face
        tessellator.startDrawingQuads();
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        //background color
        tessellator.setNormal(0, 1F, 0.0F);
        tessellator.setColorRGBA_I(dust.getPrimaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1.0, minUBG, maxVBG);
        //fg color
        tessellator.setColorRGBA_I(dust.getSecondaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 1, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1.0, minUFG, maxVFG);
*/
    }
}

 

result (notice how the north/south face is rendering when I'm trying to render the east face)

http://prntscr.com/5ff8xe

(couldn't figure out how to post the image properly)

Posted

Hi

 

Your code is a bit mixed up on which face points in which direction.  The Tessellator is hard to get right, when I was first getting used to it I had to hold a cardboard box and label it with a pen to get the vertices right.

 

So for example

        // east face
        //background color
        tessellator.setNormal(1F, 0F, 0.0F);
        tessellator.setColorRGBA_I(dust.getPrimaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0.0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 1.0, z + 0.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 1.0, z + 0, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 0, z + 0, minUBG, maxVBG);

 

The east face is the one which is located with all xpos = x+1, so none of the points in the face are located with xpos = x+0.  The code above has all points located at zpos = z+0,  which is the north face.

In order to do the east face, you need

(x+1, y+0, z+0, maxUBG, maxVBG)

(x+1, y+1, z+0, maxUBG, minVBG)

(x+1, y+1, z+1, minUBG, minVBG)

(x+1, y+0, z+1, minUBG, maxVBG)

The normal is right.

 

-TGG

Posted
Your code is a bit mixed up on which face points in which direction.  The Tessellator is hard to get right, when I was first getting used to it I had to hold a cardboard box and label it with a pen to get the vertices right.

 

And even then you'll fuck it up once in a while.

 

Doing this correctly took me like four hours even with a properly labeled drawing of which faces face which direction and have to be constructed in what order.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Now that was one well hidden shameless plug. :P

 

For a 1.6.4 micromod that I've since misplaced the code for (no really, I was syncing everything to dropbox and somewhere along the way I deleted the folders for everything pre-1.6.4).  Sure. :D

 

1.6.4.?  Nein, 1.5.1. and 1.6.2

 

It's one I do want to remake for 1.7 though, it's very useful.  I'd drop the slope support though, it was slightly buggy (the custom rail required air below it, so if you tried to connect a slope to a vanilla rail that was on the ground, it would work....until that rail received a block update).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

yay, I managed to get a cube rendering! making a box with the coordinates of the different corners helped a lot.

 

however, I can't get it to render the multiple textures, and my UP face is completely black when using my custom texture (it was working when I used the sand texture)

 

renderer:

package com.zpig333.runesofwizardry.client.render;

import com.zpig333.runesofwizardry.api.IDust;
import com.zpig333.runesofwizardry.api.IDustStorageBlock;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;

import org.lwjgl.opengl.GL11;


public class DustStorageRenderer implements ISimpleBlockRenderingHandler{
    private static int dustStorageRenderID;
    //following a "singleton" pattern since I don't like having a public constructor changing a static variable (could mess stuff up)
    private static DustStorageRenderer instance = null;
    private DustStorageRenderer(){
        dustStorageRenderID = RenderingRegistry.getNextAvailableRenderId();
    }
    public static int getRenderID(){
        return dustStorageRenderID;
    }
    public static DustStorageRenderer getInstance(){
        if(instance==null){
            instance=new DustStorageRenderer();
        }
        return instance;
    }
    @Override
    public void renderInventoryBlock(Block ablock, int metadata, int modelId, RenderBlocks renderer) {
        if (ablock instanceof IDustStorageBlock) {
            IDustStorageBlock block = (IDustStorageBlock) ablock;

            //thanks to TheGreyGhost for this https://github.com/TheGreyGhost/ItemRendering/blob/master/src/TestItemRendering/blocks/BlockPyramidRenderer.java
            Tessellator tes = Tessellator.instance;
            // if you don't perform this translation, the item won't sit in the player's hand properly in 3rd person view
            GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
            // for "inventory" blocks (actually for items which are equipped, dropped, or in inventory), should render in [0,0,0] to [1,1,1]
            tes.startDrawingQuads();
            renderDustBlock(tes, 0.0, 0.0, 0.0, metadata, block);
            tes.draw();
            // don't forget to undo the translation you made at the start
            GL11.glTranslatef(0.5F, 0.5F, 0.5F);
        }
    }

    @Override
    public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block ablock, int modelId, RenderBlocks renderer) {
        if (ablock instanceof IDustStorageBlock) {
            IDustStorageBlock block = (IDustStorageBlock) ablock;
            Tessellator tessellator = Tessellator.instance;
            // world blocks should render in [x,y,z] to [x+1, y+1, z+1]
            // tessellator.startDrawingQuads() has already been called by the caller
            int lightValue = block.getMixedBrightnessForBlock(world, x, y, z);
            tessellator.setBrightness(lightValue);
            tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
            renderDustBlock(tessellator, (double)x, (double)y, (double) z, world.getBlockMetadata(x, y, z), block);
            // tessellator.draw() will be called by the caller after return
            return true;
        }
        return false;
    }
    

    @Override
    public boolean shouldRender3DInInventory(int modelId) {
        return true;
    }

    @Override
    public int getRenderId() {
        return dustStorageRenderID;
    }

    private void renderDustBlock(Tessellator tessellator, double x, double y, double z, int meta, IDustStorageBlock block) {
        //TODO most of the work: renderDustBlock
        IDust dust = block.getIDust();
        ItemStack dustStack = new ItemStack(dust,1,meta);
        IIcon bgIcon = block.getBackgroundIcon();
        IIcon fgIcon = block.getForegroundIcon();
        int primaryColor = dust.getPrimaryColor(dustStack);
        int secondaryColor = dust.getSecondaryColor(dustStack);
        //bgIcon = Blocks.sand.getIcon(0, 0);
        //fgIcon = Blocks.bedrock.getIcon(0, 0);
        double minUBG = (double) bgIcon.getMinU();
        double minVBG = (double) bgIcon.getMinV();
        double maxUBG = (double) bgIcon.getMaxU();
        double maxVBG = (double) bgIcon.getMaxV();
        //foreground texture
        double minUFG = (double) fgIcon.getMinU();
        double minVFG = (double) fgIcon.getMinV();
        double maxUFG = (double) fgIcon.getMaxU();
        double maxVFG = (double) fgIcon.getMaxV();
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        // east face
        //background color
        tessellator.draw();//flush
        tessellator.startDrawingQuads();
        tessellator.setNormal(1F, 0F, 0.0F);
        tessellator.setColorRGBA_I(primaryColor, 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 1.0, z + 0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 1.0, z + 1, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0, z + 1, minUBG, maxVBG);
        tessellator.draw();
        
        //fg color
        tessellator.startDrawingQuads();
        tessellator.setNormal(1F, 0F, 0.0F);
        tessellator.setColorRGBA_I(secondaryColor, 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 1.0, z + 0, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 1.0, z + 1, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0, z + 1, minUFG, maxVFG);
        tessellator.draw();
        
        // west face
        tessellator.startDrawingQuads();
        tessellator.setNormal(-1, 0, 0.0F);
        tessellator.setColorRGBA_I(primaryColor, 0xFF);
        tessellator.addVertexWithUV(x + 0.0, y + 0.0, z + 1.0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 0.0, y + 1.0, z + 1.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 0.0, y + 1.0, z + 0, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 0.0, y + 0.0, z + 0.0, minUBG, maxVBG);
        tessellator.draw();
        
        tessellator.startDrawingQuads();
        tessellator.setNormal(-1, 0, 0.0F);
        tessellator.setColorRGBA_I(secondaryColor, 0xFF);
        tessellator.addVertexWithUV(x + 0.0, y + 0.0, z + 1.0, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 0.0, y + 1.0, z + 1.0, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 0.0, y + 1.0, z + 0, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 0.0, y + 0.0, z + 0.0, minUFG, maxVFG);
        
        tessellator.draw();
        // north face
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        //background color
        tessellator.startDrawingQuads();
        tessellator.setNormal(0, 0F, 1);
        tessellator.setColorRGBA_I(primaryColor, 0xFF);
        tessellator.addVertexWithUV(x + 0, y + 0.0, z + 0.0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 0, y + 1, z + 0.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 0, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0, minUBG, maxVBG);
        tessellator.draw();
        
        //fg color
        tessellator.startDrawingQuads();
        tessellator.setNormal(0, 0F, 1);
        tessellator.setColorRGBA_I(secondaryColor, 0xFF);
        tessellator.addVertexWithUV(x + 0, y + 0.0, z + 0.0, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 0, y + 1, z + 0.0, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 1, y + 1.0, z + 0, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 0, minUFG, maxVFG);
        
        tessellator.draw();
        // south face
        tessellator.startDrawingQuads();
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        //background color
        tessellator.setNormal(0, 0F, 1);
        tessellator.setColorRGBA_I(dust.getPrimaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 1, z + 1, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 1.0, z + 1, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 0.0, z + 1.0, minUBG, maxVBG);
        tessellator.draw();
        //fg color
        tessellator.startDrawingQuads();
        tessellator.setNormal(0, 0F, 1);
        tessellator.setColorRGBA_I(secondaryColor, 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 1, z + 1, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 0, y + 1.0, z + 1, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 0, y + 0.0, z + 1.0, minUFG, maxVFG);
        
        tessellator.draw();
        // bottom face
        tessellator.startDrawingQuads();
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        //background color
        tessellator.setNormal(0, -1F, 0.0F);
        tessellator.setColorRGBA_I(primaryColor, 0xFF);
        tessellator.addVertexWithUV(x + 1, y + 0.0, z + 0, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 0, z + 1, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 0.0, z + 0, minUBG, maxVBG);
        tessellator.draw();
        //fg color
        tessellator.startDrawingQuads();
        tessellator.setNormal(0, -1F, 0.0F);
        tessellator.setColorRGBA_I(dust.getSecondaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1, y + 0.0, z + 0, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 0.0, z + 1, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 0, y + 0, z + 1, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 0, y + 0.0, z + 0, minUFG, maxVFG);
        
        tessellator.draw();
        // UP face
        tessellator.startDrawingQuads();
        //NOrmals: X+ = east, Y+ =up, z+ = south 
        //background color
        tessellator.setNormal(0, 1F, 0.0F);
        tessellator.setColorRGBA_I(primaryColor, 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 1, z + 1, maxUBG, maxVBG);
        tessellator.addVertexWithUV(x + 1.0, y + 1, z + 0.0, maxUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y + 1.0, z + 0, minUBG, minVBG);
        tessellator.addVertexWithUV(x + 0, y +1, z + 1.0, minUBG, maxVBG);
        tessellator.draw();
        //fg color
        tessellator.startDrawingQuads();
        tessellator.setNormal(0, 1F, 0.0F);
        tessellator.setColorRGBA_I(dust.getSecondaryColor(dustStack), 0xFF);
        tessellator.addVertexWithUV(x + 1.0, y + 1, z + 1, maxUFG, maxVFG);
        tessellator.addVertexWithUV(x + 1.0, y + 1, z + 0.0, maxUFG, minVFG);
        tessellator.addVertexWithUV(x + 0, y + 1.0, z + 0, minUFG, minVFG);
        tessellator.addVertexWithUV(x + 0, y +1, z + 1.0, minUFG, maxVFG);

    }
}

Posted

Definitely something wrong here, But I dont know enough to say what. my guess is that it is related to either having two "faces" per block side or the transparency.

 

screenshot: (the color is fading in and out for some reason)

 

http://prntscr.com/5hohza

 

also, I would be very happy if someone would explain to me how to post images on this forum...

Posted

also, I would be very happy if someone would explain to me how to post images on this forum...

 

An [img ] tag with a URL in it that ends in .jpg, .png, or .gif

 

In this case, http://i.imgur.com/j1sL26u.png

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Hi

 

A couple of things-

1) if you are going to use brightness, you need to tessellator.setBrightness(lightValue); after every tessellator.startDrawingQuads(); because the tessellator.draw(); resets the brightness to zero.

2) for transparent blocks, the appropriate light value is the one you use, i.e.  int lightValue = block.getMixedBrightnessForBlock(world, x, y, z);

    but for opaque blocks, you need to take the light value for each face from the adjacent block, because the light value for the block itself is zero, eg

int lightValue = block.getMixedBrightnessForBlock(world, x+1, y, z); if you are drawing the east face.

3) If you are drawing the FG on top of the BG you should 'nudge' the FG face out by a very small amount to make sure it renders over the top of the BG face.  Otherwise it can get partially hidden or lead to weird stripy effects.  For example, for the east face, draw BG at x+1, and the FG at x+1.001;

 

Apart from that, your code looks ok to me.  Are you sure your dust.getSecondaryColor(dustStack) etc are correct?  the setNormals should only be required for inventory displaying; I don't think it should hurt to have them for block rendering too but you could try commenting them out if you are still having trouble.

 

-TGG

Posted

After a bit more testing, it seems the problem is my textures, since it works fine when using vanilla textures. How should transparency be handled? I currently have two png files with transparent pixels.

Posted

Hi

 

Minecraft uses two kinds of transparency -

the first is "on/off" transparency - any texels with an alpha less than 0.1 are fully transparent, any texels with an alpha of 0.1 or more are drawn fully opaque.  this is the "pass 0 " rendering.  Are you sure your png files have the proper alpha channel?

the second is alpha-blending transparency, where the texels are drawn according to their alpha level eg 0.6 means 60% opaque, 40% transparent.  this is "pass 1".

 

I think you want the on/off kind.  If you use alpha values of 0.0 or 1.0 (0 or 255) it should work fine.  If you are colouring the overlays afterwards, the png should have white texels - i.e. if your texels are green, and you try to colour them blue when rendering, you will get black.

 

-TGG

Posted

the second is alpha-blending transparency, where the texels are drawn according to their alpha level eg 0.6 means 60% opaque, 40% transparent.  this is "pass 1".

 

Note:

In pass 1, alpha below 0.1 is also drawn as fully transparent.  It's really annoying.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

the texels are either fully opaque or fully transparent, so the problem must be somewhere else... It seems that the textures are not correctly loaded, since a println of them in the renderer returns the following:

TextureAtlasSprite{name='runesofwizardry:dustStorage_bg', frameCount=0, rotated=false, x=0, y=0, height=0, width=0, u0=0.0, u1=0.0, v0=0.0, v1=0.0}

 

however, the log shows no message about a missing texture. Here is my block class:

package com.zpig333.runesofwizardry.api;

import net.minecraft.block.BlockFalling;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;

import com.zpig333.runesofwizardry.client.render.DustStorageRenderer;
import com.zpig333.runesofwizardry.core.References;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public abstract class IDustStorageBlock extends BlockFalling {
    //Icons for the background and foreground
    private static IIcon bgIcon,fgIcon;
    public IDustStorageBlock(Material mat){
        super(mat);
    }
    /** returns the dust that forms this block **/
    public abstract IDust getIDust();
    @Override
    public int damageDropped(int i) {
        return i;
    }
    public IIcon getBackgroundIcon(){
        return bgIcon;
    }
    public IIcon getForegroundIcon(){
        return fgIcon;
    }
    //TODO finish setting up the block
    //TODO Icons and stuff

    @Override
    public void registerBlockIcons(IIconRegister reg) {
        //sand icon, used only for the particles when breaking block
        blockIcon = Blocks.sand.getIcon(0, 0);
        if(bgIcon==null||fgIcon==null){
            bgIcon = reg.registerIcon(References.texture_path+"dustStorage_bg");
            fgIcon = reg.registerIcon(References.texture_path+"dustStorage_fg");
        }
    }

    @Override
    public boolean renderAsNormalBlock() {
        return false;
    }

    @Override
    public int getRenderType() {
        return DustStorageRenderer.getRenderID();
    }
}

Posted

Update: it seems that removing the if(**Icon==null) statments before registering the textures fixed the problem. However, when the blocks fall, they get the sand texture. is there a (hopefully simple-ish) way to fix that?

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.