Jump to content

Data from one block to another


xXWitherBossXx

Recommended Posts

Ok. I am making a mod about lasers. I need a block to know when it gets hit by a laser. Obviously, I can't just check if a line is rendering through a block, so I was thinking that I could use tile entities and send data between them. Is this the right way of going about this? And how could I do it? 

 

The system would be something like this: 

Block A ———gl line——— Block B

Block A sends data to Block B

Block B realizes it has a lazer on it

Yay we're done here. 

Link to comment
Share on other sites

Why do you need a TE? I could do this with blocks, nothing but blocks, and a custom Interface.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

If you're transferring power then yes, you'd need a TE to store the power in.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

world.getTileEntity(pos)?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Give your TileEntity a method.

public class MyTileEntity extends TileEntity
{
  public void sendData(int data)
  {
    // Do something with data.
  }
}

 

Assuming you have the world and position of your TileEntity, you can cast it to your custom class and call the method.

TileEntity te = world.getTileEntity(pos);
if(te instanceof MyTileEntity)
{
  MyTileEntity myTE = (MyTileEntity) te;
  myTE.sendData(12);
}

 

If you're going to have multiple TileEntity classes that need to receive data in a similar way, I recommend making an interface.

Edited by theDataSmith
Link to comment
Share on other sites

Multiple instances or multiple types?

Am interface is just an object which says "this method exists" and then every class that inherits that interface MUST provide an implementation. 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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
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.