Jump to content

Recommended Posts

Posted

I managed to update to 1.8 but i also wanted to get asap to 1.9.

There i'm struggling with the registering of blocks and items.

in 1.8 i use this:

GameRegistry.registerBlock(bricks = new Bricks("bricks",Material.rock,2,2), ItemBlockMeta.class, "bricks");

 

but in 1.9 registerBlock is deprecated it looks like this:

 

GameRegistry.registerBlock(bricks = new Bricks("bricks",Material.rock,2,2), ItemBlockMeta.class, "bricks");

It still works but i want to know what the new "way" is to register it

Posted

So i tried something but i can't make it work.

I have this:

final String colors[] = {"white","orange","magenta","light_blue","yellow","lime","pink","gray","silver","cyan","purple","blue","brown","green","red","black"};
	ResourceLocation[] resLoc = new ResourceLocation[16];
	for (int i=0; i < 16; i++)
	resLoc[i] = new ResourceLocation("tem:bricks_" + colors[i]);
	ModelBakery.registerItemVariants(Item.getItemFromBlock(bricks), resLoc);
	bricks = new Bricks("bricks",Material.rock,2,2);
	ItemBlock bricksItemBlock = new ItemBlock(bricks);
	GameRegistry.register(bricks, resLoc);
	GameRegistry.register(bricksItemBlock, resLoc);

 

i have a red line under "register" saying this:

The method register(K, ResourceLocation) in the type GameRegistry is not applicable for the arguments (Block, ResourceLocation[])

 

Posted

So , i tried following your steps and i did this:

bricks = new Bricks("bricks",Material.rock,2,2);
	ItemBlock bricksItemBlock = new ItemBlockMeta(bricks);
	GameRegistry.register(bricks.setRegistryName(bricks.getUnlocalizedName().substring(5)));
	GameRegistry.register(bricksItemBlock.setRegistryName(bricks.getUnlocalizedName().substring(5)));

 

This seems to work fine except the textures for the items are not showing up.

The blocks (or better the itemblocks) are all there in the creative tab

They have the right name also, but they have all the black/pink texture.

If i use them ( so placing a block down) , the block placed has the right texture.

 

So what am i doing wrong. Why are the item textures for my blocks not showing?

Posted

Can you also explain, why i should not use unlocalizedname?

What should i use instead? Do i need to make my own method for it?

 

i figured that this:

GameRegistry.register(bricksItemBlock.setRegistryName(bricks.getUnlocalizedName().substring(5)));

sets the registryname to "bricks" while this:

GameRegistry.register(bricks.setRegistryName(bricks.getUnlocalizedName().substring(5)));

gives me "bricks_white","bricks_orange", etc etc.

I do not understand why that is? why does it return for brick the right unlocalizedname and for the itemblock not?

 

Also i tested it just to be sure if i change the itemblock registry to this:

GameRegistry.register(bricksItemBlock.setRegistryName("bricks_orange"));

then the texture works but ofc only for the orange block

 

Posted

ok this is my bricks class:

 

package com.winnetrie.tem.blocks;

import java.util.List;

import com.winnetrie.tem.TemNameRegistry;
import com.winnetrie.tem.tem;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
//import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
//import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
//import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class Bricks extends Block implements IMetaBlockName{


public Bricks(String unlocalizedName, Material material, float hardness, float resistance) {
	super(material);
	this.setUnlocalizedName(unlocalizedName);
        this.setCreativeTab(tem.testtab);
        this.setHardness(hardness);
        this.setResistance(resistance);
        this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.WHITE));
        setRegistryName("--COLORS HERE--"+"_bricks");
        setUnlocalizedName(this.getRegistryName().toString());
        
        
}
public static final PropertyEnum TYPE = PropertyEnum.create("type", Bricks.EnumType.class);

@Override
protected BlockStateContainer createBlockState() {
    return new BlockStateContainer(this, new IProperty[] { TYPE });
}

