Jump to content

[SOLVED][1.8.9] Crop not dropping seeds?


imacatlolol

Recommended Posts

Hi there! I'm pretty inexperienced with modding and Java in general, so I apologize if this is an easy fix.

 

I'm trying to make a custom crop, but it won't drop the seeds. Instead, I get the following error:

"Attempted to add a EntityItem to the world with a invalid item at (-77.33,  4.57, 1181.27), this is most likely a config issue between you and the server. Please double check your configs"

 

ItemPPSeed:

public class ItemPPSeed extends ItemSeeds {
    public ItemPPSeed(String unlocalizedName, int maxStackSize, Block crops, Block soil) {
        super(crops, soil);
        this.setCreativeTab(CreativeTabPP.PP_TAB);
        this.setMaxStackSize(maxStackSize);
        this.setUnlocalizedName(unlocalizedName);
    }

    @Override
    public String getUnlocalizedName() {
        return String.format("item.%s%s", RefStr.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
    }

    @Override
    public String getUnlocalizedName(ItemStack itemStack) {
        return String.format("item.%s%s", RefStr.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
    }

    protected String getUnwrappedUnlocalizedName(String unlocalizedName) {
        return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
    }
}

 

BlockPPCrop:

public class BlockPPCrop extends BlockCrops {
    private Item seed;
    private Item crop;

    public BlockPPCrop(String unlocalizedName, Item seed, Item crop) {
        this.setDefaultState(this.blockState.getBaseState().withProperty(AGE, 0));
        this.setTickRandomly(true);
        float f = 0.5F;
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
        this.setCreativeTab(null);
        this.setHardness(0.0F);
        this.setStepSound(soundTypeGrass);
        this.disableStats();
        this.setUnlocalizedName(unlocalizedName);
        this.seed = seed;
        this.crop = crop;
    }

    @Override
    protected Item getSeed()
    {
        return this.seed;
    }

    @Override
    protected Item getCrop()
    {
        return this.crop;
    }

    @Override
    public String getUnlocalizedName() {
        return String.format("tile.%s%s", RefStr.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
    }

    protected String getUnwrappedUnlocalizedName(String unlocalizedName) {
        return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
    }
}

 

Relevant ModItems Line:

public static final ItemPPSeed tomatoseed = new ItemPPSeed("tomatoseed", 64, ModBlocks.tomatocrop, Blocks.farmland);

 

Relevant ModBlocks Line:

public static final BlockPPCrop tomatocrop = new BlockPPCrop("tomatocrop", ModItems.tomatoseed, ModItems.tomato);

 

The confusing thing is that it drops the tomato fine, but not the seeds.

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Link to comment
Share on other sites

The last two lines in the ModItems and ModBlocks are important here.

 

We need to know what order those are called in.

 

Because you have them as part of the static class initialization, rather than as a method, we cannot know what order they are called in nor can we change that order.

 

Secondly, you do this:

 

ItemPPSeed tomatoseed = new(ModBlocks.tomatocrop);
BlockPPCrop tomatocrop = new(ModItems.tomatoseed);

 

Each of those lines is referencing the other ONE OF THEM WILL BE NULL!  So you're storing null in a private field.

 

There's a much better way of doing this.

 

    protected Item getSeed()
    {
        return ModItems.tomatoseed; //magic
    }

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

The last two lines in the ModItems and ModBlocks are important here.

 

We need to know what order those are called in.

 

Because you have them as part of the static class initialization, rather than as a method, we cannot know what order they are called in nor can we change that order.

 

Secondly, you do this:

 

ItemPPSeed tomatoseed = new(ModBlocks.tomatocrop);
BlockPPCrop tomatocrop = new(ModItems.tomatoseed);

 

Each of those lines is referencing the other ONE OF THEM WILL BE NULL!  So you're storing null in a private field.

 

There's a much better way of doing this.

 

    protected Item getSeed()
    {
        return ModItems.tomatoseed; //magic
    }

Ah, that was certainly part of the problem, thank you. I was registering my items before my blocks, for whatever reason.

 

But, I've got a problem with the second half. I want to use one class for all of my crops, instead of making a new class for each one (mostly as an experiment to see if it's a good idea). That means I need to be able to set the seed drop and crop drop when I'm registering the crop block. There's probably an easy way to do it and I'm just being blind, but if not I'll go back to making individual classes.

 

Also (unrelated, but still), please remove all that unlocalized name crap. It is useless and slow.

Got it. I was thinking it would be useful in some way, but it's not really necessary.

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Link to comment
Share on other sites

If you want to use the same class for multiple crops you'll need to set the properties after both the seed and crop are instantiated.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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