954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help closing this class

im having trouble closing this class, ive been trying for 2 hours

Its a huge collection of ifs
package net.minecraft.src;

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

public class ItemTestItem extends Item
{
public int TimesShot;

public ItemTestItem(int i)
{
super(i);
maxStackSize = 1;
setMaxDamage(50);
}

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

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer, TimesShot timesshot)
{
if(timesshot == 5)
{
if(itemstack.getItemDamage() == 0)
{
if(entityplayer.inventory.consumeInventoryItem(mod_WIP.LAWRocket.shiftedIndex))
{
world.playSoundAtEntity(entityplayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
if(!world.multiplayerWorld)
{
world.entityJoinedWorld(new EntityRocketLAW(world, entityplayer));
itemstack.damageItem(50, entityplayer);
timesshot = 0;
return itemstack;
} else {
if(itemstack.getItemDamage() == 0)
{
if(entityplayer.inventory.consumeInventoryItem(mod_WIP.LAWRocket.shiftedIndex))
{
world.playSoundAtEntity(entityplayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
if(!world.multiplayerWorld)
{
world.entityJoinedWorld(new EntityRocketLAW(world, entityplayer));
++timesshot;
{
itemstack.damageItem(6, entityplayer);
return itemstack;
}
}
}

The error is a end of file parsing

help please

Blahthing
Newbie Poster
9 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

re-check every { and }

for instance: why do you open a bracket on the next line

if(!world.multiplayerWorld)
        {
        world.entityJoinedWorld(new EntityRocketLAW(world, entityplayer));
	++timesshot;
	<strong>{</strong>
	itemstack.damageItem(6, entityplayer);
	return itemstack;


I think you'll find you didn't close all your blocks that you open with a '{'.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

Use Ctrl+Shift+F when you work in Eclipse, this will format your code. It's very useful when you don't know where you missed a bracket. The formatter will space out the code in the wrong way when you missed one, so you can see where you made an error!

hiddepolen
Posting Whiz in Training
297 posts since Oct 2010
Reputation Points: 82
Solved Threads: 35
 
Use Ctrl+Shift+F when you work in Eclipse,


for all we know, he's writing his code in Notepad ..

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

Maybe, that's why I said 'if'.

I always encourage people to start programming with a good IDE (no, let's not start a discussion which is the best), to avoid these kind of mistakes.

hiddepolen
Posting Whiz in Training
297 posts since Oct 2010
Reputation Points: 82
Solved Threads: 35
 

Maybe, that's why I said 'if'.

I always encourage people to start programming with a good IDE (no, let's not start a discussion which is the best), to avoid these kind of mistakes.

just re-read your previous post. I don't see an 'if' there, just a 'when' what is not entirely a synonym for if.

there is no 'Best' IDE, so discussing which is the best is indeed very pointless, but when starting to develop, I think it's better to use a simple text-editor. an IDE is capable of doing a lot of the work for you, which is one of the reasons why it's best to start with an IDE when you already have the hang of: writing small applications, working with packages, compiling and running from the command line, ..

which is why I said, that, for all we know, he(/she) is using notepad (or a similar editor). Indenting the code, especially when the class is as small as the one posted above, can be quite easily done manually, and when doing so, he'll find the mistakes as soon as he tries to indent a non-existing bracket.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

Oh! I'm sorry, I thought I said 'if'. (I'm Dutch, so my English is not really good.)

Yes, if you indent your code manually, you'll find out eventually. I still think starting programmers should learn to code with IDE's, because they'll learn a lot faster, and never forget little stupid problems you would make in Notepad.

hiddepolen
Posting Whiz in Training
297 posts since Oct 2010
Reputation Points: 82
Solved Threads: 35
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You