Jump to content

Problem Making a new Crop


Nitus

Recommended Posts

So I'm having a horrible problem when trying to make a new crop. Honestly I don't know wtf is wrong in the code. Here it is:

package iFarm;

 

import java.util.Map;

 

import net.minecraft.block.Block;

import net.minecraft.block.BlockCrops;

import net.minecraft.entity.EnumCreatureType;

import net.minecraft.item.Item;

import net.minecraft.item.ItemSeeds;

import net.minecraft.item.ItemStack;

import net.minecraft.src.ModLoader;

import net.minecraft.world.biome.BiomeGenBase;

import net.minecraftforge.common.MinecraftForge;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.Init;

import cpw.mods.fml.common.Mod.Instance;

import cpw.mods.fml.common.Mod.PostInit;

import cpw.mods.fml.common.Mod.PreInit;

import cpw.mods.fml.common.SidedProxy;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.event.FMLPostInitializationEvent;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.network.NetworkMod;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

 

@Mod(modid = "modid", name = "iFarm", version = "0.0.1")

@NetworkMod(clientSideRequired = true, serverSideRequired = false)

public class iFarm {

 

public static final Item cotton = (new ItemCotton(30078)).setIconIndex(0).setItemName("cotton");

    public static final Item seedsCotton = (new ItemCottonSeeds(30079, Block.cottonPlant.blockID, Block.tilledField.blockID)).setIconIndex(1).setItemName("cotton seeds");

    public static final Block cottonPlant = (new BlockCottonPlant(59, 88)).setBlockName("cottonPlant");

 

@Instance("modid")

public static iFarm instance;

 

@SidedProxy(clientSide="iFarm.ClientProxy", serverSide="iFarm.CommonProxy")

public static CommonProxy proxy;

 

 

@PreInit

public void preInit(FMLPreInitializationEvent event) {

 

}

 

@Init

public void init(FMLInitializationEvent event) {

 

LanguageRegistry.addName(cotton, "Cotton");

 

   LanguageRegistry.addName(seedsCotton, "Cotton Seed");

   MinecraftForge.addGrassSeed(new ItemStack (seedsCotton), 10);

    

        GameRegistry.registerBlock(cottonPlant, "cottonPlant");

 

   

//register the entity

ModLoader.registerEntityID(EntityBuffalo.class, "Buffalo", ModLoader.getUniqueEntityId());

 

ModLoader.addSpawn("Buffalo", 100, 3, 6, EnumCreatureType.creature, new BiomeGenBase[] {

BiomeGenBase.extremeHills,

BiomeGenBase.extremeHillsEdge,

BiomeGenBase.forest,

BiomeGenBase.forestHills,

BiomeGenBase.plains

 

 

});

 

 

}

 

 

@PostInit

public static void postInit(FMLPostInitializationEvent event) {

 

}

}



Here is the crop code:


package iFarm;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

import java.util.ArrayList;

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.BlockFlower;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

import net.minecraftforge.common.ForgeDirection;

 

public class BlockCottonPlant extends BlockFlower

{

    protected BlockCottonPlant(int par1, int par2)

    {

        super(par1, par2);

        this.blockIndexInTexture = par2;

        this.setTickRandomly(true);

        float var3 = 0.5F;

        this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, 0.25F, 0.5F + var3);

        this.setCreativeTab((CreativeTabs)null);

        this.setHardness(0.0F);

        this.setStepSound(soundGrassFootstep);

        this.disableStats();

