Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.9] registering blocks/items in 1.9[SOLVED]


winnetrie
 Share

Recommended Posts

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

Link to comment
Share on other sites

- Create the Block instance

- call

setRegistryName

on it.

- Pass it to

GameRegistry.register

- Create the ItemBlock instance

- call

setRegistryName

on it with the same name as the Block

- Pass that to

GameRegistry.register

as well

 

The last 3 steps are not optional, if you do not perform them your Block will not have an Item, meaning it cannot exist in an inventory or as an ItemEntity.

Link to comment
Share on other sites

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[])

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Because the registry name should be absolutely stable. Once set it should never ever change or the new version of your mod that changes it breaks old worlds.

It is important to make that explicit, unlocalized names are far less stable. Plus that substring crap is ugly as hell.

What should i use instead? Do i need to make my own method for it?
block.setRegistryName("myBlock");
block.setUnlocalizedName(block.getRegistryName().toString());

// in the .lang file:
tile.myMod:myBlock.name=My Block

 

Note that your unlocalized name now includes your ModID, which it should anyways.

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?

I don't know without seeing how you set the unlocalized name. But alas you should not be doing it this way anyways.

 

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

The registry name has nothing to do with the (item's) rendering.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.
Patreon: http://www.patreon.com/lexmanos
Paypal: http://paypal.me/LexManos

BitCoin: 1Q8rWvUNMM2T1ZfDaFeeYQyVXtYoeT6tTn

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

Yes, it is registering it with the same name, which is why it works, because that's correct. A Block and it's corresponding ItemBlock must have the same name, otherwise they are not related.

 

As for conflicts: Conflicts can only happen between things of the same type, an item and a block cannot conflict name-wise exactly like an enchantment and a potion can't.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You have invtweaks which is a mod for minecraft 1.16 and you have the version of jade for minecraft 1.18. Neither of these mods will work with minecraft 1.19   The 1.19 version of jade can be found here: https://www.curseforge.com/minecraft/mc-mods/jade/files/all?filter-game-version=1738749986%3a73407  
    • my ForgeSlider can't drag , it can only be click ,I'm not sure if I'm doing something wrong this is my Screen code public class MannequinScreen extends AbstractContainerScreen<MannequinMenu> { private EditBox NameBox; private final MannequinEntity mannequin; public final MannequinMenu menu; private ForgeSlider xRotationSlider; private ForgeSlider yRotationSlider; private ForgeSlider zRotationSlider; private ForgeSlider scaleSlider; private CycleButton<Part> partButton; private Part nowPart; private Rotations rotations; private float xMouse; private float yMouse; private static final ResourceLocation TEXTURE = new ResourceLocation(KpRandomThing.MODID, "textures/gui/mannequin.png"); public MannequinScreen(MannequinMenu container, Inventory inventory, Component text) { super(container, inventory, text); this.imageWidth = 176; this.imageHeight = 210; this.mannequin = container.mannequin; this.menu = container; } @Override public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); super.render(matrixStack, mouseX, mouseY, partialTicks); this.renderTooltip(matrixStack, mouseX, mouseY); this.xMouse = mouseX; this.yMouse = mouseY; } @Override protected void renderBg(PoseStack matrixStack, float partialTicks, int gx, int gy) { RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShaderTexture(0, TEXTURE); GuiComponent.blit(matrixStack, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight); RenderSystem.disableBlend(); int width = (this.width - this.imageWidth) / 2; int height = (this.height - this.imageHeight) / 2; InventoryScreen.renderEntityInInventory(width + 46, height + 106, 30, (float) (width + 51) - this.xMouse, (float) (height + 75 - 50) - this.yMouse, this.mannequin); } @Override public void init() { super.init(); this.minecraft.keyboardHandler.setSendRepeatsToGui(true); NameBox = new EditBox(this.font, this.leftPos + 6, this.topPos + 4, 99, 20, new TextComponent("name")); NameBox.setMaxLength(60); this.addRenderableWidget(NameBox); Button rename = new Button(this.leftPos + 114, this.topPos + 4, 54, 20, new TextComponent("Rename"), onPress -> { if (!NameBox.getValue().isEmpty()) { KpRandomThing.INSTANCE.sendToServer( new MessagePacket(1, new TextComponent(NameBox.getValue()))); } }); this.addRenderableWidget(rename); int sliderX = this.leftPos + 92; int sliderY = this.topPos + 5; this.partButton = createPartButton(sliderX, sliderY + 80); this.addRenderableWidget(partButton); rotations = this.partButton.getValue().getPose(mannequin); this.xRotationSlider = createAngleSlider(sliderX, sliderY + 20, 74, 20, "X:", rotations.getX()); this.yRotationSlider = createAngleSlider(sliderX, sliderY + 40, 74, 20, "Y:", rotations.getY()); this.zRotationSlider = createAngleSlider(sliderX, sliderY + 60, 74, 20, "Z:", rotations.getZ()); this.scaleSlider = new ForgeSlider(sliderX, sliderY + 100, 74, 20, new TranslatableComponent("button.kp_random_thing.scale"), TextComponent.EMPTY, 0.1, 2, mannequin.getScale(), 0, 2, true); this.addRenderableWidget(xRotationSlider); this.addRenderableWidget(yRotationSlider); this.addRenderableWidget(zRotationSlider); this.addRenderableWidget(scaleSlider); } @Override protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) { } @Override public boolean mouseReleased(double xMouse, double yMouse, int id) { updata(); return super.mouseReleased(xMouse, yMouse, id); } @Override public boolean keyPressed(int key, int b, int c) { if (key == 256) { this.minecraft.player.closeContainer(); return true; } return super.keyPressed(key, b, c); } private void updata() { if (nowPart != partButton.getValue()) switchPart(); String name = partButton.getValue().name; double x = xRotationSlider.getValue(); double y = yRotationSlider.getValue(); double z = zRotationSlider.getValue(); double scale = scaleSlider.getValue(); KpRandomThing.INSTANCE.sendToServer(new MessagePacket(0, x, y, z, scale, new TextComponent(name))); } private void switchPart() { Rotations rotations = partButton.getValue().getPose(mannequin); this.xRotationSlider.setValue(rotations.getX()); this.yRotationSlider.setValue(rotations.getY()); this.zRotationSlider.setValue(rotations.getZ()); this.nowPart = partButton.getValue(); } private CycleButton<Part> createPartButton(int width, int height) { CycleButton<Part> button = CycleButton.builder(Part::getName).withValues(Part.values()).create(width, height, 80, 20, new TranslatableComponent("button.kp_random_thing.part")); return button; } private ForgeSlider createAngleSlider(int x, int y, int width, int height, String prefix, double currentValue) { return new ForgeSlider(x, y, width, height, new TextComponent(prefix), TextComponent.EMPTY, -180D, 180D, currentValue, 0, 2, true); } public enum Part { HEAD(MannequinEntity.DATA_HEAD_POSE, MannequinEntity.HEAD), BODY(MannequinEntity.DATA_BODY_POSE, MannequinEntity.BODY), LEFT_ARM(MannequinEntity.DATA_LEFT_ARM_POSE, MannequinEntity.LEFT_ARM), RIGHT_ARM(MannequinEntity.DATA_RIGHT_ARM_POSE, MannequinEntity.RIGHT_ARM), LEFT_LEG(MannequinEntity.DATA_LEFT_LEG_POSE, MannequinEntity.LEFT_LEG), RIGHT_LEG(MannequinEntity.DATA_RIGHT_LEG_POSE, MannequinEntity.RIGHT_LEG); final EntityDataAccessor<Rotations> dataPose; final String name; Part(EntityDataAccessor<Rotations> dataPose, String name) { this.dataPose = dataPose; this.name = name; } public Rotations getPose(ArmorStand entity) { if (entity == null) { return new Rotations(0, 0, 0); } return entity.getEntityData().get(dataPose); } public Component getName() { return new TranslatableComponent("button.kp_random_thing.part." + name); } } }  
    • Hello, I am trying to install client-side mods, to better my minecraft experience on servers, but I run into a few issues with some dependencies missing, so I would like if someone would be able to help me.  Here are the following errors: Error loading mods 3 errors have occurred during loading --------------------------------------- InventoryTweaksRenewed(invtweaks) has failed to load correctly java.lang.NoClassDefFoundError:net/minecraft/client/gui/widget/Widget Jade(jade) has failed to load correctly java.lang.NoClassDefFoundError:net/minecraftforge/event/entity/EntityJoinWorldEvent Waila(Jade)(waila)has failed to load correctly java.lang.NoClassDefFoundError:net/minecraftforge/client/event/ClientPlayerNetworkEvent$LoggedOutEvent Here is a pastebin of the crash report: https://pastebin.com/uMxfcUP3
    • You don't show the error, or minecraft version or any other useful information. "It keeps on crashing and I can't get it to load" is useless.   The github project you posted is incomplete. It has no build.gradle, etc. so we can't build it ourselves to find out the problem you have.   GUESSING: I can see a number of obvious problems with your code:   1) https://github.com/Tucky143/Buzz/blob/a03ffc801f439a095e9c272dff6510970543f0e2/src/main/java/com/example/examplemod/villager/ModVillagers.java#L29 Here you are doing instance equality tests for a Holder<PoiType> with a PoiType. This will never be true.   2) https://github.com/Tucky143/Buzz/blob/a03ffc801f439a095e9c272dff6510970543f0e2/src/main/java/com/example/examplemod/villager/ModVillagers.java#L36 That reflection code does nothing. Look at the method you are calling. Although I suspect you can't find it. The signature of the method you are using is for 1.18.x while the above methods you are using in (1) above are the signatures of methods in 1.19.x    
  • Topics

×
×
  • Create New...

Important Information

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