Jump to content

Code a block to harvest blocks around it and store harvests maybe replant


DavidSullivan

Recommended Posts

Hi all. My next goal is to make a block that I can place in a field of crops.

It will periodically check the surrounding blocks for fully matured plants and harvest them.

It will collect the plants and the seed and also replant the soil.

 

I have no idea where to start here. I have a basic mod with working ore blocks and ingots.

I can use the ores to build recipes but once I have my custom AutoFarmer I don't know how to use timers or access surrounding blocks. Any tutorial suggestions or videos I should check out to help get started?

 

Also yes I have been googling the crap out of this topic for awhile to no avail.

 

Thanks

 

Link to comment
Share on other sites

since you're asking about automatic digger/drill/excavator/farmer, let me give you a piece of advice (even if you know it, it could be useful to others)...

 

there are right ways to do it and wrong ways to do it.

 

wrong ways... let's take gravel block for example (doesn't matter could have been something else)... one wrong thing to do is get a block instance from the world instance and ask the block "what do you drop?". now, when you read that, it doesn't sound wrong but it's wrong. the gravel block object would answer that it drops 1 gravel block and depending on a dice roll and the fortune level, zero or more flint items. but what if a player has a mod that replaces flint pieces with smaller flint chips as a drop? or a mod that adds copper pieces as a possible drop? or what if some mod wants to prevent breaking of blocks under some conditions? you are supposed to play nice with all of these cases.

 

right ways... one way to do it would be to invoke forge events (just as these calls are inserted into vanilla code) and if the event chain says that it's ok that you break a block, you take a list of items from it. another way would be to create a FakePlayer (yes, that's a thing) and tell it to break blocks at given coordinates, one by one. that way, you can give the FakePlayer an iron pickaxe if your machine has an iron drill, etc. and you get correct times for breaking block with whatever tool you gave him.

 

edit: to clarify, doesn't matter if it's a mining machine or a farming machine; same principle applies.

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.