-1
\$\begingroup\$

First, tech specs:

  • Forge for 1.11.2 MDK (Latest Version)
  • Minecraft Coder Pack (Latest Version)
  • Minecraft 1.11.2 (Latest Version)
  • IntelliJ IDEA 2017 (Latest Version)

Then, the problem:

When I try to register my blocks in Forge, I get a game crash because they are all registering as air. My items are registering correctly, and before I fixed a typo in the model loading code, it worked (with the exception of missing models). I know I'm using the deprecated GameRegistry.register() but I just can't figure out the new registry method. (What the heck is the event?)

Then, of course, the code:

BlockBlueCandyBlock.java (the first block I'm trying to register)

package com.thecandiedhat.candiedcraft.block;

import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.List;

/**
 * Created by Ethan on 4/9/17.
 */
public class BlockBlueCandyBlock extends Block {

    public BlockBlueCandyBlock(Material materialIn) {
        super(materialIn);
        setUnlocalizedName("blue_candy_block");
        setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
        setHardness(25f);
        setResistance(1f);
        setSoundType(SoundType.METAL);
        this.setLightLevel(1f);
    }

    @Override
    public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
        tooltip.add("This candy is so common, you have to store it in compact blocks. That, or you want a really cool looking house.");
    }
}

BlockLightBlueCandyBlock.java (the second block I'm trying to load)

package com.thecandiedhat.candiedcraft.block;

import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

import java.util.List;

/**
 * Created by Ethan on 4/9/17.
 */
public class BlockLightBlueCandyBlock extends Block {

    public BlockLightBlueCandyBlock(Material material) {
        super(material);
        setUnlocalizedName("lightblue_candy_block");
        setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
        setHardness(25f);
        setResistance(1f);
        setSoundType(SoundType.METAL);
        this.setLightLevel(1f);
    }

    @Override
    public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
        tooltip.add("You got quite a bit of this delicious blue-raspberry candy and have decided to mass produce it by exploiting the block dupe glitch.");
        tooltip.add("Sadly, you can't. The block dupe glitch was removed long ago.");
    }
}

ModBlocks.java (the block handler)

package com.thecandiedhat.candiedcraft.block;

import com.thecandiedhat.candiedcraft.CandiedCraft;
import com.thecandiedhat.candiedcraft.item.ItemBlueCandy;
import com.thecandiedhat.candiedcraft.item.ItemLightBlueCandy;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;


public class ModBlocks {

    public static final Block[] BLOCKS = {
        new BlockBlueCandyBlock(Material.ROCK),
        new BlockLightBlueCandyBlock(Material.ROCK)
    };

    @SideOnly(Side.CLIENT)
    public static void preInit() {
        for(Block block : BLOCKS) {
            registerBlock(block);
        }
    }

    @SideOnly(Side.CLIENT)
    public static void registerBlock(Block block) {
        Item item = Item.getItemFromBlock(block);
        GameRegistry.register(block, new ResourceLocation(CandiedCraft.MODID, block.getUnlocalizedName()));
        GameRegistry.register(new ItemBlock(block), new ResourceLocation(CandiedCraft.MODID, item.getUnlocalizedName()));
        ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(  CandiedCraft.MODID + ":" + item.getUnlocalizedName(), "inventory"));
    }
}

ClientProxy.java (the proxy that runs the ModBlocks code)

package com.thecandiedhat.candiedcraft.proxy;

import com.thecandiedhat.candiedcraft.block.ModBlocks;
import com.thecandiedhat.candiedcraft.item.ModItems;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

public class ClientProxy extends CommonProxy {

    @Override
    public void preInit(FMLPreInitializationEvent event) {
        ModItems.preInit();
        ModBlocks.preInit();
    }

    @Override
    public void init(FMLInitializationEvent event) {

    }

    @Override
    public void postInit(FMLPostInitializationEvent event) {

    }

}

Crash Report:

---- Minecraft Crash Report ----
// But it works on my machine.

