Jump to content

1.6.2 Plants


mydeblob
 Share

Recommended Posts

Ok, they changed more than what I thought in 1.6.2 lol. I'm trying to create a new crop item that is almost identical to wheat, however not much works for it. To start off, I was trying to add the seeds for this plant to drop from grass, so I put this peice of code

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

But all this does in game is make tons of seeds fall from the sky. Also in my crop class, I was going off of the tutorial on the forge wiki for plants but there are some things that don't work anymore, so I ask for your guyses help with this. Thanks

Main class:

 

package sandwichmod;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
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;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;

@Mod(modid="sandwich", name="Sandwich", version="0.0.1")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class Sandwich {


        // The instance of your mod that Forge uses.
        @Instance("Sandwich")
        public static Sandwich instance;
        private static Item breadslice;
        private static Item chickensandwich;
        private static Item steaksandwich;
        private static Item hamsandwich;
        private static Item supersandwich;
        private static Item chickenbit;
        private static Item steakbit;
        private static Item porkbit;
        public static Item tomatoseeds;
        public static Item tomatofruit;
        public static Block tomatocrop;
        int breadsliceID;
        int chickensandwichID;
        int steaksandwichID;
        int hamsandwichID;
        int supersandwichID;
        int chickenbitID;
        int steakbitID;
        int porkbitID;
        int tomatoseedsID;
        int tomatocropID;
        int tomatofruitID;

        
        // Says where the client and server 'proxy' code is loaded.
        @SidedProxy(clientSide="mydeblob.sandwich.client.ClientProxy", serverSide="Sandwich.CommonProxy")
        public static CommonProxy proxy;
        
        @EventHandler
        public void preInit(FMLPreInitializationEvent event) {
        	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
        	config.load();
        	breadsliceID = config.get("Item IDs", "Bread Slice", 5000).getInt();
        	chickensandwichID = config.get("Item IDs", "Chicken Sandwich", 5001).getInt();
        	steaksandwichID = config.get("Item IDs", "Steak Sandwich", 5002).getInt();
        	hamsandwichID = config.get("Item IDs", "Ham Sandwich", 5003).getInt();
        	supersandwichID = config.get("Item IDs", "Super Sandwich", 5004).getInt();
        	chickenbitID = config.get("Item IDs", "Slice of Chicken", 5005).getInt();
        	steakbitID = config.get("Item IDs", "Slice of Steak", 5006).getInt();
        	porkbitID = config.get("Item IDs", "Slice of Pork", 5007).getInt();
        	tomatoseedsID = config.get("Item IDs", "Tomato Seeds", 5008).getInt();
        	tomatofruitID = config.get("Item IDs", "Tomato Fruit", 5009).getInt();
        	config.save();
        }
        
        @EventHandler
        public void load(FMLInitializationEvent event) {
                proxy.registerRenderers();
               breadslice = new BreadSlice(breadsliceID).setUnlocalizedName("breadslice").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("Sandwich:slicebread");
               chickensandwich = new ItemFood(chickensandwichID, 18, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("chickensandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("Sandwich:chickensandwich");
               steaksandwich = new ItemFood(steaksandwichID, 18, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("steaksandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("Sandwich:steaksandwich");
               hamsandwich = new ItemFood(hamsandwichID, 18, 0.8f, false).setPotionEffect(Potion.moveSpeed.id, 4, 0, 0.8f).setUnlocalizedName("hamsandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("Sandwich:hamsandwich");
               supersandwich = new ItemFood(supersandwichID, 18, 1.4f, false).setAlwaysEdible().setPotionEffect(Potion.regeneration.id, 6, 1, 0.8f).setPotionEffect(Potion.moveSpeed.id, 6, 1, 0.8f).setUnlocalizedName("supersandwich").setMaxStackSize(64).setCreativeTab(CreativeTabs.tabFood).func_111206_d("Sandwich:supersandwich");
               chickenbit = new Item(chickenbitID).setUnlocalizedName("chickenbit").setCreativeTab(CreativeTabs.tabFood);
               steakbit = new Item(steakbitID).setUnlocalizedName("steakbit").setCreativeTab(CreativeTabs.tabFood);
               porkbit = new Item(porkbitID).setUnlocalizedName("porkbit").setCreativeTab(CreativeTabs.tabFood);
               tomatocrop = new TomatoCrop(tomatocropID).setUnlocalizedName("tomatocrop");
               tomatoseeds = new ItemSeeds(tomatoseedsID, tomatocrop.blockID, Block.tilledField.blockID).setUnlocalizedName("tomatoseeds");
               tomatofruit = new ItemFood(tomatofruitID, 6, 0.8f, false).setUnlocalizedName("tomatofruit");
               MinecraftForge.addGrassSeed(new ItemStack (tomatoseeds), 10);
               gameRegisters();
               languageRegisters();
               craftingRecipes();



        }

        
        private static void gameRegisters(){
        	GameRegistry.registerItem(breadslice, "Bread Slice");
        	GameRegistry.registerItem(chickensandwich, "Chicken Sandwich");
        	GameRegistry.registerItem(steaksandwich, "Steak Sandwich");
        	GameRegistry.registerItem(hamsandwich, "Ham Sandwich");
        	GameRegistry.registerItem(supersandwich, "Super Sandwich");
        	GameRegistry.registerItem(chickenbit, "Slice of Chicken");
        	GameRegistry.registerItem(steakbit, "Slice of Steak");
        	GameRegistry.registerItem(porkbit, "Slice of Ham");
        	GameRegistry.registerItem(tomatoseeds, "Tomato Seeds");
        	GameRegistry.registerItem(tomatofruit, "Tomato");
        	GameRegistry.registerBlock(tomatocrop, "Tomato Crop");
        }
        private static void languageRegisters(){
        	LanguageRegistry.addName(breadslice, "Bread Slice");
        	LanguageRegistry.addName(chickensandwich, "Chicken Sandwich");
        	LanguageRegistry.addName(steaksandwich, "Steak Sandwich");
        	LanguageRegistry.addName(hamsandwich, "Ham Sandwich");
        	LanguageRegistry.addName(supersandwich, "Super Sandwich");
        	LanguageRegistry.addName(chickenbit, "Slice of Chicken");
        	LanguageRegistry.addName(steakbit, "Slice of Steak");
        	LanguageRegistry.addName(porkbit, "Slice of Ham");
        	LanguageRegistry.addName(tomatoseeds, "Tomato Seeds");
        	LanguageRegistry.addName(tomatofruit, "Tomato");
        }
        public void craftingRecipes(){
        	GameRegistry.addShapelessRecipe(new ItemStack (Sandwich.breadslice, 12), new ItemStack(ItemFood.bread));
        	GameRegistry.addShapelessRecipe(new ItemStack (Sandwich.chickenbit, 3), new ItemStack(ItemFood.chickenCooked));
        	GameRegistry.addShapelessRecipe(new ItemStack (Sandwich.steakbit, 3), new ItemStack(ItemFood.beefCooked));
        	GameRegistry.addShapelessRecipe(new ItemStack (Sandwich.porkbit, 3), new ItemStack(ItemFood.porkCooked));
        	GameRegistry.addRecipe(new ItemStack(Sandwich.chickensandwich, 1), new Object[]{"BBB", "CCC", "BBB", 'B', Sandwich.breadslice, 'C', Sandwich.chickenbit });
        	GameRegistry.addRecipe(new ItemStack(Sandwich.steaksandwich, 1), new Object[]{"BBB", "SSS", "BBB", 'B', Sandwich.breadslice, 'S', Sandwich.steakbit});
        	GameRegistry.addRecipe(new ItemStack(Sandwich.hamsandwich, 1), new Object[]{"BBB", "PPP", "BBB", 'B', Sandwich.breadslice, 'P', Sandwich.porkbit});
        	GameRegistry.addRecipe(new ItemStack(Sandwich.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', Sandwich.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(Sandwich.supersandwich, 1), new Object []{"BBB", "SCP", "BBB", 'B', Sandwich.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(Sandwich.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', Sandwich.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(Sandwich.supersandwich, 1), new Object []{"BBB", "SPC", "BBB", 'B', Sandwich.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(Sandwich.supersandwich, 1), new Object []{"BBB", "PSC", "BBB", 'B', Sandwich.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(Sandwich.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', Sandwich.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(Sandwich.supersandwich, 1), new Object []{"BBB", "CSP", "BBB", 'B', Sandwich.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        	GameRegistry.addRecipe(new ItemStack(Sandwich.supersandwich, 1), new Object []{"BBB", "CPS", "BBB", 'B', Sandwich.breadslice, 'C', ItemFood.chickenCooked, 'S', ItemFood.beefCooked, 'P', ItemFood.porkCooked});
        
        	
        }
        @EventHandler
        public void postInit(FMLPostInitializationEvent event) {
                // Stub Method
        }

 

And then here is my crop class

 

package sandwichmod;

import java.util.Random;

import net.minecraft.block.material.Material;
import net.minecraft.block.Block;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.IPlantable;

public class TomatoCrop extends Block{

    public TomatoCrop (int id) {
        super(id, Material.plants);
        setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.5F, 1.0F);
        setTickRandomly(true);
    }

    @Override
    public AxisAlignedBB getCollisionBoundingBoxFromPool (World world, int x,
            int y, int z) {
        return null;
    }

    @Override
    public int getRenderType () {
        return 6;
    }

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

    public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
        return 32 + metadata;
    }

    @Override
    public void updateTick (World world, int x, int y, int z, Random random) {
        if (world.getBlockMetadata(x, y, z) == 1) {
            return;
        }

        if (random.nextInt(isFertile(world, x, y - 1, z) ? 12 : 25) != 0) {
            return;
        }

        world.setBlockMetadataWithNotify(x, y, z, 1, z);
    }

    @Override
    public void onNeighborBlockChange (World world, int x, int y, int z,
            int neighborId) {
        if (!canBlockStay(world, x, y, z)) {
            dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
            setBlock(x, y, z, 0); //-------- Here is the second error
        }
    }

    

@Override
    public boolean canBlockStay (World world, int x, int y, int z) {
        Block soil = blocksList[world.getBlockId(x, y - 1, z)];
        return (world.getFullBlockLightValue(x, y, z) >= 8 || world
                .canBlockSeeTheSky(x, y, z))
                && (soil != null && soil.canSustainPlant(world, x,  y -1,  z,          //--------Here is one error---------
                        ForgeDirection.UP, Sandwich.tomatoseeds));
    }

    @Override
    public int idDropped (int metadata, Random random, int par2) {
        switch (metadata) {
        case 0:
            return Sandwich.tomatoseeds.itemID;
        case 1:
            return Sandwich.tomatofruit.itemID;
        default:
            // Error case!
            return -1; // air
        }
    }

    @Override
    public int idPicked (World world, int x, int y, int z) {
        return Sandwich.tomatoseeds.itemID;
    }
}

 

Link to comment
Share on other sites

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
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.

 Share



×
×
  • Create New...

Important Information

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