Jump to content

[1.9.4] [SOLVED] NullPointer on attempted plant


swordkorn

Recommended Posts

When I right click to plant the relevant seed it crashes on a null pointer:

// Hi. I'm Minecraft, and I'm a crashaholic.

Time: 6/21/16 9:15 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
at net.minecraft.item.ItemSeeds.getPlant(ItemSeeds.java:52)
at net.minecraft.block.Block.canSustainPlant(Block.java:1819)
at net.minecraft.item.ItemSeeds.onItemUse(ItemSeeds.java:31)
at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:157)
at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:477)
at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1602)
at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2273)
at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2057)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1845)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1119)
at net.minecraft.client.Minecraft.run(Minecraft.java:404)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Item class:

public class MysticalCropSeed extends ItemSeeds {

    public MysticalCropSeed(Block crops, Block soil,String regName) {
        super(crops, soil);
        this.setUnlocalizedName(regName);
        this.setCreativeTab(MysticalCrops.cropsTab);
    }
}

Relevant Block class methods:

public class MysticalCropBlock extends BlockCrops implements IGrowable, IPlantable {

    protected Item getSeeds() {
        final Item seeds = CropItems.seedsMap.get(this);

        if(seeds == null) {
            FMLLog.bigWarning("No seeds detected!");
            return new Item();
        }
        return seeds;
    }

    @Override
    public ItemStack getItem(World world, BlockPos pos, IBlockState state) {
        return new ItemStack(getSeeds());
    }

    protected Item getHarvestedItem() {
        final Item harvestedItem = CropItems.harvestedItemMap.get(this);
        if(harvestedItem == null) {
            FMLLog.bigWarning("No drop registered!");
            return new Item();
        }
        return harvestedItem;
    }

    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
                                    ItemStack stack, EnumFacing side, float hitX, float hitY, float hitZ) {
        if(isHarvestReady(state)) {
            if(world.isRemote) {
                return true;
            }

            final ItemStack savedStack = new ItemStack(getHarvestedItem());

            world.setBlockState(pos, state.withProperty(AGE, 0), 7);
            final EntityItem entItem = new EntityItem(world, player.posX, player.posY - 1D, player.posZ, savedStack);
            world.spawnEntityInWorld(entItem);
            entItem.onCollideWithPlayer(player);
            return true;
        }
        return false;
    }
}

The methods to bind the seed to the block:

public class CropItems {
    public static Item[] MCSeeds;
    public static Item[] MCDrops;
    public static HashMap<MysticalCropBlock, Item> seedsMap = new HashMap<MysticalCropBlock, Item>();
    public static HashMap<MysticalCropBlock, Item> harvestedItemMap = new HashMap<MysticalCropBlock, Item>();

    public static Item redstoneCropSeed;

    public static Item regItem(Item item, String regName) {
        item.setRegistryName(regName);
        item.setUnlocalizedName(regName);

        return GameRegistry.register(item);
    }

    public static Item regSeeds(String regName, Block crop) {
        Item item = new MysticalCropSeed(crop, Blocks.FARMLAND, regName);

        seedsMap.put((MysticalCropBlock) crop, item);

        return regItem(item, regName);
    }

    public static Item regDrops(Item item, Block crop) {
        return harvestedItemMap.put((MysticalCropBlock) crop, item);
    }

    public static void loadItemRegistry() {
        redstoneCropSeed = regSeeds("redstoneCropSeed", CropBlocks.redstoneCrop);
        regDrops(Items.REDSTONE, CropBlocks.redstoneCrop);

        MCSeeds = new Item[] {redstoneCropSeed};
        MCDrops = new Item[] {Items.REDSTONE};
    }
}

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • why when I launch the forge version of minecraft in full screen and turn on screen recording, only the first static image of the launch is recorded and the gameplay itself is not recorded
    • Hello! I am the leader of this rp community for a Minecraft rp server and I would like to lend out an invitation to you all to join! We are on a rp server meaning we are going to do some rp and have characters, lore, stories and more! If you want to join just click the discord link below and I’ll help guide you through the process in joining the server and joining us on the server which should be easy. (NOTE: server requires you have to be 16 years old or older) (Java only!) Discord: https://discord.gg/V9uxjKQ7dB
    • these are the errors at startup [06nov2024 19:13:37.566] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--launchTarget, forgeserver, --fml.forgeVersion, 47.3.11, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [06nov2024 19:13:37.570] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 23.0.1 by Oracle Corporation; OS Windows 11 arch amd64 version 10.0 [06nov2024 19:13:39.173] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: ImmediateWindowProvider not loading because launch target is forgeserver [06nov2024 19:13:39.178] [main/INFO] [mixin-transmog/]: Mixin Transmogrifier is definitely up to no good... [06nov2024 19:13:39.398] [main/INFO] [mixin-transmog/]: Redefining 5 mixin classes [06nov2024 19:13:39.412] [main/INFO] [mixin-transmog/]: crimes against java were committed [06nov2024 19:13:39.413] [main/INFO] [com.teampotato.redirector.Redirector/]: Redirector CoreMod initialized successfully! [06nov2024 19:13:39.424] [main/INFO] [mixin-transmog/]: Original mixin transformation service successfully crobbed by mixin-transmogrifier! [06nov2024 19:13:39.453] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/C:/Users/zappi/OneDrive/Desktop/server%20forge/mods/Connector-1.0.0-beta.18+1.20.1-full.jar%23386%23390!/ Service=ModLauncher Env=SERVER [06nov2024 19:13:40.424] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\fmlcore\1.20.1-47.3.11\fmlcore-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:40.427] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\javafmllanguage\1.20.1-47.3.11\javafmllanguage-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:40.430] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\lowcodelanguage\1.20.1-47.3.11\lowcodelanguage-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:40.433] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file C:\Users\zappi\OneDrive\Desktop\server forge\libraries\net\minecraftforge\mclanguage\1.20.1-47.3.11\mclanguage-1.20.1-47.3.11.jar is missing mods.toml file [06nov2024 19:13:41.061] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select two dependency jars from JarJar which have the same identification: Mod File:  and Mod File: . Using Mod File:  [06nov2024 19:13:41.062] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select two dependency jars from JarJar which have the same identification: Mod File:  and Mod File: . Using Mod File:  [06nov2024 19:13:41.063] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: curios. Using Mod File: C:\Users\zappi\OneDrive\Desktop\server forge\mods\curios-forge-5.10.0+1.20.1.jar [06nov2024 19:13:41.063] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: terrablender. Using Mod File: C:\Users\zappi\OneDrive\Desktop\server forge\mods\TerraBlender-forge-1.20.1-3.0.1.7.jar [06nov2024 19:13:41.063] [main/WARN] [net.minecraftforge.jarjar.selection.JarSelector/]: Attempted to select a dependency jar for JarJar which was passed in as source: aeroblender. Using Mod File: C:\Users\zappi\OneDrive\Desktop\server forge\mods\aeroblender-1.20.1-1.0.1-neoforge.jar [06nov2024 19:13:41.063] [main/INFO] [net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator/]: Found 97 dependencies adding them to mods collection [06nov2024 19:13:42.637] [main/INFO] [dev.su5ed.sinytra.connector.locator.DependencyResolver/]: Dependency resolution found 11 candidates to load [06nov2024 19:13:43.954] [main/INFO] [Configured Defaults/]: Applying default files...
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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