Hi everyone! This is my first contribution to the mod, and for it I present you the new block Minecolonies has to offer: the Composter Barrel. This block will bring the colony an extra way to deal with excess items and get something in exchange: the Compost item, a new item that acts like vanilla Bone Meal.
What's new:
For the most part, Colonies use to produce some excess of some items, like seeds, saplings, rotten flesh, etc. So we wanted to bring some use for those full chests of leftover bio-material. So here comes the Barrel Block, wich will allow you to store inside of it 64 items, and after 2 days in average will give you 6 Compost items. Some items count as 2 for the composter, to give them more value at the time u decide to spend them making compost.
For now the block is on its own to be used by the player, but we are planing on adding a worker to automate it. For now the block it's here to be tested by players and adjusted to fit in the gameplay.
First of all, you will need to craft the block. For that you will need 6 wooden planks, 1 block of dirt, 1 iron ingot and a building tool:
Next you need to find a spot to place it. Keep in mind it cant be placed on air or another barrel.
As you click on the block with a valid item on your hand, it will take the maximum number of items it can to fill himself up. So, if you have 64 wheat seeds and it is empty, it will take the whole stack, but if its half filled it will take 32 of your 64 seeds.
The Barrel has 8 different states showing how filled it is, and if it's currently working or ready to be harvested:
When the Barrel is ready to be harvested it will start to emit particles, and when the player right clicks it it will add to his inventory 6 Compost items.
The compost item can't be crafted, and its only obtainable through the composting process. It works exactly like the Bone Meal, but it can't be used as a dye. Just right click the crops with the item in the hand to use it.
Also the items that the composter admits as valid can be adjusted from the mod settings, under gameplay "listOfCompostableItems", where you can simply add or remove the IDs of the items or their OreDictionary tag, to maximize mod compatibilities. This configuration on multiplayer is set by the server owner and will override client cofigurations.
What we did:
First of all we created the BarrelBlock class. To simplify, I'm only adding screenshots of the interesting code.
For the sake of a fluent explanation, I will be going over the classes that are used by the block in first place.
The first of those classes will BarrelType, a class to manage the metadata of the block and its different states. This are the different states:
The second class the Block will be using is its TileEntity, TileEntityBarrel:
We have made it extend ITickable so Minecraft calls automatically its update method.
This are its variables, wich we will be using in the future:
The update method that will be called by Minecraft randomly calls the function that will make the compost process advance:
This method will check if the barrel is composting. If it has finished composting, it spawns the particles from the server side:
If the Barrel is composting, it calls doBarrelCompostTick, wich will increase the timer, and check if it went over the end of the timer. If it did, it changes the TileEntity variables so it changes its state:
Finally, when the player interacts with the block, it will call useBarrel from the TileEntity:
This method will check if the Barrel has finished composting. If so, it adds the Compost items to the player's inventory, and changes the barrel state to empty. If not, it checks if the player is holding a valid item. If the barrel is full, it will notify the player with a chat message. Finally, if all the conditions are met, I consumes the needed items.
This method checks if the item being hold by the player is on the list or if it has a tag also contained in the list:
Here comes the complicated part, so buckle up:
First we need to know how many items is the player holding, so for that we assign a factor to the item deppending on what it is (as some of them count as double). Then we get the count of the stack and multiply by the factor. We have now how many items is holding the player.
Now we need to know how many does the barrel need. For that we substract what the Barrel has to the max items it can hold. Now that we have both, we need to calculate the minimum of those 2, as it will be the maximum items we can take from the player. Lastly we remove that number of items from the player's stack, and add them to the items the Barrel contains.
Now we need a way to tell Minecraft that it should update this block. For that we used this method:
The rest is just overriding the TileEntity methods for networking with the correct values, and it should work.
Finally, the BarrelBlock:
It extends from ITileEntityProvider so we can link it to the TileEntity we just covered. For this part I mostly override most of the block methods to fit the correct values. I will cover 5 of this methods and one that is not inherited.
This is simply to call the update method from the TileEntity every tick that runs on the block. It also marks the block for update both on server and client.
This method will be called by Minecraft whenever a player interacts with the block, so we call our TileEntity method for the interaction and mark the block for update.
This method will be called by Minecraft whenever it needs to get the BlockState of the block. For that we crated an auxiliar method that return the state based on the TileEntity values:
We get the different states by checking the items inside the TE, and if it is working or done (all of them TE variables).
And finally we dont want the Barrel to be placed on the air or over another Barrel, and if the floor below it gets broken, we want it to break:
Last of all, we added a list of to the configurations to be able to change the items it can get, and also registered some vanilla items with the food and seeds tags.
And for the item we made a new item, and took the functionallity from the Bone Meal and implemented it under onItemUse. (the implementation can be found on the Vanilla BoneMeal).
Link to the pull-request: https://github.com/ldtteam/minecolonies/pull/2605
That was all for this update, I hope you liked it, both the post and the new Block and Item! I see you in the next post!
Great update @fireruner, can't wait to see the matching AI to this!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks, I can't wait to start learning AI :D
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @fireruner
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks for the fast evaluation and the great comment :D
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
✅ @fireruner, I gave you an upvote on your post! Please give me a follow and I will give you a follow in return and possible future votes!
Thank you in advance!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @fireruner! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :
You published your First Post
You got a First Vote
Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word
STOP
To support your work, I also upvoted your post!
Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Semi Finals - Day 1
Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @fireruner! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :
You made your First Comment
Award for the number of upvotes received
Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Semi Finals - Day 1
Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @fireruner! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Play-off for third result
Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit