Jump to content

Draco18s

Members
  • Posts

    16559
  • Joined

  • Last visited

  • Days Won

    155

Posts posted by Draco18s

  1. You....are not doing things the way I'm doing them, and it does not appear that your....renderer has any quads or a model to draw.

     

    Here's mine:

     

    package draco18s.traps.client;
    
    import net.minecraft.client.renderer.entity.Render;
    import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
    import net.minecraft.entity.Entity;
    import net.minecraft.tileentity.TileEntity;
    
    public class SpikesRenderer extends TileEntitySpecialRenderer {
    private SpikesModel spikes = new SpikesModel();
    
    @Override
    public void renderTileEntityAt(TileEntity tileentity, double d0, double d1, double d2, float f) {
    	spikes.render(tileentity, d0, d1, d2);
    }
    }
    

     

    SpikesModel

     

    // Date: 6/9/2013 12:58:24 AM
    // Template version 1.1
    // Java generated by Techne
    // Keep in mind that you still need to fill in some blanks
    // - ZeuX
    
    package draco18s.traps.client;
    
    import org.lwjgl.opengl.GL11;
    
    import cpw.mods.fml.client.FMLClientHandler;
    import draco18s.traps.entities.EntitySpikes;
    
    import net.minecraft.client.model.ModelBase;
    import net.minecraft.client.model.ModelRenderer;
    import net.minecraft.entity.Entity;
    import net.minecraft.tileentity.TileEntity;
    
    public class SpikesModel extends ModelBase
    {
    //fields
    ModelRenderer Base;
    ModelRenderer SpikeLower2;
    ModelRenderer SpikeUpper2;
    ModelRenderer SpikeLower4;
    ModelRenderer SpikeUpper4;
    ModelRenderer SpikeLower1;
    ModelRenderer SpikeUpper1;
    ModelRenderer SpikeLower3;
    ModelRenderer SpikeUpper3;
    
    public SpikesModel()
    {
    	textureWidth = 64;
    	textureHeight = 32;
    
    	Base = new ModelRenderer(this, 0, 0);
    	Base.addBox(0F, 0F, 0F, 16, 1, 16);
    	Base.setRotationPoint(-8F, 8F, -8F);
    	Base.setTextureSize(64, 32);
    	Base.mirror = true;
    	setRotation(Base, 0F, 0F, 0F);
    	/*SpikeLower2 = new ModelRenderer(this, 32, 17);
    	SpikeLower2.addBox(-2F, 0F, -2F, 4, 5, 4);
    	SpikeLower2.setRotationPoint(-4F, 14F, 4F);
    	SpikeLower2.setTextureSize(64, 32);
    	SpikeLower2.mirror = true;
    	setRotation(SpikeLower2, 0F, 0F, 0F);
    	SpikeUpper2 = new ModelRenderer(this, 24, 17);
    	SpikeUpper2.addBox(-1F, 0F, -1F, 2, 8, 2);
    	SpikeUpper2.setRotationPoint(-4F, 22F, 4F);
    	SpikeUpper2.setTextureSize(64, 32);
    	SpikeUpper2.mirror = true;
    	setRotation(SpikeUpper2, 0F, 0F, 0F);*/
    	SpikeLower4 = new ModelRenderer(this, 0, 17);
    	SpikeLower4.addBox(0F, 0F, 0F, 4, 5, 4);
    	SpikeLower4.setRotationPoint(2F, 14F, -2F);
    	SpikeLower4.setTextureSize(64, 32);
    	SpikeLower4.mirror = true;
    	setRotation(SpikeLower4, 0F, 0F, 0F);
    	SpikeUpper4 = new ModelRenderer(this, 16, 17);
    	SpikeUpper4.addBox(0F, 0F, 0F, 2, 8, 2);
    	SpikeUpper4.setRotationPoint(3F, 22F, -3F);
    	SpikeUpper4.setTextureSize(64, 32);
    	SpikeUpper4.mirror = true;
    	setRotation(SpikeUpper4, 0F, 0F, 0F);
    	SpikeLower1 = new ModelRenderer(this, 0, 17);
    	SpikeLower1.addBox(-2F, 0F, -2F, 4, 5, 4);
    	SpikeLower1.setRotationPoint(-4F, 14F, -4F);
    	SpikeLower1.setTextureSize(64, 32);
    	SpikeLower1.mirror = true;
    	setRotation(SpikeLower1, 0F, 0F, 0F);
    	SpikeUpper1 = new ModelRenderer(this, 16, 17);
    	SpikeUpper1.addBox(-1F, 0F, -1F, 2, 8, 2);
    	SpikeUpper1.setRotationPoint(-4F, 22F, -4F);
    	SpikeUpper1.setTextureSize(64, 32);
    	SpikeUpper1.mirror = true;
    	setRotation(SpikeUpper1, 0F, 0F, 0F);
    	SpikeLower3 = new ModelRenderer(this, 0, 17);
    	SpikeLower3.addBox(-2F, 0F, -2F, 4, 5, 4);
    	SpikeLower3.setRotationPoint(4F, 14F, 4F);
    	SpikeLower3.setTextureSize(64, 32);
    	SpikeLower3.mirror = true;
    	setRotation(SpikeLower3, 0F, 0F, 0F);
    	SpikeUpper3 = new ModelRenderer(this, 16, 17);
    	SpikeUpper3.addBox(-1F, 0F, -1F, 2, 8, 2);
    	SpikeUpper3.setRotationPoint(4F, 22F, 4F);
    	SpikeUpper3.setTextureSize(64, 32);
    	SpikeUpper3.mirror = true;
    	setRotation(SpikeUpper3, 0F, 0F, 0F);
    }
    
    public void render(TileEntity te, double x, double y, double z) {
    	EntitySpikes es = (EntitySpikes)te;
    	setBlood(es.isBloody);
    	GL11.glPushMatrix();
    	GL11.glTranslatef((float)x + 0.5f, (float)y - 0.5f, (float)z + 0.5f);
    	//GL11.glScalef(0.5f, 0.5f, 0.5f);
    	FMLClientHandler.instance().getClient().renderEngine.bindTexture("/mods/Traps/textures/entities/spike.png");
    	this.render();
        GL11.glPopMatrix();
    }
    
    private void render() {
    	setRotation(SpikeLower1, 3.1415F, 0, 0);
    	setRotation(SpikeLower2, 3.1415F, 0, 0);
    	setRotation(SpikeLower3, 3.1415F, 0, 0);
    	setRotation(SpikeLower4, 3.1415F, 0, 0);
    	setRotation(SpikeUpper1, 3.1415F, 0, 0);
    	setRotation(SpikeUpper2, 3.1415F, 0, 0);
    	setRotation(SpikeUpper3, 3.1415F, 0, 0);
    	setRotation(SpikeUpper4, 3.1415F, 0, 0);
    	Base.render(0.0625F);
    	SpikeLower1.render(0.0625F);
    	SpikeLower2.render(0.0625F);
    	SpikeLower3.render(0.0625F);
    	SpikeLower4.render(0.0625F);
    	SpikeUpper1.render(0.0625F);
    	SpikeUpper2.render(0.0625F);
    	SpikeUpper3.render(0.0625F);
    	SpikeUpper4.render(0.0625F);
    }
    
    private void setRotation(ModelRenderer model, float x, float y, float z)
    {
    	model.rotateAngleX = x;
    	model.rotateAngleY = y;
    	model.rotateAngleZ = z;
    }
    
    public void setBlood(int t) {
    	if(t == 2) {
    		SpikeLower2 = new ModelRenderer(this, 0, 0);
    		SpikeUpper2 = new ModelRenderer(this, 48, 0);
    	}
    	else if(t == 1) {
    		SpikeLower2 = new ModelRenderer(this, 32, 17);
    		SpikeUpper2 = new ModelRenderer(this, 24, 17);
    	}
    	else {
    		SpikeLower2 = new ModelRenderer(this, 0, 17);
    		SpikeUpper2 = new ModelRenderer(this, 16, 17);
    	}
    	SpikeLower2.addBox(-2F, 0F, -2F, 4, 5, 4);
    	SpikeLower2.setRotationPoint(-4F, 14F, 4F);
    	SpikeLower2.setTextureSize(64, 32);
    	SpikeLower2.mirror = true;
    	setRotation(SpikeLower2, 0F, 0F, 0F);
    	SpikeUpper2.addBox(-1F, 0F, -1F, 2, 8, 2);
    	SpikeUpper2.setRotationPoint(-4F, 22F, 4F);
    	SpikeUpper2.setTextureSize(64, 32);
    	SpikeUpper2.mirror = true;
    	setRotation(SpikeUpper2, 0F, 0F, 0F);
    }
    }
    

     

     

    Model was exported from Techne and minorly tweaked.*

     

    *Imports and oddly, the model came in upside down and I had to figure out how to flip it back over.

     

     

  2. I've been doing something similar, but the way I did it was to yoink the relevant block texture, render it, then render a second quad with my overlay on it, a very tiny fraction of a pixel above* the first quad.  Just enough offset so there's no z-fighting, but too small to see.  1F/256 is good.

     

    I have, however, been having a devil of a time getting block brightness to be calculated correctly.  Think I thought of a solution, and that's a faux block that gets rendered using the normal renderer after rendering the base material block in the same manner.

     

    *relative to the block face

  3. /**
         * Returns whether this block is collideable based on the arguments passed in Args: blockMetaData, unknownFlag
         */
        public boolean canCollideCheck(int par1, boolean par2)
        {
            return this.isCollidable();
        }

     

    The par2 boolean is a flag that relates to collision raycasts, say, by the player's mouse cursor.

     

    I had a dispenser-like block that I wanted to fire multiple arrows from, found that because of some offsets (so that they would be emitted from different locations, regardless of orientation) was causing some arrows to collide with the block itself.  So I looked into making the block non-collidable for that purpose.

     

    Found the above function (well, knew it existed, but implemented it for an override and did this:

     

    public boolean canCollideCheck(int par1, boolean par2)
        {
            return this.isCollidable() & par2;
        }

     

    I could now no longer right-click interact with my block, but the arrows passed through it as desired.

     

    Changed to

     

    public boolean canCollideCheck(int par1, boolean par2)
        {
            return this.isCollidable() | par2;
        }

     

    And retained the desired behavior and regained the ability to interact with it.

     

    Scratch that, was a total fluke due to the RNG.

    (There are 4 spots my arrows fire from, two of them collide, two don't, the test I thought things worked right was just a fluke of the RNG picking the two that worked).

     

    Back-tracing the code it appears that this boolean is true if and only if the player right-clicks while holding a boat.  I suspect that this code is used to place the boat on top of water rather than underneath.

  4. Thanks so much.  Just understanding the basic structure of what I'm trying to do here will help a good deal.  In this example, should MyTileEntityRenderer also implement IMerchant and IInventory?  Rendering a gui is still a little confusing to me, but I know I need at least one of those two.

     

    Maybe?  I don't recognize those two classes at the moment.

  5. No, I mean beta 1.5_01, which is what that mod is written for. I first started somewhere around Beta 1.6.

     

    I'd gone looking.  And...I missed that version (apparently I skimmed the quicklinks which only went back to 1.7, so I'd moved on down to Alpha).

  6. Did this:

    int brightness = Block.blocksList[block.stone.blockID].getMixedBrightnessForBlock(world, x, y, z);

    Instead of this:

    int brightness = block.getMixedBrightnessForBlock(world, x, y, z);

     

    And it got better.  Only "flaw" is that it has the brightness/color of the top face rather than the side face of that location (specifically, the brightness/color of the top face of the block below where I'm rendering).

  7. Still need help with this.  Brightness integers are weird.

    I solved the alpha problem (seems that bits 9 to 16 effect the alpha, 21 to 24 are brightness, and the lowest 8 are color; 17 to 20 appear unused) but now I have an absolute brightness issue and color problem.

     

    I'm actually stripping out the 3rd bit of the absolute brightness to tone it down some (helps, but not enough in some cases; 4th bit too much in all cases).

     

    And this is what it looks like under various conditions:

     

    Full sun.  Color is off.  Absolute brightness perfect.

    Near-full darkness.  Very slight color difference.  Absolute brightness perfect.

    Torch light.  Color perfect.  Absolute brightness out of whack.

  8. Eurgh. I think it's more readable if you name those ContainerMyBlock, TileEntityMyBlock, and RenderMyBlock respectively. In fact, I need to get my partner atrain99 to rename our classes like that :P

     

    Whichever.  A lot of tutorials and such always do it as MyFoo and MyBar

  9. Good gracious! 1.5_01... that's about when I started playing Minecraft. I thought you said 1.2.5... Still, it can be done. Actually, it's easier. But it'll be a hard task for you to update...

     

    And before me, though not by much. (*cough* also I think you meant 1.0.5_01)

    I can't find my original registration date, but it's around Alpha v1.1.2_01, which is the earliest reference I have to my having played, only two weeks later.

  10. If you want an actually-blank third row* then just omit that parameter.

     

    GameRegistry.addRecipe(new ItemStack(ModItems.ClayIngot), new Object[]{ "x x", " x ", Character.valueOf('x'), ModItems.ClayIngot});

     

    Also, you can do 'x' instead of Character.valueOf('x'), Java distinguishes between " (for strings) and ' (for chars).

     

    *It's not a colum, DELTA_12, it's a row

  11. Step 1:

     

    class MyTileEntityBlock extends BlockContainer

     

    Yes, it creates a container but that's because the original vanilla TE objects have inventories.  You don't need to utilize this fact, nor do you need to utilize the NBT data that can easily get saved via entities.

     

    Step 2:

     

    class MyTileEntityEntity extends TileEntity

     

    This class is what's created when you place the block.  The parent class (BlockContainer) will throw an "add unimplemented methods" error, one of which will be function that returns a tile entity.  You'd add "return new MyTileEntityEntity()" there.  WARNING: do not pass parameters or change properties of the TE at this point, as you will want to read these values from the NBT data or they'll get reset on world load.

     

    Step 3

     

    public class MyTileEntityRenderer extends TileEntitySpecialRenderer

     

    This will handle your TE rendering.  You may also have a model that you're using or you might use the tessalator directly.  I've done both.

     

    Step 4

     

    In your base mod class:

    RenderingRegistry.registerBlockHandler(new MyTileEntityRenderer());

    You should also use RenderingRegistry.getNextAvailableRenderId() to get a rendering ID and pass it to both your block and render class.

  12. We'll start with a picture of what I have

     

    width=800 height=449http://s11.postimg.org/k3dpbpw83/2013_06_10_17_42_07.png[/img]

     

    The block itself actually exists in a different place than its rendering.  One block down and one block "in" (the block attaches to a solid surface, like a ladder, and renders 1 block below that in order to cover an open space, for tripwire hooks).

     

    Problem is, I can't get it to render at the correct brightness.  The getMixedBrightnessForBlock function seems to return full sun despite the fact that that space is not under full sun (if I cover things over it still renders too bright, although it does dim as the light value is reduced).

     

    How can I fix this?

     

    Render code:

    package draco18s.traps.client;
    
    import net.minecraft.block.Block;
    import net.minecraft.client.renderer.RenderBlocks;
    import net.minecraft.client.renderer.Tessellator;
    import net.minecraft.util.Icon;
    import net.minecraft.world.IBlockAccess;
    import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
    
    public class RenderCoverPlate implements ISimpleBlockRenderingHandler {
    private int renderType;
    
    public RenderCoverPlate(int r) {
    	renderType = r;
    }
    
    @Override
    public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
    
    }
    
    @Override
    public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
            
    	Tessellator tessellator = Tessellator.instance;
            int l = world.getBlockMetadata(x, y, z);
            //gets the texture based on block location, the block blends in to neighbors, grabbing their texture
            Icon icon = block.getBlockTexture(world, x, y, z, 2);
    
            double f = 1F/64;
            
            switch(l) {
            case 2:
            	z++;
            	break;
            case 3:
            	z--;
            	break;
            case 4:
            	x++;
            	break;
            case 5:
            	x--;
            	break;
            }
            y--;
            int brightness = block.getMixedBrightnessForBlock(world, x, y, z);
            tessellator.setBrightness(brightness);
            tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
            
            double d0 = (double)icon.getMinU();
            double d1 = (double)icon.getMinV();
            double d2 = (double)icon.getMaxU();
            double d3 = (double)icon.getMaxV();
            double d5 = (double)(x + 1);
            double d7 = (double)(x);
            double d9 = (double)(z);
            double d11 = (double)(z + 1);
            double d13 = (double)(y + 1);
            double d15 = (double)(y);
            
            tessellator.addVertexWithUV(d7, d13, d9, d2, d1);
            tessellator.addVertexWithUV(d7, d15, d9, d2, d3);
            tessellator.addVertexWithUV(d5, d15, d9, d0, d3);
            tessellator.addVertexWithUV(d5, d13, d9, d0, d1);
    
            tessellator.addVertexWithUV(d5, d13, d9, d2, d1);
            tessellator.addVertexWithUV(d5, d15, d9, d2, d3);
            tessellator.addVertexWithUV(d5, d15, d11, d0, d3);
            tessellator.addVertexWithUV(d5, d13, d11, d0, d1);
    
            tessellator.addVertexWithUV(d7, d13, d11, d0, d1);
            tessellator.addVertexWithUV(d7, d15, d11, d0, d3);
            tessellator.addVertexWithUV(d7, d15, d9, d2, d3);
            tessellator.addVertexWithUV(d7, d13, d9, d2, d1);
    
            tessellator.addVertexWithUV(d5, d13, d11, d2, d1);
            tessellator.addVertexWithUV(d5, d15, d11, d2, d3);
            tessellator.addVertexWithUV(d7, d15, d11, d0, d3);
            tessellator.addVertexWithUV(d7, d13, d11, d0, d1);
    
            //gets the little "hole" texture from the blocks registered texture, renders ever so slightly in front to avoid z-fighting
            icon = block.getIcon(0, 0);
            d0 = (double)icon.getMinU();
            d1 = (double)icon.getMinV();
            d2 = (double)icon.getMaxU();
            d3 = (double)icon.getMaxV();
            d5 = (double)(x + 1 + f);
            d7 = (double)(x - f);
            d9 = (double)(z - f);
            d11 = (double)(z + 1 + f);
            d13 = (double)(y + 1);
            d15 = (double)(y);
            
            tessellator.addVertexWithUV(d7, d13, d9, d2, d1);
            tessellator.addVertexWithUV(d7, d15, d9, d2, d3);
            tessellator.addVertexWithUV(d5, d15, d9, d0, d3);
            tessellator.addVertexWithUV(d5, d13, d9, d0, d1);
    
            tessellator.addVertexWithUV(d5, d13, d9, d2, d1);
            tessellator.addVertexWithUV(d5, d15, d9, d2, d3);
            tessellator.addVertexWithUV(d5, d15, d11, d0, d3);
            tessellator.addVertexWithUV(d5, d13, d11, d0, d1);
    
            tessellator.addVertexWithUV(d7, d13, d11, d0, d1);
            tessellator.addVertexWithUV(d7, d15, d11, d0, d3);
            tessellator.addVertexWithUV(d7, d15, d9, d2, d3);
            tessellator.addVertexWithUV(d7, d13, d9, d2, d1);
    
            tessellator.addVertexWithUV(d5, d13, d11, d2, d1);
            tessellator.addVertexWithUV(d5, d15, d11, d2, d3);
            tessellator.addVertexWithUV(d7, d15, d11, d0, d3);
            tessellator.addVertexWithUV(d7, d13, d11, d0, d1);
    
    	return false;
    }
    
    @Override
    public boolean shouldRender3DInInventory() {
    	return true;
    }
    
    @Override
    public int getRenderId() {
    	return renderType;
    }
    }
    

×
×
  • Create New...

Important Information

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