        this.setRequiresSelfNotify();

    }

 

    /**

    * Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of

    * blockID passed in. Args: blockID

    */

    protected boolean canThisPlantGrowOnThisBlockID(int par1)

    {

        return par1 == Block.tilledField.blockID;

    }

 

    /**

    * Ticks the block if it's been scheduled

    */

    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)

    {

        super.updateTick(par1World, par2, par3, par4, par5Random);

 

        if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9)

        {

            int var6 = par1World.getBlockMetadata(par2, par3, par4);

 

            if (var6 < 7)

            {

                float var7 = this.getGrowthRate(par1World, par2, par3, par4);

 

                if (par5Random.nextInt((int)(25.0F / var7) + 1) == 0)

                {

                    ++var6;

                    par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);

                }

            }

        }

    }

 

    /**

    * Apply bonemeal to the crops.

    */

    public void fertilize(World par1World, int par2, int par3, int par4)

    {

        par1World.setBlockMetadataWithNotify(par2, par3, par4, 7);

    }

 

    /**

    * Gets the growth rate for the crop. Setup to encourage rows by halving growth rate if there is diagonals, crops on

    * different sides that aren't opposing, and by adding growth for every crop next to this one (and for crop below

    * this one). Args: x, y, z

    */

    private float getGrowthRate(World par1World, int par2, int par3, int par4)

    {

        float var5 = 1.0F;

        int var6 = par1World.getBlockId(par2, par3, par4 - 1);

        int var7 = par1World.getBlockId(par2, par3, par4 + 1);

        int var8 = par1World.getBlockId(par2 - 1, par3, par4);

        int var9 = par1World.getBlockId(par2 + 1, par3, par4);

        int var10 = par1World.getBlockId(par2 - 1, par3, par4 - 1);

        int var11 = par1World.getBlockId(par2 + 1, par3, par4 - 1);

        int var12 = par1World.getBlockId(par2 + 1, par3, par4 + 1);

        int var13 = par1World.getBlockId(par2 - 1, par3, par4 + 1);

        boolean var14 = var8 == this.blockID || var9 == this.blockID;

        boolean var15 = var6 == this.blockID || var7 == this.blockID;

        boolean var16 = var10 == this.blockID || var11 == this.blockID || var12 == this.blockID || var13 == this.blockID;

 

        for (int var17 = par2 - 1; var17 <= par2 + 1; ++var17)

        {

            for (int var18 = par4 - 1; var18 <= par4 + 1; ++var18)

            {

                int var19 = par1World.getBlockId(var17, par3 - 1, var18);

                float var20 = 0.0F;

 

                if (blocksList[var19] != null && blocksList[var19].canSustainPlant(par1World, var17, par3 - 1, var18, ForgeDirection.UP, this))

                {

                    var20 = 1.0F;

 

                    if (blocksList[var19].isFertile(par1World, var17, par3 - 1, var18))

                    {

                        var20 = 3.0F;

                    }

                }

 

                if (var17 != par2 || var18 != par4)

                {

                    var20 /= 4.0F;

                }

 

                var5 += var20;

            }

        }

 

        if (var16 || var14 && var15)

        {

            var5 /= 2.0F;

        }

 

        return var5;

    }

 

    /**

    * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata

    */

    public int getBlockTextureFromSideAndMetadata(int par1, int par2)

    {

        if (par2 < 0)

        {

            par2 = 7;

        }

 

        return this.blockIndexInTexture + par2;

    }

 

    /**

    * The type of render function that is called for this block

    */

    public int getRenderType()

    {

        return 6;

    }

 

    /**

    * Generate a seed ItemStack for this crop.

    */

    protected int getSeedItem()

    {

        return iFarm.seedsCotton.itemID;

    }

 

    /**

    * Generate a crop produce ItemStack for this crop.

    */

    protected int getCropItem()

    {

        return iFarm.cotton.itemID;

    }

 

    /**

    * Drops the block items with a specified chance of dropping the specified items

    */

    public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)

    {

        super.dropBlockAsItemWithChance(par1World, par2, par3, par4, par5, par6, 0);

    }

 

    @Override

    public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)

    {

        ArrayList<ItemStack> ret = super.getBlockDropped(world, x, y, z, metadata, fortune);

 

        if (metadata >= 7)

        {

            for (int n = 0; n < 3 + fortune; n++)

            {

                if (world.rand.nextInt(15) <= metadata)

                {

                    ret.add(new ItemStack(this.getSeedItem(), 1, 0));

                }

            }

        }

 

        return ret;

    }

 

    /**

    * Returns the ID of the items to drop on destruction.

    */

    public int idDropped(int par1, Random par2Random, int par3)

    {

        return par1 == 7 ? this.getCropItem() : this.getSeedItem();

    }

 

    /**

    * Returns the quantity of items to drop on block destruction.

    */

    public int quantityDropped(Random par1Random)

    {

        return 1;

    }

 

    @SideOnly(Side.CLIENT)

 

    /**

    * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)

    */

    public int idPicked(World par1World, int par2, int par3, int par4)

    {

        return this.getSeedItem();

    }

}

If anyone can help, please do.

Link to comment
Share on other sites

^that^ And, I am not seeing the code for the buffalo model, but I suppose you've got that covered in the buffalo class?

The buffalo is still a work-in-progress thing, ain't really what im aiming at. And as i said i don't have a clue of what is wrong. I basically copied the Crops (wheat) block class and costumized it.

Link to comment
Share on other sites

The buffalo is still a work-in-progress thing, ain't really what im aiming at. And as i said i don't have a clue of what is wrong. I basically copied the Crops (wheat) block class and costumized it.

