Jump to content

Recommended Posts

Posted

Hey guys !

 

I got a problem with my crops :

 

package com.hamsterfurtif.elisancecraft.blocks;

import com.hamsterfurtif.elisancecraft.ElisanceCraftMOD;
import com.hamsterfurtif.elisancecraft.lib.References;

import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

@SuppressWarnings("unused")
public class BlockMais extends BlockCrops
{
    private IIcon[] field_149868_a;
    
private static final String __OBFID = "CL_00000212";

    /**
     * Gets the block's texture. Args: side, meta
     */
@Override
    public IIcon getIcon(int p_149691_1_, int p_149691_2_)
    {
        if (p_149691_2_ < 7)
        {
            if (p_149691_2_ == 6)
            {
                p_149691_2_ = 5;
            }

            return this.field_149868_a[p_149691_2_ >> 1];
        }
        else
        {
            return this.field_149868_a[3];
        }
    }
    
    @Override
    public boolean canBlockStay (World world, int posX, int posY, int posZ) 
    {

    	
    	Block dessous = world.getBlock(posX, posY - 1, posZ);
    	Block dessus = world.getBlock(posX, posY + 1, posZ);
    	int met = world.getBlockMetadata(posX, posY, posZ);


    	if (dessous == Blocks.farmland )
    	{
    		
    		return true;
    	}

    	else 
    	{
    		return false;
    	}
    	
    	
    }
    
    


    protected Item func_149866_P()
    {
        return ElisanceCraftMOD.mais_epis;
    }

    protected Item func_149865_i()
    {
        return ElisanceCraftMOD.mais_epis;
        
    }

    @Override
    public void registerBlockIcons(IIconRegister p_149651_1_)
    {
        this.field_149868_a = new IIcon[4];

        for (int var2 = 0; var2 < this.field_149868_a.length; ++var2)
        {
            this.field_149868_a[var2] = p_149651_1_.registerIcon(References.MODID + ":pousse_mais" + "_stage_" + var2);
        }
    }
    
    public void onBlockAdded(World world, int posX, int posY, int posZ)
    {
    	world.setBlock(posX, posY +1, posZ, ElisanceCraftMOD.mais_pousse_top);
    }
    
    

    public int getRenderType()
    {
    	return 2;
    }
    
    public Item getItem(World world, int posX, int posY, int posZ)
    {
        return ElisanceCraftMOD.mais_epis;
    }
}

 

The problem is that when I use this:

    public int getRenderType()
    {
    	return 2;
    }

 

The textures stay the same, at the first stage.

Posted

Your getIcon method seems maybe a bit unnecessarily complicated.  How many grow stages do you have textures for?

 

In my crop I have 4 textures so I use the following code.  There are 8 grow stages for crops (0 to 7), so I duplicate entries in an icon array to fill it up, like this:

    @Override
    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister parIIconRegister)
    {
          iIcon = new IIcon[8];
          // seems that crops like to have 8 growth icons, but okay to repeat actual texture if you want
          iIcon[0] = parIIconRegister.registerIcon("recipeplus:blueberries_stage_0");
          iIcon[1] = parIIconRegister.registerIcon("recipeplus:blueberries_stage_0");
          iIcon[2] = parIIconRegister.registerIcon("recipeplus:blueberries_stage_1");
          iIcon[3] = parIIconRegister.registerIcon("recipeplus:blueberries_stage_1");
          iIcon[4] = parIIconRegister.registerIcon("recipeplus:blueberries_stage_2");
          iIcon[5] = parIIconRegister.registerIcon("recipeplus:blueberries_stage_2");
          iIcon[6] = parIIconRegister.registerIcon("recipeplus:blueberries_stage_3");
          iIcon[7] = parIIconRegister.registerIcon("recipeplus:blueberries_stage_3");
    }

And then in the getIcon() method it can be really simple:

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int parSide, int parGrowthStage)
    {
     return iIcon[parGrowthStage];
    }

Note I have a whole tutorial on crops: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-creating-custom.html

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

