The_G0dPiXeL Posted June 16, 2017 Posted June 16, 2017 (edited) What I am trying to do is create a block that does AND gate logic, which has 2 sides for input and 1 side for output. I have no code except the block registration because I have literally no clue where to start, the API for redstone blocks is terrible and I tried to look at the code for the Observer block and that gave me a little bit of information but I have no idea how to modify that code to my liking as I have no idea what any of those functions do. I've looked everywhere for documentation but alas I could not find a single tutorial, so I had to turn to the forums. I'm wondering if anybody has a modding library or some code that I could use make this. I'm sorry if this seems like I'm asking people to do my homework for me but I did hours upon hours of research and trial and error, yet I can't make it work, so I need help from the community. Edited June 16, 2017 by The_G0dPiXeL Quote
draganz Posted June 16, 2017 Posted June 16, 2017 Mmm, mind you I have never done any redstone before, but from ten minutes of looking at Minecraft code, you just (and others please correct me if I am wrong) need to create a propertyEnum, set all of the property states and meta, have canProvidePower set to return true, then (look at how Minecraft discriminates between what "strong" and "weak" is, I choose weak, cause that might be more of what you want, if you want to have behavior like a comparator, set you getStrongPower to your weak power) have getWeakPower return an int value (between and inclusive between 0 and 15) based on the property state. For you case, specifically, you should probably also want to override onNeighborChanged so to detect when power is being provided. Beyond that, everything is self-explanatory, just look at how Minecraft does it, tends to be the best way. Quote
The_G0dPiXeL Posted June 16, 2017 Author Posted June 16, 2017 (edited) deleted Edited June 16, 2017 by The_G0dPiXeL Quote
The_G0dPiXeL Posted June 16, 2017 Author Posted June 16, 2017 (edited) Alright, so I did some more testing and stuff and I got the output working but I still don't know how to get inputs from both sides https://pastebin.com/WXSYfmpc Edited June 16, 2017 by The_G0dPiXeL Quote
lukas2005 Posted June 16, 2017 Posted June 16, 2017 1 minute ago, The_G0dPiXeL said: Alright, so I did some more testing and stuff and I got the output working but I still don't know how to get inputs from both sides https://pastebin.com/WXSYfmpc from this point, it should be pretty easy all you need to do is chek if on a left and right sides there is power and if yes then give output PS I don't think you should use a variable for this because it is going to be shared by all the ANDGate blocks in Mc Quote
The_G0dPiXeL Posted June 16, 2017 Author Posted June 16, 2017 51 minutes ago, lukas2005 said: from this point, it should be pretty easy all you need to do is chek if on a left and right sides there is power and if yes then give output PS I don't think you should use a variable for this because it is going to be shared by all the ANDGate blocks in Mc Well, I don't see a function that gives an EnumFacing object that also watches neighbors, so can you give me some ideas. Also how come I can't use a boolean, that's kinda stupid, I'll make it a PropertyBool if that is the case. Quote
Jay Avery Posted June 16, 2017 Posted June 16, 2017 You can NEVER use instance fields to store information about individual blocks (or items), because they are singletons. There is only one instance of that block in the entire game, so if you change that isOn field, it will effect every block of that type. That's what blockstates are for. If your block is supposed to face a specific direction and behave accordingly (like a comparator, repeater, observer, or etc), then you will also need a facing property in your blockstate. Quote
The_G0dPiXeL Posted June 16, 2017 Author Posted June 16, 2017 2 minutes ago, Jay Avery said: You can NEVER use instance fields to store information about individual blocks (or items), because they are singletons. There is only one instance of that block in the entire game, so if you change that isOn field, it will effect every block of that type. That's what blockstates are for. If your block is supposed to face a specific direction and behave accordingly (like a comparator, repeater, observer, or etc), then you will also need a facing property in your blockstate. I tried using a PropertyBool but it's not working https://pastebin.com/u0tK9BVk Quote
Jay Avery Posted June 16, 2017 Posted June 16, 2017 Quote it's not working Be more specific, no-one here is looking at your workspace or reading your mind. Quote
The_G0dPiXeL Posted June 16, 2017 Author Posted June 16, 2017 2 minutes ago, Jay Avery said: Be more specific, no-one here is looking at your workspace or reading your mind. https://pastebin.com/wEnmaiZB Quote
Jay Avery Posted June 16, 2017 Posted June 16, 2017 You need to override createBlockState in your block class. Read the page I linked you, this is explained in there. Quote
The_G0dPiXeL Posted June 16, 2017 Author Posted June 16, 2017 8 minutes ago, Jay Avery said: You need to override createBlockState in your block class. Read the page I linked you, this is explained in there. Ok done, but now I'm getting this Quote
The_G0dPiXeL Posted June 16, 2017 Author Posted June 16, 2017 8 minutes ago, Jay Avery said: Read the page I linked you. Oh sorry, I only read the beginning of the page which was createBlockState. After I added in those other functions Forge finally initializes, I got a ModelLoader exception but I fixed that. This is the current state of my code, it doesn't give any errors except the usual yggdrasil error, but it doesn't have the functionality I want. Quote
Jay Avery Posted June 16, 2017 Posted June 16, 2017 What exact functionality do you want, and what isn't happening? Quote
The_G0dPiXeL Posted June 16, 2017 Author Posted June 16, 2017 (edited) Well as you can tell from the name of the block, it's an AND logic gate in block form, I want it to take inputs from 2 sides and output out the other when both inputs are on. It's not doing anything Edited June 16, 2017 by The_G0dPiXeL Quote
Jay Avery Posted June 16, 2017 Posted June 16, 2017 Do you remember when I said this? 56 minutes ago, Jay Avery said: If your block is supposed to face a specific direction and behave accordingly (like a comparator, repeater, observer, or etc), then you will also need a facing property in your blockstate. Quote
The_G0dPiXeL Posted June 16, 2017 Author Posted June 16, 2017 (edited) 1 hour ago, Jay Avery said: Do you remember when I said this? I tend to skim over things from time to time, sorry. I made the block extend BlockDirectional and added a println statement in each function, and I found that my code doesn't even execute onNeighborChange, do you know why this is? Edited June 16, 2017 by The_G0dPiXeL Quote
lukas2005 Posted June 23, 2017 Posted June 23, 2017 On 16.06.2017 at 10:49 PM, The_G0dPiXeL said: I tend to skim over things from time to time, sorry. I made the block extend BlockDirectional it shloud extend BlockHorizontal Quote
lukas2005 Posted June 23, 2017 Posted June 23, 2017 I think that GitHub repo would b best but if you can't make it then use paste bin or code tags here on forums 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.