Jump to content

[1.7.2][SOLVED]Custom crop drops wheat seeds and wheat(Not what I want it to)


The_Fireplace

Recommended Posts

It is supposed to be dropping Quartz Seeds and a Quartz Block. Instead, it drops Wheat and Seeds. Also, if anyone knows how, I would like to set the percentage of the time each thing drops. I am updating from 1.6.4.

 

Here is my code:

 

 

 

package f1repl4ce.unlogic.blocks;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import f1repl4ce.unlogic.unbase;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.IIcon;

public class QuartzCrop extends BlockCrops{

@SideOnly(Side.CLIENT)
private IIcon[] iconArray;
public QuartzCrop(int par1) {
super();
}

@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata){
if(metadata < 7){
if(metadata == 6){
metadata = 5;
}
return iconArray[metadata >> 1];
}
return iconArray[4];
}

public Item getSeedItem(){
return unbase.QSeed;
}

public Block getCropItem(){
return Blocks.quartz_block;
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister){
this.iconArray = new IIcon[5];

for(int i = 0; i < this.iconArray.length; i++){
this.iconArray[i] = iconRegister.registerIcon("unlogic:QCrop_" + (i+1));
}
}

}

 

 

 

And the Mod Base:

 

 

 

package f1repl4ce.unlogic;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
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.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import f1repl4ce.unlogic.proxy.*;
import f1repl4ce.unlogic.items.*;
import f1repl4ce.unlogic.blocks.*;

@Mod(modid="unlogic", name="UnLogic", version="0.1.0")
public class unbase {

// The instance of your mod that Forge uses.
@Instance(value = "unlogic")
public static unbase instance;
//Creative Tab Registry
public static CreativeTabs TabUnLogic = new TabUnLogic(CreativeTabs.getNextID(), "UnLogic");
//Block Registry
public static Block QCrop = new QuartzCrop(2481);
public static Block FarmObsidian = new FarmObsidian(2482, Material.rock);
//Item Registry
public static Item Component = new Component(16794).setUnlocalizedName("Component_UN").setCreativeTab(TabUnLogic);
public static Item QSeed = new ItemSeeds(QCrop, Blocks.farmland/*FarmObsidian*/).setUnlocalizedName("QSeed").setTextureName("unlogic:QSeeds").setCreativeTab(TabUnLogic);

// Says where the client and server 'proxy' code is loaded.
@SidedProxy(clientSide="f1repl4ce.unlogic.proxy.Client", serverSide="f1repl4ce.unlogic.proxy.Common")
public static Common proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
LanguageRegistry.instance().addStringLocalization("item.Component_UN.unlogicGem.name", "en_US", "UnLogic Gem");
LanguageRegistry.instance().addStringLocalization("item.Component_UN.fireCore.name", "en_US", "Fire Core");
LanguageRegistry.instance().addStringLocalization("item.Component_UN.iceCore.name", "en_US", "Ice Core");
LanguageRegistry.instance().addStringLocalization("item.Component_UN.antiGold.name", "en_US", "Anti-Gold");
LanguageRegistry.instance().addStringLocalization("item.Component_UN.redGem.name", "en_US", "Red Gem");
LanguageRegistry.instance().addStringLocalization("item.Component_UN.blueGem.name", "en_US", "Blue Gem");
LanguageRegistry.addName(QSeed, "Nether Quartz Seeds");
LanguageRegistry.addName(FarmObsidian, "Obsidian Farmland");
GameRegistry.registerBlock(QCrop, "Quartz Crop");
GameRegistry.registerBlock(FarmObsidian, "Obsidian Farmland");
GameRegistry.registerItem(QSeed, "Qseed");
GameRegistry.registerItem(Component, "Component");
ItemStack fireCore = new ItemStack(Component, 1, 1);
ItemStack iceCore = new ItemStack(Component, 1, 2);
ItemStack unlogicGem = new ItemStack(Component, 1, 0);
ItemStack seedStack = new ItemStack(Items.wheat_seeds);
ItemStack redGemStack = new ItemStack(Component, 1, 4);
ItemStack blueGemStack = new ItemStack(Component, 1, 5);
ItemStack qSeedStack = new ItemStack(QSeed);
ItemStack quartzStack = new ItemStack(Items.quartz);
OreDictionary.registerOre("fireCore", fireCore);
OreDictionary.registerOre("iceCore", iceCore);
GameRegistry.addRecipe(unlogicGem, "xy", "yx",
'x', redGemStack, 'y', blueGemStack);
GameRegistry.addRecipe(unlogicGem, "yx", "xy",
'x', redGemStack, 'y', blueGemStack);
GameRegistry.addRecipe(qSeedStack, "sus", "uqu", "sus",
's', seedStack, 'u', unlogicGem, 'q', quartzStack);
GameRegistry.addSmelting(Blocks.redstone_block, redGemStack, 10);
GameRegistry.addSmelting(Blocks.lapis_block, blueGemStack, 10);
}