If you're going to use copy-paste code at least clean up the parameter names, delete the unused bits, and try to understand it. Nobody is going to help you until you do.

It makes it difficult for us to read and difficult to give help. It also makes it difficult for you to understand that help if you don't even understand your own code.

Posted

What a lot of the noobs to modding do not know is that the parameter names are local only to your method and can be renamed very easily to more understandable/readable names. Just select the parameter name and press CTRL-ALT-R (in eclipse) to give it a new name and all the uses of that name will change automagicly. Eclipse scores! You win.

Posted

Well, this is the basic minecraft method, but it works just fine. The problem comes when I add:

    public int getRenderType()
    {
    	return 2;
    }

 

I think render type 2 is for torches.  Is that the type of render you want?  You can see a list of all the render types in the renderBlockByRenderType() method which has the following:

           case 0 : return this.renderStandardBlock(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 4: return this.renderBlockLiquid(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 31: return this.renderBlockLog(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 1: return this.renderCrossedSquares(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 40: return this.renderBlockDoublePlant((BlockDoublePlant)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 2: return this.renderBlockTorch(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 20: return this.renderBlockVine(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 11: return this.renderBlockFence((BlockFence)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 39: return this.renderBlockQuartz(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 5: return this.renderBlockRedstoneWire(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 13: return this.renderBlockCactus(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 9: return this.renderBlockMinecartTrack((BlockRailBase)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 19: return this.renderBlockStem(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 23: return this.renderBlockLilyPad(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 6: return this.renderBlockCrops(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 3: return this.renderBlockFire((BlockFire)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 8: return this.renderBlockLadder(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 7: return this.renderBlockDoor(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 10: return this.renderBlockStairs((BlockStairs)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 27: return this.renderBlockDragonEgg((BlockDragonEgg)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 32: return this.renderBlockWall((BlockWall)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 12: return this.renderBlockLever(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 29: return this.renderBlockTripWireSource(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 30: return this.renderBlockTripWire(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 14: return this.renderBlockBed(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 15: return this.renderBlockRepeater((BlockRedstoneRepeater)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 36: return this.renderBlockRedstoneDiode((BlockRedstoneDiode)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 37: return this.renderBlockRedstoneComparator((BlockRedstoneComparator)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 16: return this.renderPistonBase(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_, false) ;
            case 17: return this.renderPistonExtension(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_, true) ;
            case 18: return this.renderBlockPane((BlockPane)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 41: return this.renderBlockStainedGlassPane(p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 21: return this.renderBlockFenceGate((BlockFenceGate)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 24: return this.renderBlockCauldron((BlockCauldron)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 33: return this.renderBlockFlowerpot((BlockFlowerPot)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 35: return this.renderBlockAnvil((BlockAnvil)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 25: return this.renderBlockBrewingStand((BlockBrewingStand)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 26: return this.renderBlockEndPortalFrame((BlockEndPortalFrame)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 28: return this.renderBlockCocoa((BlockCocoa)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 34: return this.renderBlockBeacon((BlockBeacon)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_) ;
            case 38: return this.renderBlockHopper((BlockHopper)p_147805_1_, p_147805_2_, p_147805_3_, p_147805_4_);
            default: return FMLRenderAccessLibrary.renderWorldBlock(this, blockAccess, p_147805_2_, p_147805_3_, p_147805_4_, p_147805_1_, l);

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

The problem is that when I use this:

    public int getRenderType()
    {
    	return 2;
    }

 

The textures stay the same, at the first stage.

I'm not quiet sure if I understand u right, but you want this code to change the textures to the next stage?

Cause that is completly wrong, if not what is actually not working or where is the problem?

Posted

No, he wants his texture to be displayed as crops are. Return 1 or 6 so that renderCrossedSquares or renderBlockCrops are used.

PS: you can use for loops to register your icons. I think it's better (like texture_name + i in a for (int i=0...))

That way you can retrieve the texture doing iconsArray[metadata]

Check out my blog!

http://www.whov.altervista.org

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.