@Override
public IBlockState getStateFromMeta(int meta) {
	EnumType type = null;
	switch(meta){
	case 0: type = EnumType.WHITE;
		break;
	case 1: type = EnumType.ORANGE;
		break;
	case 2: type = EnumType.MAGENTA;
		break;
	case 3: type = EnumType.LIGHTBLUE;
		break;
	case 4: type = EnumType.YELLOW;
		break;
	case 5: type = EnumType.LIME;
		break;
	case 6: type = EnumType.PINK;
		break;
	case 7: type = EnumType.GRAY;
		break;
	case 8: type = EnumType.SILVER;
		break;
	case 9: type = EnumType.CYAN;
		break;
	case 10: type = EnumType.PURPLE;
		break;
	case 11: type = EnumType.BLUE;
		break;
	case 12: type = EnumType.BROWN;
		break;
	case 13: type = EnumType.GREEN;
		break;
	case 14: type = EnumType.RED;
		break;
	case 15: type = EnumType.BLACK;
		break;
	}
	//return ((IBlockState) blockState).withProperty(TYPE2,type);
    return getDefaultState().withProperty(TYPE, type);// == 0 ? EnumType.WHITE : EnumType.BLACK);
}

@Override
public int getMetaFromState(IBlockState state) {
    EnumType type = (EnumType) state.getValue(TYPE);
    return type.getID();
}
@Override
public int damageDropped(IBlockState state) {
    return getMetaFromState(state);
}
@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
    list.add(new ItemStack(itemIn, 1, 0)); //Meta 0
    list.add(new ItemStack(itemIn, 1, 1)); //Meta 1
    list.add(new ItemStack(itemIn, 1, 2));
    list.add(new ItemStack(itemIn, 1, 3));
    list.add(new ItemStack(itemIn, 1, 4));
    list.add(new ItemStack(itemIn, 1, 5));
    list.add(new ItemStack(itemIn, 1, 6));
    list.add(new ItemStack(itemIn, 1, 7));
    list.add(new ItemStack(itemIn, 1, );
    list.add(new ItemStack(itemIn, 1, 9));
    list.add(new ItemStack(itemIn, 1, 10));
    list.add(new ItemStack(itemIn, 1, 11));
    list.add(new ItemStack(itemIn, 1, 12));
    list.add(new ItemStack(itemIn, 1, 13));
    list.add(new ItemStack(itemIn, 1, 14));
    list.add(new ItemStack(itemIn, 1, 15));
}
@Override
public String getSpecialName(ItemStack stack) {
	int meta = stack.getItemDamage();
	String name="";
	switch(meta){
	case 0:name="white";
	break;
	case 1:name="orange";
	break;
	case 2:name="magenta";
	break;
	case 3:name="light_blue";
	break;
	case 4:name="yellow";
	break;
	case 5:name="lime";
	break;
	case 6:name="pink";
	break;
	case 7:name="gray";
	break;
	case 8:name="silver";
	break;
	case 9:name="cyan";
	break;
	case 10:name="purple";
	break;
	case 11:name="blue";
	break;
	case 12:name="brown";
	break;
	case 13:name="green";
	break;
	case 14:name="red";
	break;
	case 15:name="black";
	break;
	}
    return name;    
}

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
    {
        return getItem(world, pos, state);
}
public enum EnumType implements IStringSerializable{

	WHITE(0, "white"), ORANGE(1, "orange"), MAGENTA(2, "magenta"), LIGHTBLUE(3, "light_blue"), YELLOW(4, "yellow"), LIME(5, "lime"), PINK(6, "pink"), GRAY(7, "gray"), 
	SILVER(8, "silver"), CYAN(9, "cyan"), PURPLE(10, "purple"), BLUE(11, "blue"), BROWN(12, "brown"), GREEN(13, "green"), RED(14, "red"), BLACK(15, "black");

    private int ID;
    private String name;
    
    private EnumType(int ID, String name) {
        this.ID = ID;
        this.name = name;
    }
    
    @Override
    public String getName() {
        return name;
    }

    public int getID() {
        return ID;
    }
    @Override
    public String toString() {
        return getName();
    }
}
}

 

As you can see i need to change the "--COLORS HERE--"

I have no idea how to do it? I tried many things but still

Posted

bf620e38d6.png

Isn't this so much cleaner... and it does the EXACT same thing as your code.... You really need to go and learn some basic code style/java instead of copy pasting tutorials.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

