Jump to content

Recommended Posts

Posted

I have a weapon in my mod that can switch modes, and it works fine in singleplayer.  But when I switch over to multiplayer, it says i switched modes, but the effect is always that of the first mode

 

My Item Class

 

  Reveal hidden contents

 

 

Plz help

 

-LazerMan47

Creator Of Weapons+ Mod & Sword Art Online HUD Mod

Posted

I can give you a starting tutorial with item NBT data.

 

All ItemStacks in a world can contain additional data called NBT data. You can write NBT data to an ItemStack like so:

 

public void storeIntegerInItemStackNBT(ItemStack itemStack, String tagKey, int number) {
    // If an ItemStack doesn't have NBT data associated with it, then the stackTagCompound (returns an NBTTagCompound object) field will be null.
    if (itemStack.stackTagCompound == null) {
        // NBTTagCompound is the object that stores an ItemStack's NBT data
        itemStack.setTagCompound(new NBTTagCompound());
    }
    // NBTTagCompound has many methods to store many data types, including bytes, byte arrays, shorts, integers, Strings, etc.
    // When storing values using NBTTagCompound, you will also need a key (String) to associate with the value. This is for calling the value later when you want to extract information from an NBTTagCompound object.
    itemStack.stackTagCompound.setInteger("Key", number);
}

 

You can read NBT data from an ItemStack like so:

 

public int readIntegerFromItemStackNBT(ItemStack itemStack, String tagKey) {
    if (itemStack.stackTagCompound == null) {
        itemStack.setTagTagCompound(new NBTTagCompound());
    }
    return itemStack.stackTagCompound.getInteger(tagKey);
}

 

That's the basics of ItemStack NBT data. You can also check out this: http://www.minecraftforum.net/topic/982336- tutorial for more information.

if (user.hasKnowledgeOfJava) {

    if (user.question.hasCode) {

        return interpetHelpfulResponse(user.getQuestion());

    } else {

        return "Could you post your code please?";

    }

} else {

    return "Learn some freaking Java!";

}

Posted

It seems to be letting me add and call tags, but it wont let me change ones i already created, is this possible?

 

My New Item Class:

 

  Reveal hidden contents

 

Creator Of Weapons+ Mod & Sword Art Online HUD Mod

Posted

I have removed them from my item class, and switched their references to tagCompounds.  It still doesnt seem to be working though :/

 

My New Item Code:

 

  Reveal hidden contents

 

Creator Of Weapons+ Mod & Sword Art Online HUD Mod

Posted
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if( par1ItemStack.stackTagCompound == null )
	par1ItemStack.setTagCompound( new NBTTagCompound( ) );
if(par3EntityPlayer.isSneaking())
{
                // Here's your problem. Check to see if the world is NOT remote. if (!world.isRemote) { code }
	if(par2World.isRemote)
	{ ...

if (user.hasKnowledgeOfJava) {

    if (user.question.hasCode) {

        return interpetHelpfulResponse(user.getQuestion());

    } else {

        return "Could you post your code please?";

    }

} else {

    return "Learn some freaking Java!";

}

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.