Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

This is what I am trying to register:

 

item10mmPistol = registerItem(new ItemGun(item10mmAmmo).setUnlocalizedName("10mmPistol"));

 

item10mmPistol is what I have registered already, and item10mmAmmo is another item I have registered that I wish to use as a consumable. The problem is when I run it, the item10mmPistol, is no longer registered. It seems as though it just re-registers item10mmAmmo. I am just wondering if anyone has any ideas as to how to get around this problem. Everything has already been registered and textured before, its just when I have tried to put an already registered item into this constructor, things seem to mess up.

 

 

  • Author

ItemDecMO Class

package net.mineout.mod.items;

import net.minecraft.item.Item;

public class ItemDecMO {

//Ammo
public static Item item308Ammo;
public static Item item32Ammo;
public static Item item44MagnumAmmo;
public static Item item10mmAmmo;
public static Item item12GaugeAmmo;
public static Item item556mmAmmo;
public static Item item5mmAmmo;
public static Item itemAlienPowerCellAmmo;
public static Item itemAlienPowerModuleAmmo;
public static Item itemBBAmmo;
public static Item itemDartAmmo;
public static Item itemElectronChargePackAmmo;
public static Item itemEnergyCellAmmo;
public static Item itemFlamethrowerFuelAmmo;
public static Item itemMesmetronPowerCellAmmo;
public static Item itemMicrofusionCellAmmo;
public static Item itemMiniNukeAmmo;
public static Item itemMisileAmmo;
public static Item itemRailwaySpikesAmmo;

//Guns
public static Item item10mmPistol;

}

 

 

ItemsMO class

package net.mineout.mod.items;

import static net.mineout.mod.items.ItemDecMO. *;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.Item;


public class ItemsMO {

public static void init() {
	registerItems();
}

public static void registerItems() {
	//Guns
	item10mmPistol = registerItem(new ItemGun(item10mmAmmo).setUnlocalizedName("10mmPistol"));
	//Ammo
	item308Ammo = registerItem(new SimpleItemsMO().setUnlocalizedName("308Ammo"));
	item32Ammo = registerItem(new SimpleItemsMO().setUnlocalizedName("32Ammo"));
	item44MagnumAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("44MagnumAmmo"));
	item10mmAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("10mmAmmo"));
	item12GaugeAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("12GaugeAmmo"));
	item556mmAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("556Ammo"));
	item5mmAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("5mmAmmo"));
	itemAlienPowerCellAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("AlienPowerCellAmmo"));
	itemAlienPowerModuleAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("AlienPowerModuleAmmo"));
	itemBBAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("BBAmmo"));
	itemElectronChargePackAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("ElectronChargePackAmmo"));
	itemFlamethrowerFuelAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("FlamethrowerFuelAmmo"));
	itemMesmetronPowerCellAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("MesmetronPowerCellAmmo"));
	itemMicrofusionCellAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("MicrofusionCellAmmo"));
	itemMiniNukeAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("MiniNukeAmmo"));
	itemMisileAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("MisileAmmo"));
	itemRailwaySpikesAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("RailwaySpikesAmmo"));

}

public static Item registerItem(Item item) {
	GameRegistry.registerItem(item, item.getUnlocalizedName().substring(5));
	return item;
}

}

 

 

ItemGun class

package net.mineout.mod.items;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.mineout.mod.Main;
import net.mineout.mod.entity.projectiles.EntityBullet;
import static net.mineout.mod.items.ItemDecMO. *;

public class ItemGun extends Item {

private Item Ammo;

public ItemGun(Item x){
	this.Ammo = x;
}

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,EntityPlayer par3EntityPlayer) {

	if(par3EntityPlayer.capabilities.isCreativeMode||par3EntityPlayer.inventory.consumeInventoryItem(Ammo)) {

        par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
        if (!par2World.isRemote) {
        	
        	par2World.spawnEntityInWorld(new EntityBullet(par2World, par3EntityPlayer));
        	
        }
        
	}

    return par1ItemStack;
    
}