It does indeed looks cleaner.

I didn't just copy pasted tutorials.

For this class i followed a tutorial for 1.8 from MrCrayFish on youtube.

He explains why you need those method, what they do and where you can get them.

So i copy-pasted the methods from the minecraft block.class over to mine and then i changed them to what i need.

That switch statement wasn't even shown in his tutorial.

I know i need to learn more java, i'm trying to pick it up while modding.

As in fact i have some programming knowledge of c++

I don't want to copy paste stuff without knowing and understanding what it does.

 

I see to get the specialname you return the enumtype and chanhe them to lowercase. That's nice!

EDIT:

I need to (i think) get the "specialname" into the place of "--COLORS HERE--"

setRegistryName("--COLORS HERE--"+"_bricks");
        setUnlocalizedName(this.getRegistryName().toString());

I don't know how to do this.

Posted

Oh yes i see.

It seems to work now:

bricks = new Bricks("bricks",Material.rock,2,2);
	bricksItemBlock = new ItemBlockMeta(bricks);
	GameRegistry.register(bricks.setRegistryName("bricks"));
	GameRegistry.register(bricksItemBlock.setRegistryName("bricks"));
	final String colors[] = {"white","orange","magenta","light_blue","yellow","lime","pink","gray","silver","cyan","purple","blue","brown","green","red","black"};
	ResourceLocation[] resLoc = new ResourceLocation[16];
	for (int i=0; i < 16; i++)
	resLoc[i] = new ResourceLocation("tem:bricks_" + colors[i]);
	ModelBakery.registerItemVariants(Item.getItemFromBlock(bricks), resLoc);

and for my block i have this now:

 

package com.winnetrie.tem.blocks;

import java.util.List;

import com.winnetrie.tem.TemNameRegistry;
import com.winnetrie.tem.tem;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
//import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
//import net.minecraft.util.BlockPos;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
//import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class Bricks extends Block implements IMetaBlockName{
public static final PropertyEnum TYPE = PropertyEnum.create("type", Bricks.EnumType.class);
public Bricks(String unlocalizedName, Material material, float hardness, float resistance) {
	super(material);
	this.setUnlocalizedName(unlocalizedName);
        this.setCreativeTab(tem.testtab);
        this.setHardness(hardness);
        this.setResistance(resistance);
        this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.WHITE));
        
        
}
@Override
protected BlockStateContainer createBlockState() {
    return new BlockStateContainer(this, new IProperty[] { TYPE });
}
@Override
public IBlockState getStateFromMeta(int meta) {	
    return getDefaultState().withProperty(TYPE, EnumType.values()[meta]);
}

@Override
public int getMetaFromState(IBlockState state) {
    return ((Enum<EnumType>) state.getValue(TYPE)).ordinal();
}
@Override
public int damageDropped(IBlockState state) {
    return getMetaFromState(state);
}
@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
	for (EnumType t : EnumType.values())
    list.add(new ItemStack(itemIn, 1, t.ordinal()));  
}

@Override
public String getSpecialName(ItemStack stack) {
	return EnumType.values()[stack.getItemDamage()].name().toLowerCase();
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
    {
        return getItem(world, pos, state);
}

public enum EnumType implements IStringSerializable{

	WHITE(0, "white"), ORANGE(1, "orange"), MAGENTA(2, "magenta"), LIGHTBLUE(3, "light_blue"), YELLOW(4, "yellow"), LIME(5, "lime"), PINK(6, "pink"), GRAY(7, "gray"), 
	SILVER(8, "silver"), CYAN(9, "cyan"), PURPLE(10, "purple"), BLUE(11, "blue"), BROWN(12, "brown"), GREEN(13, "green"), RED(14, "red"), BLACK(15, "black");

    private int ID;
    private String name;
   
    private EnumType(int ID, String name) {
        this.ID = ID;
        this.name = name;
            
    }
    @Override
    public String getName() {
        return name;
    }
    public int getID() {
        return ID;
    }
    @Override
    public String toString() {
        return getName();
    }
}

}

 

