Jump to content

Recommended Posts

Posted (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 by The_G0dPiXeL
Posted

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.  

Posted
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 

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

Posted

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.

Posted
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

Posted
8 minutes ago, Jay Avery said:

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.

Posted (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 by The_G0dPiXeL
Posted

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.

 

Posted (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 by The_G0dPiXeL
Posted
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

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.