Time: 4/9/17 8:24 PM
Description: There was a severe problem during mod loading that has caused the game to fail

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from CandiedCraft (candiedcraft)
Caused by: java.lang.IllegalArgumentException: The name candiedcraft:tile.air has been registered twice, for net.minecraft.item.ItemBlock@1dece75a and net.minecraft.item.ItemBlock@129b75c.
  at net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry.add(FMLControlledNamespacedRegistry.java:480)
  at net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry.register(FMLControlledNamespacedRegistry.java:854)
  at net.minecraftforge.fml.common.registry.GameData.register_impl(GameData.java:225)
  at net.minecraftforge.fml.common.registry.GameData.register_impl(GameData.java:206)
  at net.minecraftforge.fml.common.registry.GameRegistry.register(GameRegistry.java:175)
  at com.thecandiedhat.candiedcraft.block.ModBlocks.registerBlock(ModBlocks.java:39)
  at com.thecandiedhat.candiedcraft.block.ModBlocks.preInit(ModBlocks.java:31)
  at com.thecandiedhat.candiedcraft.proxy.ClientProxy.preInit(ClientProxy.java:14)
  at com.thecandiedhat.candiedcraft.CandiedCraft.preInit(CandiedCraft.java:34)
  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:498)
  at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:643)
  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:498)
  at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
  at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
  at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
  at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
  at com.google.common.eventbus.EventBus.post(EventBus.java:275)
  at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:246)
  at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:224)
  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:498)
  at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
  at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
  at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
  at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
  at com.google.common.eventbus.EventBus.post(EventBus.java:275)
  at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:147)
  at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:647)
  at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:275)
  at net.minecraft.client.Minecraft.init(Minecraft.java:478)
  at net.minecraft.client.Minecraft.run(Minecraft.java:387)
  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:498)
  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:498)
  at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
  at GradleStart.main(GradleStart.java:26)


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

-- System Details --
Details:
  Minecraft Version: 1.11.2
  Operating System: Mac OS X (x86_64) version 10.12.4
  Java Version: 1.8.0_111, Oracle Corporation
  Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
  Memory: 495305264 bytes (472 MB) / 762839040 bytes (727 MB) up to 1908932608 bytes (1820 MB)
  JVM Flags: 0 total; 
  IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
  FML: MCP 9.38 Powered by Forge 13.20.0.2279 5 mods loaded, 5 mods active
  States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
  UCH   minecraft{1.11.2} [Minecraft] (minecraft.jar) 
  UCH   mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
  UCH   FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.11.2-13.20.0.2279.jar) 
  UCH   forge{13.20.0.2279} [Minecraft Forge] (forgeSrc-1.11.2-13.20.0.2279.jar) 
  UCE   candiedcraft{0.2.1.1b} [CandiedCraft] (CandiedCraft_main) 
  Loaded coremods (and transformers): 
\$\endgroup\$
  • \$\begingroup\$ Why are using both of MCP AND Forge? You need only one of them, not both. And it would be wise to use only Forge. \$\endgroup\$ – DH. Apr 10 '17 at 15:40
  • \$\begingroup\$ Um... pretty sure I need both. I don't know why, but when I installed the forge MDK, MCP was just... there. I didn't directly download MCP. \$\endgroup\$ – Ethan Cannoy Apr 10 '17 at 16:51
  • \$\begingroup\$ Forge uses MCP, so if you are using Forge we don't need to know about MCP. Also, don't say "Latest Version". Latest stable or beta version? Your question will be seen in the future and viewers will see "Latest Version" and will wonder what the heck was the "latest version" at that time. \$\endgroup\$ – DH. Apr 10 '17 at 19:19
0
\$\begingroup\$

In the constructor of each block you have set only the unlocalized name. You also need to use setRegistryName(<name>) so that it doesn't get registered as air(id 0) as you have noticed.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks! I realized that, but thought I'd leave the question up so that people could find the answer. I would have posted it, but I didn't know exactly what was going on. :) \$\endgroup\$ – Ethan Cannoy Apr 13 '17 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.