I tried Lexmanos his simple and much cleaner version of  "public enum EnumType" but that doesn't work at all

When i try this it gives me an error at this:

public static final PropertyEnum TYPE = PropertyEnum.create("type", Bricks.EnumType.class);

a red line appear under "create" saying this :

 

Bound mismatch: The generic method create(String, Class<T>) of type PropertyEnum<T> is not applicable for the arguments (String, Class<Bricks.EnumType>). The inferred type Bricks.EnumType is not a valid substitute for the bounded parameter <T extends Enum<T> & IStringSerializable>

 

i could fix that with implementing IStringSerializable but the it asks me also for a method, this :

@Override
    public String getName() {
        return null;
    }

So because this crashes the game changed it back to this:

 

public enum EnumType implements IStringSerializable{

	WHITE(0, "white"), ORANGE(1, "orange"), MAGENTA(2, "magenta"), LIGHTBLUE(3, "light_blue"), YELLOW(4, "yellow"), LIME(5, "lime"), PINK(6, "pink"), GRAY(7, "gray"), 
	SILVER(8, "silver"), CYAN(9, "cyan"), PURPLE(10, "purple"), BLUE(11, "blue"), BROWN(12, "brown"), GREEN(13, "green"), RED(14, "red"), BLACK(15, "black");

    private int ID;
    private String name;
   
    private EnumType(int ID, String name) {
        this.ID = ID;
        this.name = name;
            
    }
    @Override
    public String getName() {
        return name;
    }
    public int getID() {
        return ID;
    }
    @Override
    public String toString() {
        return getName();
    }
}

 

and this works fine i think i can't get go around this.

 

 

Posted

So now (i'm trying to improve) i did this:

public Bricks(String unlocalizedName, Material material, float hardness, float resistance) {
	super(material);
	//this.setUnlocalizedName(unlocalizedName);
        this.setCreativeTab(tem.testtab);
        this.setHardness(hardness);
        this.setResistance(resistance);
        this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.WHITE));
        this.setRegistryName("bricks");
        this.setUnlocalizedName(this.getRegistryName().toString());
        
}

So the registryname is now in the bricks class. I think it's better.

for the gameregistry i have now this:

GameRegistry.register(bricks);
	GameRegistry.register(bricksItemBlock.setRegistryName(bricks.getRegistryName()));

It seems to work all fine.

Just 1 thing i was wondering about. Does this not register "bricks" and "bricksItemBlock" with the same name? wich i defined as "bricks"

If it does. Does it matter at all, can this conflict with anyhting?

Just wondering. Because it works , doesn't mean it is done right. Right?

 

 

  • 2 weeks later...
Posted

Going to hijack this thread:

 

The following throws a NullPointerException, and it is basically equivalent to winnetrie's working code. It's contained in Main's preInit, and I'm on forge-1.9.12.16.0.1865-1.9

 

Any ideas? What silly thing am I overlooking? The last line below is what the stacktrace points to.

 

		blockRedstoneAnvil = new BlockRedstoneAnvil();
	GameRegistry.register(blockRedstoneAnvil.setRegistryName("redstone_anvil"));		
	itemRedstoneAnvilBlock = Item.getItemFromBlock((Block) blockRedstoneAnvil);
	GameRegistry.register(itemRedstoneAnvilBlock.setRegistryName(blockRedstoneAnvil.getRegistryName()));

 

Interestingly enough, everything seemed to be working fine without registering the item, and using the deprecated registerBlock method.

Posted

Why are you casting a block to a block?

Item.getItemFromBlock((Block) blockRedstoneAnvil);

That may be your issue. Other than that I am looking at this code and it looks fine.

Posted

More context:

 

Main.class