@EventHandler
public void load(FMLInitializationEvent event) {
proxy.registerRenderers();
}

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
}
}

 

 

 

If any code you need to see is missing, tell me and I'll add it.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

  • 2 months later...

package yourpackage;

 

import java.util.Random;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.material.Material;

import net.minecraft.block.Block;

import net.minecraft.block.BlockCrops;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.IIcon;

import net.minecraft.world.World;

 

 

public class yourcrop extends BlockCrops{

 

public yourcrop() {

super();

 

 

 

}

@SideOnly(Side.CLIENT)

    private IIcon[] field_149869_a;

    private static final String __OBFID = "CL_00000286";

 

    /**

    * Gets the block's texture. Args: side, meta

    */

    @SideOnly(Side.CLIENT)

    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_149869_a[p_149691_2_ >> 1];

        }

        else

        {

            return this.field_149869_a[3];

        }

    }

 

   

    protected Item func_149866_i()

    {

    return **DROP always**

   

   

       

       

       

    }

   

   

   

    protected Item func_149865_P()

    {

    return **DROP if full grown**

   

    }

 

   

 

/**

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

    */

    public void dropBlockAsItemWithChance(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)

    {

        super.dropBlockAsItemWithChance(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_6_, p_149690_7_);

 

        if (!p_149690_1_.isRemote)

        {

            if (p_149690_5_ >= 7 && p_149690_1_.rand.nextInt(50) == 0)

            {

                this.dropBlockAsItem(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, new ItemStack(Items.string));

            }

        }

    }

 

    @SideOnly(Side.CLIENT)

    public void registerBlockIcons(IIconRegister p_149651_1_)

   

    {

        this.field_149869_a = new IIcon[4];

 

        for (int i = 0; i < this.field_149869_a.length; ++i)

        {

       

        int stage = 0;

if(i==0)

{

stage = 0;

}

if(i==1)

{

stage = 1;

}

if(i==2)

{

stage = 2;

}

if(i==3)

{

stage = 3;

}

            }

            this.field_149869_a = p_149651_1_.registerIcon("yourtexturefile" + "_" + stage);

        }

     

       

       

    }

 

 

   

 

}

Link to comment
Share on other sites

  • 4 weeks later...

(sorry for bad english, i'm from venezuela)

Override this methods on your crop

@Override
    public Item getItemDropped(int meta, Random random, int fortune) //get drop item based on meta
    {
        return meta == 7 ? this.getCropItem() : this.getSeedItem();
    }

    @SideOnly(Side.CLIENT)
    public Item getItem(World world, int x, int y, int z) //get item with mouse wheel
    {
        return this.getSeedItem();
    }

   @Override
    public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) //get drops array
    {
        ArrayList<ItemStack> drops = new ArrayList<ItemStack>();

        int count = quantityDropped(metadata, fortune, world.rand);
        for(int i = 0; i < count; i++)
        {
            Item item = getItemDropped(metadata, world.rand, fortune);
            if (item != null)
            {
                drops.add(new ItemStack(item, 1, damageDropped(metadata)));
            }
        }
        
        if (metadata >= 7)
        {
            for (int i = 0; i < 3 + fortune; ++i)
            {
                if (world.rand.nextInt(15) <= metadata)
                {
                    drops.add(new ItemStack(this.getSeedItem(), 1, 0)); //<-- here
                }
            }
        }
        
        return drops;
    }

