Jump to content

[1.8] My First Modding Experience


statphantom

Recommended Posts

Never ever ever create new Items outside of preInit! Creating a new Item means you are creating a new type of Item. You must re-use the static Item instance you create in preInit.

 

THANK YOU! Light bulb moment, I am such an idiot I completely forget it is a static variable in the mod class. I knew there was something wrong with my calling my item constructor but had no idea how to get around it, it is working now :D thanks!!!!

Link to comment
Share on other sites

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

I am trying to register a texture but keep getting a nullpointer exception.

 

Maybe it's because I'm using the forge eclipse environment it is not registering it in the right place? help anyone? :)

 

I am using this....

 

    public static void regTexture(Item item) {
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
    }

Link to comment
Share on other sites

If you haven't found it yet:

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample

 

I don't know why I didn't post it earlier...

 

Should resolve all your basic problems.

 

More info:

http://greyminecraftcoder.blogspot.co.at/p/list-of-topics.html

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

If you haven't found it yet:

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample

 

I don't know why I didn't post it earlier...

 

Should resolve all your basic problems.

 

More info:

http://greyminecraftcoder.blogspot.co.at/p/list-of-topics.html

 

I have checked greyminecraftcoder and been looking at those examples but still cant figure out where to put my textures.

 

I register my item here....

 

    @EventHandler
    public void preInit (FMLPreInitializationEvent event) {
    	
    	System.out.println("Loading " + MODNAME + "!");
    	System.out.println("Version " + VERSION + "!");
    	
    	sharpstick = new SharpStick();
    	
    	MinecraftForge.EVENT_BUS.register(new LevelEventHandler());
    	
    	if (event.getSide() == Side.CLIENT) {
    		regTexture(sharpstick);                                <------ calling here
    	}
    	
    	GameRegistry.addRecipe(new ItemStack(sharpstick),
    	"A ",
    	" A",
    	'A', Items.stick);
    }

 

I have tried various places to put the texture files but I have put it in src/main/resources/assets/ModName/textures/items

and my .json files in src/main/resources/assets/ModName/models/item

Link to comment
Share on other sites

What do I use to get the itemStack of a custom item? Items class only contains vanilla items, do I need to do a search for name?

 

Of you didn't figure it out:

New ItemStack (MainModClass.yourItem)

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

 

Main Mod Class

 

package tutorial.generic;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = Level.MODID, name = Level.MODNAME, version = Level.VERSION)
public class Level {
    public static final String MODID = "StatsLevelMod";
    public static final String MODNAME = "Level";
    public static final String VERSION = "1.0.1";
}

 

Oooops!  Make your mod ID all lower case.  That's probably part, if not all of your problem with the texture

 

Link to comment
Share on other sites

 

Main Mod Class

 

package tutorial.generic;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = Level.MODID, name = Level.MODNAME, version = Level.VERSION)
public class Level {
    public static final String MODID = "StatsLevelMod";
    public static final String MODNAME = "Level";
    public static final String VERSION = "1.0.1";
}

 

Oooops!  Make your mod ID all lower case.  That's probably part, if not all of your problem with the texture

 

thanks, fixed this but still not working, I think it might be a problem with my path but I can't find any forge eclipse environment path example to help iron out the problem

my current path is.

 

src/main/resources/assets/statslevelmod/textures/items/sharpStick.png

NOT eclipse/src but have tried it in their also.

 

PS: I really am grateful of everyone's help and I hope I'm not becoming annoying :P

Link to comment
Share on other sites

Post your json file for the texture.

 

path is:

src/main/resources/assets/statslevelmod/models/item/sharpStrick.json

{
    "parent":"builtin/generated",
    "textures": {
        "layer0":"statslevelmod:items/sharpStick"
    },
    "display": {
        "thirdperson": {
            "rotation": [ -90, 0, 0 ],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "firstperson": {
            "rotation": [ 0, -135, 25 ],
            "translation": [ 0, 4, 2 ],
            "scale": [ 1.7, 1.7, 1.7 ]
        }
    }
}

Link to comment
Share on other sites

I'm unsure if this is it l, because json stuff...  But try renaming the json file from sharpStick to SharpStick.

I haven't messed with textures lately, but I vaguely remember doing something similar to that and it fixed it.

I'm also on my phone, so if that doesn't work, I'll check back in a little bit when I get back home.

Link to comment
Share on other sites

I'm unsure if this is it l, because json stuff...  But try renaming the json file from sharpStick to SharpStick.

I haven't messed with textures lately, but I vaguely remember doing something similar to that and it fixed it.

I'm also on my phone, so if that doesn't work, I'll check back in a little bit when I get back home.

 

Nop :( no change, still getting nullpointer exception

Link to comment
Share on other sites

Fixed my texture problem! it was both a wrong path but the crash was due to me calling it during preInit, not Init.

 

new idea: I want sharp sticks to only be gathered when under leaves, I am thinking of doing a loop check, checking the block two above the block clicked, then +1 Z axis untill either it hits a leaf block then it passes true, up to..... I am tihnking 20 blocks high at which point it will return false. Is this a good way to do this or is there a better way?

Link to comment
Share on other sites

Show your entityItem class.

 

is this what you mean?

package statslevelmod;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class SharpStick extends Item {

private final String name = "sharpStick";

public SharpStick() {
	super();

	GameRegistry.registerItem(this, name);
	setCreativeTab(CreativeTabs.tabMisc);
	setUnlocalizedName(name);
	setMaxStackSize(64);
}
}

Link to comment
Share on other sites

Now, my mistake - show where you make the spawnEntityInWorld for the item

 

@SubscribeEvent
public void onPlayerClickEvent(PlayerInteractEvent event) {
	if (event.action == Action.LEFT_CLICK_BLOCK) {

		Block block = event.world.getBlockState(event.pos).getBlock();

		if (event.entityPlayer.getCurrentEquippedItem() == null) {

			if (block == Blocks.grass && event.face == event.face.UP) {

				if (!event.world.isRemote) {

					if (checkIfUnderLeaves(event)) {

						float chance = Level.rnumber.nextFloat();

						if (chance < 0.10f) {
							event.world.setBlockState(event.pos, Blocks.dirt.getDefaultState());
						}

						if (chance < 0.15f) {
							event.world.spawnEntityInWorld(new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), new ItemStack(Items.stick)));
						} else if (chance > 0.985) {
							event.world.spawnEntityInWorld(new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), new ItemStack(Level.sharpstick)));

						}
					}
				}
			}

 

I think its due to im spawning the item at the block location when the block is not destroyed, but unsure what to do about it since i do the same thing about logs where you can be any side so spawning on top wont work

Link to comment
Share on other sites

I have my rake working, however since it doesn't destroy any blocks it never calls item use when using it as a rake, I can manually damage the item stack easily using helditem.attemptDamageItem(1, Level.rnumber); but I cant find out how to manually destroy the item when this method breaks the item. Anyone help?

 

Thanks :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements




×
×
  • Create New...

Important Information

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