@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
	this.itemIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5));
}

}

  • Author

Ok so now it looks like this:

 

ItemsMO class

package net.mineout.mod.items;

import static net.mineout.mod.items.ItemDecMO. *;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.Item;


public class ItemsMO {

public static void init() {
	registerItems();
}

public static void registerItems() {
	//Ammo
	item308Ammo = registerItem(new SimpleItemsMO().setUnlocalizedName("308Ammo"));
	item32Ammo = registerItem(new SimpleItemsMO().setUnlocalizedName("32Ammo"));
	item44MagnumAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("44MagnumAmmo"));
	item10mmAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("10mmAmmo"));
	item12GaugeAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("12GaugeAmmo"));
	item556mmAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("556Ammo"));
	item5mmAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("5mmAmmo"));
	itemAlienPowerCellAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("AlienPowerCellAmmo"));
	itemAlienPowerModuleAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("AlienPowerModuleAmmo"));
	itemBBAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("BBAmmo"));
	itemElectronChargePackAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("ElectronChargePackAmmo"));
	itemFlamethrowerFuelAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("FlamethrowerFuelAmmo"));
	itemMesmetronPowerCellAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("MesmetronPowerCellAmmo"));
	itemMicrofusionCellAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("MicrofusionCellAmmo"));
	itemMiniNukeAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("MiniNukeAmmo"));
	itemMisileAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("MisileAmmo"));
	itemRailwaySpikesAmmo = registerItem(new SimpleItemsMO().setUnlocalizedName("RailwaySpikesAmmo"));
	//Guns
	item10mmPistol = registerItem(new ItemGun(item10mmAmmo).setUnlocalizedName("10mmPistol"));

}

public static Item registerItem(Item item) {
	GameRegistry.registerItem(item, item.getUnlocalizedName().substring(5));
	return item;
}

}

 

Unfortunately its still not registering the item10mmPistol.

  • Author

ItemGun class

package net.mineout.mod.items;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.mineout.mod.Main;
import net.mineout.mod.entity.projectiles.EntityBullet;
import static net.mineout.mod.items.ItemDecMO. *;

public class ItemGun extends Item {

private Item Ammo;

public ItemGun(Item x){
	this.Ammo = x;
}

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,EntityPlayer par3EntityPlayer) {

	if(par3EntityPlayer.capabilities.isCreativeMode||par3EntityPlayer.inventory.consumeInventoryItem(Ammo)) {

        par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
        if (!par2World.isRemote) {
        	
        	par2World.spawnEntityInWorld(new EntityBullet(par2World, par3EntityPlayer));
        	
        }
        
	}

    return par1ItemStack;
    
}

@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
	this.itemIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5));
}

}

Hi

 

May it's a silly question, but do you really call the init() method ?

 

And since you do have two classes, one for accessing and one for registering the item object, are you sure you got those references correctly?

 

Sincerely -pick

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

  • Author

There's no pink and black box like all the other un-textured stuff in the creative tab. I also cant use the give command to give it to myself.

G'Day

 

CreativeTabs its a good point: As of my understanding you cannot expect an item / block in a creative tab without set the creativetab (Weird sentence, sorry, you need to call 'setCreativeTab' somewhere arount registering).

 

Again: Do you call the ItemsMO.init() function?

 

Sincerely -pick

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

There's no pink and black box like all the other un-textured stuff in the creative tab. I also cant use the give command to give it to myself.

 

As mister pickaxe pointed out, is the method registerItems() in ItemsMO called? Put a println in there if you're not sure, and see if it prints something.

  • Author

Yeah I forgot the

 

this.setCreativeTab(Main.tabMineout);

 

The ItemsMO.init() was something i was missing, it goes in the pre Init section correct?

 

 

Yeah I forgot the

 

this.setCreativeTab(Main.tabMineout);

 

The ItemsMO.init() was something i was missing, it goes in the pre Init section correct?

 

Correct.

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.