Making mods is fun!!!

(sorry bad english, i'm from venezuela)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Another Minecraft Launcher https://multimc.org/#Download or https://atlauncher.com/downloads
    • Remove these mods and combine OptiFine HD U I6 with Forge 47.2.18 Start with Optifine - without any other mods - if this works, add the mods one by one or in groups until you find the mod, conflicting with Optifine
    • Ok yeah I think this might be where the problem starts. For starters, I think you can get rid of your RecipeType impl and make it a static constant instead. I'm not 100% sure this will fix it but it's posssible. RuneInscribingRecipe public class RuneInscribingRecipe implements Recipe<SimpleContainer> { public static final RecipeType<RuneInscribingRecipe> RECIPE_TYPE = new RecipeType<>(){}; // .... @Override public RecipeType<?> getType() { return RECIPE_TYPE; } // .... } RuneInscriberMenu private Optional<RecipeHolder<RuneInscribingRecipe>> getCurrentRecipe() { SimpleContainer inventory = new SimpleContainer(2); inventory.setItem(BASE_INPUT_SLOT, this.inventory.getStackInSlot(BASE_INPUT_SLOT)); inventory.setItem(TEMPLATE_INPUT_SLOT, this.inventory.getStackInSlot(TEMPLATE_INPUT_SLOT)); List<RecipeHolder<RuneInscribingRecipe>> list = this.blockEntity.getLevel().getRecipeManager().getRecipesFor(RuneInscribingRecipe.RECIPE_TYPE, inventory, this.blockEntity.getLevel()); if (list.isEmpty()) { return Optional.empty(); } return Optional.of(list.get(0)); }   Also, this here is a little suspicious where you're getting the `this.inventory.getStackInSlot` calls. I'd try and make sure those are what you expect they are with either a Debug line in IDE or print statement SimpleContainer inventory = new SimpleContainer(2); inventory.setItem(BASE_INPUT_SLOT, this.inventory.getStackInSlot(BASE_INPUT_SLOT)); System.out.printf("CHECKING BASE INPUT OF RECIPE: %s\n", this.inventory.getStackInSlot(BASE_INPUT_SLOT)); inventory.setItem(TEMPLATE_INPUT_SLOT, this.inventory.getStackInSlot(TEMPLATE_INPUT_SLOT)); System.out.printf("CHECKING TEMPLATE INPUT OF RECIPE: %s\n", this.inventory.getStackInSlot(TEMPLATE_INPUT_SLOT)); ^ See what the result of those print statements are, make sure they're right
    • Upon testing again after adding them, the game still doesn't crash however the resource packs are still unfortunately broken.
    • Hi! Can someone please point me to the correct FAQ or place? I'm not able do DuckDuckGo myself out of this one. As you can hopefully see, chunks are not rendered. I run a forge server, fresh install on a linux VM. Curseforge on the Win11 client with Embeddium, Oculus and Unbound shader. No mods. Forge 47.2.23 on server & client.  No errors, no crashes, no apparent CPU or RAM issues with the VM. This screenshot was captured while creative, but the same happens when flying in survival. Waiting (floating) for a few minutes sooner or (often) later, lets the missing chunks appear. Usually takes 5-10 minutes.  When on a local game, the chunks appear slowly, but they do appear without pause.   This must be something simple, obvious, but I can't find the correct "search words" to find my way out. "Chunks not loading / rendering" didn't help. Browsing several forums neither. 
  • Topics

×
×
  • Create New...

Important Information

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