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

[1.7.2]Item changing in inventory help!


CraigTheMailman
 Share

Recommended Posts

I am trying to make a sigil using an onItemRightClick Method,

but when i right click with the item nothing happens,

can anyone help me?

 

Main mod class:

 

package net.craig.cm;

 

import net.craig.cm.blocks.Enhancer;

import net.craig.cm.blocks.MagicalBlock;

import net.craig.cm.event.ModdedEventHandler;

import net.craig.cm.handler.FuelHandler;

import net.craig.cm.handler.GuiHandler;

import net.craig.cm.help.Register;

import net.craig.cm.items.AbilityWand;

import net.craig.cm.items.EnhanceDust;

import net.craig.cm.items.EnhancedSilk;

import net.craig.cm.items.MagicProp;

import net.craig.cm.items.UselessWand;

import net.craig.cm.items.WitchesEnhancer;

import net.craig.cm.proxy.CommonProxy;

import net.craig.cm.sigils.SigilGiarc;

import net.craig.cm.tileentity.TileEntityEnhancer;

import net.craig.cm.worldgen.WorldGen;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

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 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.network.NetworkRegistry;

import cpw.mods.fml.common.registry.GameRegistry;

 

@Mod(name = "Craig's Magic", modid = Cm.modid, version = Cm.version)

public class Cm {

 

public static final String modid = "craigsmagic";

public static final String version = "Alpha 1.7.2-v0.1";

 

WorldGen eventWorldGen = new WorldGen();

 

@Instance(modid)

public static Cm instance;

 

@SidedProxy(clientSide = "net.craig.cm.proxy.ClientProxy",

serverSide = "net.craig.cm.proxy.CommonProxy")

public static CommonProxy proxy;

 

//CreativeTab

public static CreativeTabs tabMagical;

 

//Items

public static Item itemUselessWand;

public static Item itemEnhanceDust;

public static Item itemAbilityWand;

public static Item itemMagicProp;

public static Item itemWitchesEnhancer;

public static Item itemEnhancedSilk;

 

//Sigils

public static Item sigilGiarcOn;

public static Item sigilGiarcOff;

 

//Blocks

public static Block blockEnhancerOn;

public static Block blockEnhancerOff;

public static Block blockMagicBlock;

 

public static final int guiIDEnhancer = 1;

 

@EventHandler

public void PreInit(FMLPreInitializationEvent preEvent) {

tabMagical = new CreativeTabs("MagicalTab") {

@Override

public Item getTabIconItem() {

return itemEnhanceDust;

}

};

 

itemUselessWand = new UselessWand().setUnlocalizedName("UselessWand");

itemEnhanceDust = new EnhanceDust().setUnlocalizedName("EnhanceDust");

itemAbilityWand = new AbilityWand().setUnlocalizedName("AbliltyWand");

itemMagicProp = new MagicProp().setUnlocalizedName("MagicProp");

itemWitchesEnhancer = new WitchesEnhancer().setUnlocalizedName("WitchesEnhancer");

itemEnhancedSilk = new EnhancedSilk().setUnlocalizedName("EnhancedSilk");

sigilGiarcOn = new SigilGiarc(true).setUnlocalizedName("Giarc_on");

sigilGiarcOff = new SigilGiarc(false).setUnlocalizedName("Giarc_off").setCreativeTab(tabMagical);

 

blockEnhancerOn = new Enhancer(true).setBlockName("Enhancer").setLightLevel(1F).setHardness(5F).setResistance(7F);

blockEnhancerOff = new Enhancer(false).setBlockName("Enhancer_off").setCreativeTab(tabMagical).setHardness(5F).setResistance(7F);

blockMagicBlock = new MagicalBlock(Material.iron).setBlockName("MagicBlock");

 

Register.registerItem(itemUselessWand);

Register.registerItem(itemEnhanceDust);

Register.registerItem(itemAbilityWand);

Register.registerItem(itemMagicProp);

Register.registerItem(itemWitchesEnhancer);

Register.registerItem(itemEnhancedSilk);

Register.registerItem(sigilGiarcOn);

Register.registerItem(sigilGiarcOff);

 

Register.registerBlock(blockEnhancerOn);

Register.registerBlock(blockEnhancerOff);

Register.registerBlock(blockMagicBlock);

 

GameRegistry.registerWorldGenerator(eventWorldGen, 0);

 

proxy.registerRenderThings();

 

}

 

@EventHandler

public void Init(FMLInitializationEvent event) {

 

NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());

 

MinecraftForge.EVENT_BUS.register(new ModdedEventHandler());

 

GameRegistry.registerFuelHandler(new FuelHandler());

 

GameRegistry.registerTileEntity(TileEntityEnhancer.class, "Enhancer");

 

GameRegistry.addShapedRecipe(new ItemStack(this.itemEnhanceDust, 1), new Object [] {

"XXX",

"XKX",

"XXX",

'X',Items.blaze_powder,

'K',itemWitchesEnhancer

});

 

GameRegistry.addShapedRecipe(new ItemStack(itemEnhancedSilk, 1), new Object [] {

"XXX",

"XYX",

"XXX",

'X', Blocks.wool,

'Y', itemEnhanceDust

});

 

GameRegistry.addShapedRecipe(new ItemStack(blockEnhancerOff, 1), new Object [] {

"XXX",

"XYX",

"XXX",

'X', itemEnhanceDust,

'Y', Blocks.furnace

});

 

}

 

