I was making an item for a game im modding, but it cant seem to read the variable and perform its function. Yeah, it recompiles fine, but dosent work ingame

The functions that dont work ingame, are

-Printing A Chat Message To An Entity
-Setting Variable Timesshot to 0
-Damaging the item by 60 part

Pretty much all the ones below "if(timesshot ==45)"

As for the counting part or "Test Notes" part, once it reaches 45, nothing happens, and continues on to 46 and 47 and so on. It dosent reset

package net.minecraft.src;

import java.util.Random;
import java.util.*;

public class ItemPP901M extends Item
{
	int timesshot = 0;
	
    public ItemPP901M(int i)
    {
        super(i);
        maxStackSize = 1;
        setMaxDamage(60);
    }

    public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
    {
    	if(timesshot != 45);
    	{
			if(itemstack.getItemDamage() == 0)
				{
					if(entityplayer.inventory.consumeInventoryItem(mod_com.PP901MMagazine.shiftedIndex))
						{
							world.playSoundAtEntity(entityplayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
							if(!world.multiplayerWorld)
								{
								world.entityJoinedWorld(new EntityBulletPP901Friendly(world, entityplayer));
								entityplayer.addChatMessage("Test Notes: Times shot: " + timesshot);
								}
							timesshot++;
						}
                        itemstack.damageItem(1, entityplayer);
                } 
			    else
			    {	
                if(timesshot == 45);
            	{
            		if(entityplayer.inventory.consumeInventoryItem(mod_com.PP901MMagazine.shiftedIndex));
            			{
            				world.playSoundAtEntity(entityplayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
            				if(!world.multiplayerWorld)
    						entityplayer.addChatMessage("Test Notes: Damage 60 Now");
            					{
            						world.entityJoinedWorld(new EntityBulletPP901Friendly(world, entityplayer));
            						
            					}
            					itemstack.damageItem(60, entityplayer);

            			}
        				timesshot = 0;
            	}

    }
    	}
return itemstack;
    }
    
    public boolean isFull3D()
    {
        return true;
    }
        
        public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag)
    {
            if(itemstack.getItemDamage() != 0)
        {
            itemstack.damageItem(-1, (EntityLiving)entity);
        }
    }
}

Recommended Answers

All 6 Replies

if(timesshot != 45);
{
//...
}else{ 
     if(timesshot == 45);
     {
     //...
     }
}

try to remove the semicolons in your if statements

Now why make an "if(timesshot == 45)" statement when you already have an else statement (@ the "if(timesshot != 45)" statement) for that very purpose?

if(timesshot != 45);
{
//...
}else{ 
     if(timesshot == 45);
     {
     //...
     }
}

try to remove the semicolons in your if statements

Now why make an "if(timesshot == 45)" statement when you already have an else statement (@ the "if(timesshot != 45)" statement) for that very purpose?

Hmm thats odd, after completing these changes, when the variable reaches 45, it ceases to do anything at all, and becomes an useless object. I dont suspect its anything of the coding, as its the same as the top one, just with "timesshot = 0;". still, +1 to vote, thanks

when the variable reaches 45, it ceases to do anything at all

Please explain.
Try debugging your code by adding printlns to show where the execution flow is going and to show the values of variables as they are changed. The print out will show you if the code is doing anything and why it is doing what it is doing.

Please explain.
Try debugging your code by adding printlns to show where the execution flow is going and to show the values of variables as they are changed. The print out will show you if the code is doing anything and why it is doing what it is doing.

I tried that and the results are quite wild.

Without "if(timesshot = 45)" (which was not needed), it displayed a print of doing the first step of the function but did not continue with it, and it did it around 6 times, before 45, but with the code added, it displayed nothing at all. Plus, when it does reach 45, no prints are actually happen at all

did not continue with it

Was it supposed to continue? If it was, why didn't it continue? The printed out values of the variables should show you why it did not continue.

when it does reach 45, no prints are actually happen at all

Then you need to add more printlns to show what is happening.
If nothing is printing, then that code is not being executed.

Alright i managed to fix it (somehow), thanks for the help everything

+ 1 for anyone that helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.