Jump to content




Making a peripheral (Questions)


  • You cannot reply to this topic
8 replies to this topic

#1 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 12 November 2012 - 11:46 AM

Hello again,

Now that I've finally managed to get ComputerCraft running from Eclipse, I am looking to create a peripheral just to try things out. For some reason peripheral.isPresent(side) just returns nil. Could someone look over this code and tell me what I'm doing wrong? I'm sure it's something stupid but I can't seem to figure this out.

BlockPeripheralBlock.java
Spoiler

TileEntityPeripheral.java
Spoiler

Peripheral.java
Spoiler

Eclipse is not giving me any errors.
Note: This is not intended for release (obviously). It is merely a test of the CC api and creating peripherals.

#2 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 12 November 2012 - 01:16 PM

Your tile entity is never loaded because minecraft can't derive it from the block. Add this method to the class BlockPeripheralBlock:
public TileEntity createNewTileEntity(World par1World)
{
  return new TileEntityPeripheral();
}


#3 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 12 November 2012 - 01:33 PM

View PostOrwell, on 12 November 2012 - 01:16 PM, said:

Your tile entity is never loaded because minecraft can't derive it from the block. Add this method to the class BlockPeripheralBlock:
public TileEntity createNewTileEntity(World par1World)
{
  return new TileEntityPeripheral();
}

Added to the code, but there was no effect. Methinks I just need to learn Java better before I start trying to write peripherals.

#4 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 12 November 2012 - 02:12 PM

Oh yea, you should try adding this as well to the BlockPeripheralBlock class:
public boolean hasTileEntity(int metadata)
{
	return true;
}

I never needed to do this though. Also, I always add the '@Override' annotation to those functions, maybe it matters?

#5 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 12 November 2012 - 02:57 PM

View PostOrwell, on 12 November 2012 - 02:12 PM, said:

Oh yea, you should try adding this as well to the BlockPeripheralBlock class:
public boolean hasTileEntity(int metadata)
{
	return true;
}

I never needed to do this though. Also, I always add the '@Override' annotation to those functions, maybe it matters?

Hmm still no success. I think I'm going to try starting over to see if I've done something wrong along the way.

Using an @Override on those functions doesn't work because the BlockPeripheralBlock class does not extend TileEntity. Do you mean I should add @Override to any functions that are in any extended classes?

#6 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 12 November 2012 - 03:19 PM

View PostChallenge.Accepted, on 12 November 2012 - 02:57 PM, said:

Using an @Override on those functions doesn't work because the BlockPeripheralBlock class does not extend TileEntity. Do you mean I should add @Override to any functions that are in any extended classes?

BlockPeripheral extends Block. So that's why. In theory I think you should add @Override to any function that 'overrides' a function from the class it extends (and any parent class higher in the hierarchy). So in your case it's practically every function (it gives an error when it isn't an existing function in the parent classes). Not all code I've seen does this this though, so I don't know about that. :P/>

#7 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 12 November 2012 - 03:34 PM

View PostOrwell, on 12 November 2012 - 03:19 PM, said:

View PostChallenge.Accepted, on 12 November 2012 - 02:57 PM, said:

Using an @Override on those functions doesn't work because the BlockPeripheralBlock class does not extend TileEntity. Do you mean I should add @Override to any functions that are in any extended classes?

BlockPeripheral extends Block. So that's why. In theory I think you should add @Override to any function that 'overrides' a function from the class it extends (and any parent class higher in the hierarchy). So in your case it's practically every function (it gives an error when it isn't an existing function in the parent classes). Not all code I've seen does this this though, so I don't know about that. :P/>

Yeah I'm not quite sure I understand what the whole deal is with @Override. Some people use it and some people don't so I'm not really sure what to think. Thanks for your help though :)/>

#8 faubiguy

  • Members
  • 213 posts

Posted 12 November 2012 - 04:03 PM

Try making it extend BlockContainer, instead of Block.

#9 sirdabalot

  • Members
  • 115 posts

Posted 16 November 2012 - 04:03 AM

View Postfaubiguy, on 12 November 2012 - 04:03 PM, said:

Try making it extend BlockContainer, instead of Block.

Absolutly spot on, fixed my probem. And I'm trying to make a peripheral identical to yours.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users