xXWitherBossXx Posted June 11, 2017 Posted June 11, 2017 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. Quote
Draco18s Posted June 11, 2017 Posted June 11, 2017 Why do you need a TE? I could do this with blocks, nothing but blocks, and a custom Interface. Quote 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.
xXWitherBossXx Posted June 12, 2017 Author Posted June 12, 2017 Ok, can you give me an idea of how I could do that? I was thinking that I needed a te because the lasers were going to act as a power transfer system Quote
Draco18s Posted June 12, 2017 Posted June 12, 2017 If you're transferring power then yes, you'd need a TE to store the power in. Quote 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.
xXWitherBossXx Posted June 12, 2017 Author Posted June 12, 2017 Ok, thanks! Any idea on what to use to actually send data between the tile entities? Storing the power and creating the power is fine. I'm just confused on transporting the power. Any clarification? Quote
Alpvax Posted June 12, 2017 Posted June 12, 2017 You need to do a raytrace along the line of your laser and find the block that it hits. Quote
xXWitherBossXx Posted June 12, 2017 Author Posted June 12, 2017 I already know how to get the block that I am aiming for. I just don't know how to tell the tile entity that it is being hit Quote
Draco18s Posted June 12, 2017 Posted June 12, 2017 world.getTileEntity(pos)? Quote 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.
xXWitherBossXx Posted June 13, 2017 Author Posted June 13, 2017 Any ideas on how to send a peice of data to the tile entity from another tile entity? It would probably be a couple variables. Quote
theDataSmith Posted June 13, 2017 Posted June 13, 2017 (edited) 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 June 13, 2017 by theDataSmith Quote
xXWitherBossXx Posted June 13, 2017 Author Posted June 13, 2017 Thanks. I will have multiple tile entities, how could I use an interface to accomplish this? Quote
Draco18s Posted June 13, 2017 Posted June 13, 2017 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. Quote 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.
theDataSmith Posted June 13, 2017 Posted June 13, 2017 This is a basic java question. There are plenty of resources online that can help you. I recommend starting by learning inheritance if you haven't already, then specifically interfaces. Quote
Recommended Posts
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.