Jump to content

Recommended Posts

Posted

I have had a very busy month and i have gotten quite rusty in this past month.

However we are near christmass and my school's homeworks are getting lighter. Today i opened up Eclipse and started to catch up to my old project. Apparently i would have wanted to make dispensers able to plant seeds. So instead of dispensing the seeds as items, i want the dispenser plant these seeds if the block on front is farmland. I haven't quite started anything on this and before i do i wanted to make sure that this can be done easily. Is there any event that handles item dispensed? Maybe through that event i might be able to achieve something. If there is can you please tell me the event name. If there is not. How can i edit the dispenser class? I don't remember on working in this type of thing before so any help would be appreciated.

Thank you for your time.

Posted

1) you can't edit bar classes

2) you don't need to, you may need to create a custom dispenser behavior and add it to the dictionary.

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.

Posted

Now, adding the custom behavior wasn't hard at all. I tested and it worked. It does set the Wheat (The first type of seeds i tried). But problems started soon when i tried to add an if statement to check if the block in front of dispenser is farmland. I am so damn confused with this block states thing that were added on 1.8

 

I tried using this code:

 

 

if(worldIn.getBlockState(pos) == Blocks.farmland.getDefaultState()){

        worldIn.setBlockState(pos, Blocks.wheat.getDefaultState());

        }

 

 

It doesn't work. It wont even place the seeds.

However if i remove the if statement, it will place the seeds even if the block in front is obsidian. (It doesn't care what block is there). Now i think that i know what is happening and i don't know at the same time. I refused to work with 1.8 before and this was one of the reasons. I don't like this blockstates thing.

 

What i am guessing it happens is that the farmland should have different states. I am only checking for the default state in which the farmland may or not be. Of course since there is not a checker for the wheat block the dispenser will always try to place the wheat block. So it wastes seeds and also resets the crop state from full-grown to ungrown state. How can i make this block-check thing easily. I am sorry for noobish questions but i really don't get these block states.

 

It is actually very frustrating because it seems like is such a simple thing to do and i can't get around it :/

Posted

try

worldIn.getBlockState(pos).getBlock() == Blocks.farmland

And yes farmland has states for the moist. Comparing just the states is a bad idea in this case

I think its my java of the variables.

Posted

Is it possible to compare blocks with blockstates? I thought you couldn't do that. Anyway i will try this when i get home

 

Edit: Sorry i missed the .getBlock() part. I was on my phone. It is now working, thanks for help

Posted

Is it possible to compare blocks with blockstates?

 

blocks will never equal blockstates, so you're going to have to rephrase your question.  What is it that you are trying to do?

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.

Posted

As mentioned above. I missed a part of the code he wrote because i was on my phone.

That is why i asked that question, because it doesn't make sense to compare a block with a blockstate. However when i got home i re-checked the code and saw the .getBlock in:

worldIn.getBlockState(pos).getBlock() == Blocks.farmland

Everything made sense after i notice this.

I managed to get it working and the dispenser is now planting the seeds the way i wanted it to.

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.