@Mod(modid = Main.MOD_ID, name = Main.MOD_NAME, version = Main.VERSION)
public class Main {

public static final String MOD_ID = "nates1984redstoneanvil";
public static final String MOD_NAME = "Redstone Anvil";
public static final String VERSION = "1.1";
public static SimpleNetworkWrapper network;
public static Block blockRedstoneAnvil;
public static Item itemRedstoneAnvilBlock;

@Instance(MOD_ID)
public static Main instance;

@SidedProxy(clientSide = "nates1984.redstoneanvil.proxy.ClientProxy", serverSide = "nates1984.redstoneanvil.proxy.CommonProxy")
public static CommonProxy proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent e) {

	network = NetworkRegistry.INSTANCE.newSimpleChannel("nates1984redstoneanvil");
	network.registerMessage(RenameMessage.Handler.class, RenameMessage.class, 0, Side.SERVER);
	network.registerMessage(RenameMessage.Handler.class, RenameMessage.class, 0, Side.CLIENT);

	blockRedstoneAnvil = new BlockRedstoneAnvil();
	GameRegistry.register(blockRedstoneAnvil.setRegistryName("redstone_anvil"));

	itemRedstoneAnvilBlock = Item.getItemFromBlock(blockRedstoneAnvil);
	GameRegistry.register(itemRedstoneAnvilBlock.setRegistryName(blockRedstoneAnvil.getRegistryName()));

	proxy.preInit();
}

@EventHandler
public void init(FMLInitializationEvent e) {

    GameRegistry.addRecipe(new ItemStack(blockRedstoneAnvil), "AAA", "BCB", "CCC", 
    		'A', Blocks.iron_block, 'B', Blocks.redstone_block, 'C', Items.iron_ingot);
    
    NetworkRegistry.INSTANCE.registerGuiHandler(Main.instance, new GuiHandler());
    
	proxy.init();
}

@EventHandler
public void postInit(FMLPostInitializationEvent e) {
	proxy.postInit();
}

}

 

Stacktrace

[23:21:10] [Client thread/ERROR] [FML]: The following problems were captured during this phase
[23:21:10] [Client thread/ERROR] [FML]: Caught exception from nates1984redstoneanvil
java.lang.NullPointerException
at nates1984.redstoneanvil.Main.preInit(Main.java:56) ~[bin/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560) ~[forgeSrc-1.9-12.16.0.1865-1.9.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228) ~[forgeSrc-1.9-12.16.0.1865-1.9.jar:?]
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206) ~[forgeSrc-1.9-12.16.0.1865-1.9.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135) [LoadController.class:?]
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556) [Loader.class:?]
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:240) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:472) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:381) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
[23:21:10] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:646]: ---- Minecraft Crash Report ----
// There are four lights!

Time: 4/22/16 11:21 PM
Description: Initializing game

java.lang.NullPointerException: Initializing game
at nates1984.redstoneanvil.Main.preInit(Main.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:228)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:135)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:240)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:472)
at net.minecraft.client.Minecraft.run(Minecraft.java:381)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at nates1984.redstoneanvil.Main.preInit(Main.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:228)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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:135)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:240)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:472)

-- Initialization --
Details:
Stacktrace:
at net.minecraft.client.Minecraft.run(Minecraft.java:381)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

Posted

Pretty sure you can't Item.getItemFromBlock() before you've registered the itemblock.

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.

Posted

Still seeing the same error after putting getItemFromBlock after register.

 

Edit: Maybe this line from the console output is helpful:

 

[23:57:37] [Client thread/ERROR] [FML]: Fatal errors were detected during the transition from PREINITIALIZATION to INITIALIZATION. Loading cannot continue

 

Edit2: Note that the following code from the working 1.8 version of this appears to work without issue:

 

		blockRedstoneAnvil = new BlockRedstoneAnvil().setUnlocalizedName("redstone_anvil");
    GameRegistry.registerBlock(blockRedstoneAnvil, ItemRedstoneAnvilBlock.class, "redstone_anvil");

    itemRedstoneAnvilBlock = GameRegistry.findItem("nates1984redstoneanvil", "redstone_anvil");

Posted

The problem is that you have not associated an ItemBlock with your Block, so Item#getItemFromBlock()  returns null. Create the ItemBlock by calling the constructor of ItemBlock that takes a Block as a parameter, then register that instead.

Posted

That worked. Thanks a bunch!

 

		itemRedstoneAnvilBlock = new ItemBlock(blockRedstoneAnvil);
	GameRegistry.register(itemRedstoneAnvilBlock.setRegistryName(blockRedstoneAnvil.getRegistryName()));

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.