@EventHandler

public void PostInit(FMLPostInitializationEvent postEvent) {

 

}

 

}

 

 

 

Item Class:

 

package net.craig.cm.sigils;

 

import net.craig.cm.Cm;

import net.minecraft.client.gui.inventory.GuiContainer;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class SigilGiarc extends Item {

 

public final boolean isActive;

 

public SigilGiarc(boolean isActive) {

super();

 

this.isActive = isActive;

 

this.setMaxDamage(1);

}

 

@SideOnly(Side.CLIENT)

public void registerIcons(IIconRegister iconRegister) {

this.itemIcon = iconRegister.registerIcon(Cm.modid + ":" + (this.isActive ? "Giarc_on" : "Giarc_off"));

}

 

@Override

public ItemStack onItemRightClick(ItemStack stack, World worldObj, EntityPlayer player)

    {

super.onItemRightClick(stack, worldObj, player);

 

ItemStack sigili = new ItemStack(Cm.sigilGiarcOff);

ItemStack sigilon = new ItemStack(Cm.sigilGiarcOn);

 

ItemStack sigil = player.inventory.getStackInSlot(1);

ItemStack sigil2 = player.inventory.getStackInSlot(2);

ItemStack sigil3 = player.inventory.getStackInSlot(3 );

ItemStack sigil4 = player.inventory.getStackInSlot(4);

ItemStack sigil5 = player.inventory.getStackInSlot(5);

ItemStack sigil6 = player.inventory.getStackInSlot(6);

ItemStack sigil7 = player.inventory.getStackInSlot(7);

ItemStack sigil8 = player.inventory.getStackInSlot(8 );

ItemStack sigil9 = player.inventory.getStackInSlot(9);

 

if(sigil == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(sigil2 == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(sigil3 == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(sigil4 == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(sigil5 == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(sigil6 == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(sigil7 == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(sigil8 == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(sigil9 == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(sigil == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

if(sigil2 == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

if(sigil3 == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

if(sigil4 == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

if(sigil5 == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

if(sigil6 == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

if(sigil7 == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

if(sigil8 == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

if(sigil9 == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

        return stack;

    }

}

 

 

Link to comment
Share on other sites

I Even tried changing my code up

 

Item Code:

 

package net.craig.cm.sigils;

 

import net.craig.cm.Cm;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class SigilGiarc extends Item {

 

public final boolean isActive;

 

public SigilGiarc(boolean isActive) {

super();

 

this.isActive = isActive;

 

this.setMaxDamage(1);

}

 

@SideOnly(Side.CLIENT)

public void registerIcons(IIconRegister iconRegister) {

this.itemIcon = iconRegister.registerIcon(Cm.modid + ":" + (this.isActive ? "Giarc_on" : "Giarc_off"));

}

 

@Override

public ItemStack onItemRightClick(ItemStack stack, World worldObj, EntityPlayer player)

    {

super.onItemRightClick(stack, worldObj, player);

 

ItemStack sigili = new ItemStack(Cm.sigilGiarcOff);

ItemStack sigilon = new ItemStack(Cm.sigilGiarcOn);

 

ItemStack slot = player.inventory.getCurrentItem();

 

ItemStack sigil = player.inventory.getStackInSlot(1);

ItemStack sigil2 = player.inventory.getStackInSlot(2);

ItemStack sigil3 = player.inventory.getStackInSlot(3);

ItemStack sigil4 = player.inventory.getStackInSlot(4);

ItemStack sigil5 = player.inventory.getStackInSlot(5);

ItemStack sigil6 = player.inventory.getStackInSlot(6);

ItemStack sigil7 = player.inventory.getStackInSlot(7);

ItemStack sigil8 = player.inventory.getStackInSlot(8 );

ItemStack sigil9 = player.inventory.getStackInSlot(9);

 

if(slot == sigili) {

player.setItemInUse(sigilon, 1);

player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

}

 

if(slot == sigilon) {

player.setItemInUse(sigili, 1);

player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

}

 

        return stack;

    }

 

}

 

 

Link to comment
Share on other sites

Hmm......... notice that "stack" that is given to you by the method? that is the itemstack that the player right clicked so you can just use stack.getItem().equals(new ItemStack(Cm.sigilGiarcOff))

 

Or better yet get rid of sigilGiarcOff and sigilGiarcOn and use the damage value to determine if it is on or off.

 

Edit: Disregard the first part of this post i was confused because you are using 3 separate items when you only need 1.

 

Edit2: Oh and the reason its not doing anything as it is is because the item you are using is SigilGiarc but the two items you are checking for are sigilGiarcOff and sigilGiarcOn.

 

Edit3: And one last thing the players hotbar slots are 0-8 not 1-9.

I am the author of Draconic Evolution

Link to comment
Share on other sites

Hmm......... notice that "stack" that is given to you by the method? that is the itemstack that the player right clicked so you can just use stack.getItem().equals(new ItemStack(Cm.sigilGiarcOff))

 

Or better yet get rid of sigilGiarcOff and sigilGiarcOn and use the damage value to determine if it is on or off.

 

Edit: Disregard the first part of this post i was confused because you are using 3 separate items when you only need 1.

 

Edit2: Oh and the reason its not doing anything as it is is because the item you are using is SigilGiarc but the two items you are checking for are sigilGiarcOff and sigilGiarcOn.

 

Edit3: And one last thing the players hotbar slots are 0-8 not 1-9.

 

Uhh i am using two items, using the same concept as a furnace,

replacing the items instead of a block,

and both items use the same class

I'm changing my code right now...

Link to comment
Share on other sites

Still nothing,

it's like the code isn't called,

no output from the consle...

 

new code:

 

package net.craig.cm.sigil;

 

import net.craig.cm.Cm;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class SigilGiarc extends Item {

 

public boolean isActive;

 

public SigilGiarc(boolean isActive) {

super();

 

this.isActive = isActive;

 

setMaxStackSize(1);

}

 

@SideOnly(Side.CLIENT)

  public void registerIcons(IIconRegister iconRegister) {

      this.itemIcon = iconRegister.registerIcon(Cm.modid + ":" + (this.isActive ? "Giarc_on" : "Giarc_off"));

  }

 

  @Override

  public ItemStack onItemRightClick(ItemStack stack, World worldObj, EntityPlayer player)

    {

      super.onItemRightClick(stack, worldObj, player);

     

      ItemStack sigili = new ItemStack(Cm.sigilGiarcOff);

      ItemStack sigilon = new ItemStack(Cm.sigilGiarcOn);

     

      if(stack.getItem().equals(Cm.sigilGiarcOff)) {

        player.setItemInUse(sigilon, 1);

        player.inventory.clearInventory(Cm.sigilGiarcOff, 1);

      }

     

      if(stack.getItem().equals(Cm.sigilGiarcOn)) {

        player.setItemInUse(sigili, 1);

        player.inventory.clearInventory(Cm.sigilGiarcOn, 1);

      }

     

        return stack;

    }

 

}

 

 

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.