Hello, i have been creating my first mod and it contains an item called"magic home finder", i referenced the net.minecraft.item.ItemEnderEye class, so far it works okay but i seem to have 2 bugs that i can't seem to resolve, one is that my item flys to the global spawn point chunk, however it is expected to go to the user's spawn point "bed" and the second one is that the item is duplicated in minecraft " i can see it in the creative inventory twice".
Here's the ItemMagicHomeFinder class
package MyMod.items;
import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityEnderEye;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import MyMod.MyMod;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemMagicHomeFinder extends Item
{
public ItemMagicHomeFinder()
{
super();
this.setCreativeTab(CreativeTabs.tabMisc);
this.setTextureName("Magic_Home_Finder");
this.maxStackSize = 1;
}
@SideOnly(Side.CLIENT)
private IIcon[] icons;
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister)
{
icons = new IIcon[2];
for (int i = 0; i < icons.length; i++) {
icons[i] = par1IconRegister.registerIcon(MyMod.MODID + ":" + (this.getUnlocalizedName().substring(5)) + i);
}
}
public static final String names = "Magic Home Finder";
@Override
public String getUnlocalizedName(ItemStack par1ItemStack)
{
int i = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, 15);
return super.getUnlocalizedName() + "." + names;
}
@Override
public IIcon getIconFromDamage(int par1)
{
return icons[par1];
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SideOnly(Side.CLIENT)
@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
if (par3World.isRemote) {
return true;
}
return false;
}
/**
* Called whenever this item is equipped and the right mouse button is
* pressed. Args: itemStack, world, entityPlayer
*/
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if (!par2World.isRemote) {
ChunkCoordinates coordinates = par3EntityPlayer.getBedLocation(0);
if (coordinates != null) {
coordinates = par2World.getSpawnPoint();
EntityEnderEye entityendereye = new EntityEnderEye(par2World, par3EntityPlayer.posX, par3EntityPlayer.posY + 1.62D - (double) par3EntityPlayer.yOffset, par3EntityPlayer.posZ);
entityendereye.moveTowards((double) coordinates.posX + 0.5D, (int) coordinates.posY + 3, (double) coordinates.posZ + 0.5D);
par2World.spawnEntityInWorld(entityendereye);
par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
par2World.playAuxSFXAtEntity((EntityPlayer) null, 1002, (int) par3EntityPlayer.posX, (int) par3EntityPlayer.posY, (int) par3EntityPlayer.posZ, 0);
}
}
return par1ItemStack;
}
@Override
public void func_150895_a(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int x = 0; x < 2; x++) {
par3List.add(new ItemStack(this, 1, x));
}
System.out.println("\n" + "\n" + "\n" + "\n" + "ItemMagicHomeFinder done" + "\n" + "\n" + "\n" + "\n");
}
}
and here's the main class "MyMod"
package MyMod;
import net.minecraft.item.Item;
import MyMod.config.ConfigHandler;
import MyMod.items.ItemMagicHomeFinder;
import MyMod.items.ItemMagicMirror;
import MyMod.job.JobHandler;
import MyMod.proxies.CommonProxy;
import MyMod.tests.TestsHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = MyMod.MODID, name = MyMod.NAME, version = MyMod.VERSION)
public class MyMod
{
public static final String MODID = "MyMod";
public static final String NAME = "Example";
public static final String VERSION = "1.0";
@Instance(MyMod.MODID)
public static MyMod instance;
private static Item ItemMagicMirror = new ItemMagicMirror();
private static Item ItemMagicHomeFinder = new ItemMagicHomeFinder();
public static Item JobHandler = new JobHandler();
@SidedProxy(clientSide = "MyMod.proxies.ClientProxy", serverSide = "MyMod.proxies.CommonProxy")
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
// early things like registering items, blocks sounds ids , create
// config
ConfigHandler.init(event.getSuggestedConfigurationFile());
System.out.println(ConfigHandler.SOME_TEXT_VALUE);
proxy.initSounds();
proxy.initRenderers();
//ItemMagicMirror = new ItemMagicMirror().setUnlocalizedName("Magical");
//GameRegistry.registerItem(ItemMagicMirror, "Magic Mirror");
ItemMagicHomeFinder = new ItemMagicHomeFinder().setUnlocalizedName("Magical");
GameRegistry.registerItem(ItemMagicHomeFinder, "Magic Home Finder");
proxy.registerRenderThings();
//JobHandler = new JobHandler();
}
@EventHandler
public void load(FMLInitializationEvent event)
{
proxy.registerRenderThings();
//JobHandler = new JobHandler();
//new JobHandler();
// MyMod.JobHandler.toast();
// JobHandler.toast() teast = new JobHadler.toast();
System.out.println("\n" + "\n" + "\n" + "\n" + "public void load(FMLInitializationEvent event) done" + "\n" + "\n" + "\n" + "\n");
}
@EventHandler
public void modsLoaded(FMLPostInitializationEvent event)
{
proxy.registerRenderThings();
//JobHandler = new JobHandler();
//new JobHandler();
// MyMod.JobHandler.toast();
// JobHandler.toast() teast = new JobHadler.toast();
System.out.println("\n" + "\n" + "\n" + "\n" + "public void load(FMLPostInitializationEvent event) done" + "\n" + "\n" + "\n" + "\n");
// TestsHandler tst = new TestsHandler
TestsHandler.main(null);
}
}
I am really new to modding, i referenced thishttp://www.wuppy29.com/minecraft/modding-tutorials/wuppys-minecraft-forge-modding-tutorials-for-1-7-updating-1-6-to-1-7-part-4-items/#comment-3221 link to create my items for 1.7.2 and inserted the code that lets an item do something on right click above that, it resulted on both items getting the same functionality which i didn't want, and so i made 2 classes for both this "Magic Home Finder" and another item which is still WIP "Magic Mirror".
EDIT: for those who misunderstood me, my item flys towards the chunk where the player spawns on world creation instead of the one that contains the bed (yes, i did sleep on the bed).
Feel free to let me know if anything else i am doing is wrong
Thanks in advance