Well, as far as I know, you are required to have a model for a creature if you are going to let it spawn. That could be your problem, I'll check tomorrow if there's anything else what could be causing a problem. (I haven't got my workspace available atm, I'm at a friend's)

Link to comment
Share on other sites

Well, as far as I know, you are required to have a model for a creature if you are going to let it spawn. That could be your problem, I'll check tomorrow if there's anything else what could be causing a problem. (I haven't got my workspace available atm, I'm at a friend's)

Ok let me actually tell exacly what my problem is. Everything works fine, the cotton seed the cotton item, the buffalo even spawns (need to fix that though) but when i reach the cotton plant block it makes the game crash. Apparently it only happens when I make the cotton seed plant that block. It just straight A crashes.

This is the crash report:

---- Minecraft Crash Report ----

// I let you down. Sorry 

 

Time: 10-03-2013 18:12

Description: Invalid request to getUniqueSpriteIndex

 

java.lang.Exception: Invalid getUniqueSpriteIndex call for texture: /gfx/ifarm

    at cpw.mods.fml.client.SpriteHelper.getUniqueSpriteIndex(SpriteHelper.java:100)

    at cpw.mods.fml.client.registry.RenderingRegistry.addTextureOverride(RenderingRegistry.java:95)

    at net.minecraft.src.ModLoader.addOverride(ModLoader.java:236)

    at iFarm.iFarm.<clinit>(iFarm.java:37)

    at java.lang.Class.forName0(Native Method)

    at java.lang.Class.forName(Unknown Source)

    at cpw.mods.fml.common.FMLModContainer.constructMod(FMLModContainer.java:416)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

    at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

    at com.google.common.eventbus.EventBus.post(EventBus.java:268)

    at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:140)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

    at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

    at com.google.common.eventbus.EventBus.post(EventBus.java:268)

    at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:83)

    at cpw.mods.fml.common.Loader.loadMods(Loader.java:479)

    at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:161)

    at net.minecraft.client.Minecraft.startGame(Minecraft.java:410)

    at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)

    at net.minecraft.client.Minecraft.run(Minecraft.java:744)

    at java.lang.Thread.run(Unknown Source)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- System Details --

Details:

    Minecraft Version: 1.4.7

    Operating System: Windows 7 (amd64) version 6.1

    Java Version: 1.7.0_15, Oracle Corporation

    Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

    Memory: 799022712 bytes (762 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)

    JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

    AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

    Suspicious classes: FML and Forge are installed

    IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

    FML: MCP v7.26 FML v4.7.4.520 Minecraft Forge 6.6.0.497 4 mods loaded, 4 mods active

    mcp [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed

    FML [Forge Mod Loader] (coremods) Unloaded->Constructed

    Forge [Minecraft Forge] (coremods) Unloaded->Constructed

    modid [iFarm] (bin) Unloaded

Link to comment
Share on other sites

I see now... What the report is saying, is that somewhere there's an invalid getUniqueSpriteIndex in the code. Now about finding it...

It has to be in the CottonPlant code which is the second code I uploaded (the 1st post on the thread), also I dont have any idea of what the getUniqueSpriteIndex means.... yeah i'm new to coding...

Link to comment
Share on other sites

It has to be in the CottonPlant code which is the second code I uploaded (the 1st post on the thread), also I dont have any idea of what the getUniqueSpriteIndex means.... yeah i'm new to coding...

I am newer to it than you, I assure you. ;)

I'd assume It's in the second bit as well. But I can't seem to find that piece of code... It has something to do with textures for sure. Maybe with the different textures corresponding to different levels of maturity? That's just a wild guess though...

Link to comment
Share on other sites

I am newer to it than you, I assure you. ;)

I'd assume It's in the second bit as well. But I can't seem to find that piece of code... It has something to do with textures for sure. Maybe with the different textures corresponding to different levels of maturity? That's just a wild guess though...

I believe you might be right. The problem is that i do not have any fucking clue on how to had the differend stages of growth..

Link to comment
Share on other sites

I believe you might be right. The problem is that i do not have any fucking clue on how to had the differend stages of growth..

You used the vanilla code for wheat and then tweaked it, right? If so, you can just change the iconIndex around, to get different textures. If not, I would strongly recommend looking at the code for wheat.

Link to comment
Share on other sites

You used the vanilla code for wheat and then tweaked it, right? If so, you can just change the iconIndex around, to get different textures. If not, I would strongly recommend looking at the code for wheat.

Yes I used the code of wheat, the problem is that blocks like wheat don't use iconIndex (i think). I still need to do further research on this problem.

Link to comment
Share on other sites

Yes I used the code of wheat, the problem is that blocks like wheat don't use iconIndex (i think). I still need to do further research on this problem.

They, don't? Hmmm, maybe there's a way to force it to use iconIndex?

Link to comment
Share on other sites

They, don't? Hmmm, maybe there's a way to force it to use iconIndex?

IconIndex is only for icon of items (don't quote me on that). Block use a different code to render.

Link to comment
Share on other sites

That's right, but the seeds are items, right? Or are they some weird crossbreed?

Yes that's true, but i already have the seeds ready. Now they are a kind of cheat... you get them, plant them and you get a diamond block.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...