Minecolonies & The MultiBlock

in #utopian-io6 years ago (edited)

Hey everyone,

While I am waiting for a few contributions of our other devs I got inspired to create a new Minecolonies Block.
The MultiBlock.

Minecraft at the moment already offers a way to push around blocks and entities.

And not only by being mean.

It's by using Pistons.

While this is nice and people are able to leverage this to build complex things like elevadors, different types of doors etc, it's still difficult to make really cool stuff and, if space restrictions are in place, several things are impossible.

That's why we created the MultiBlock.

The MultiBlock (The one above the diamond block) allows you to do much more than a simple piston can do.

It basically sucks a limited amount of blocks, on command through it.

In the GUI you can configure which direction to which direction should be used and also how many blocks should be considered and at which speed they should move.

Since it is difficult to explain this just in pictures I created a nice Video:

But let's cut the chase.

To make this I had to create a block which is interactable and a GUI.

Fortunately we have our own GUI framework called Blockout which allows us to design GUIs quite easily.

https://github.com/Minecolonies/BlockOut

We design it with a traditional XML syntax and catch the button calls in the Window class I showed above.

The only missing thing now is the TileEntity.

TileEntity in minecraft are "entities" which allow you to store additional data in a block and allow you to execute certain actions each tick.

For this we created the TileEntityMultiBlock and this entity class is where the magic happens.

It has a row of variables.

Most importantly the state it is in (Pushing or retracting) as in "on".
The "direction" it pushes in and the "output" direction it pushes to.
The "range" it considers and the speed it does it in.

Quite important as well is what it currently does.
Which in this case, is the "currentDirection" it has to push to, with the progress it made and the ticks that passed.

Then each tick it will check if it has anything to do at the moment (following the above variables) and if it has something to do it calls the "handleTick" method.

And this method is the most important part.

First of all we get the block we want to push or pull to make sure we only push the blocks of the same kind.

Then in the huge "if" you can see we check if it is of any kind of block which shouldn't be pushed, like for example blocks which would get destroyed or bedrock or blocks that block or ignore movement.

Then we come to the main part of it. The for loop.

First of all we calculate the block it should go to and the block it should come from.

A short example for a run.
Let's calculate the first run, for a 3 block movement.

3: ()
2: ()
1: ()
0: []
-1: X
-2: X
-3: X

Imagine the above situation, we want to move the block from the X to the empty brackets + we have to pull the "0" situation in the middle.

That means in the first run we have the following operations:

-1 to 1
-2 to -1
-3 to -2

This means, if the value is negative we have to go into one direction, if positive in the other.
If the value is 0 we have o jump over it.

I found this task extremely educating and also a reason why programming exams should always be on paper and not on the computer.

Since algorithms are created on Paper, if you start creating an algorithm in code you usually end up with a slower algorithm and you end up needing more time, since you're thinking more about the code than about the actual algorithm.

I hope you liked this as much as I did.

I'll see you guys the next time!



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Very creative!
I can tell you had a lot of fun making this. Keep it up!

Yeah, definitely =P I came up with quite some use cases

Haha, well my kid is the big Minecrafter. I'll let him see it.

Hey @raycoms I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

my son plays something like that but it's called minicratf and I like it because it's building houses, it looks a lot like this.

This is a modification of the game of Minecraft, like something additional you can install.

ok, I'll show it to my son. Thanks buddy

That's pretty awesome man! Have you considered getting it incorporated into a modpack later on?

Since it is part of the "Minecolonies mod" it is incorporated in a bunch of modpacks already =)

I've read your post thanks a lot but I still understand this little can be a good information

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

What happens if pistons and multiblocks end up interacting directly and/or indirectly? Which one takes priority?

The multiblock can't push itself and can't push pistons. If both get fired at the same time, it's probably random who will take the lead (Depending on which ticks first).

Coin Marketplace

STEEM 0.32
TRX 0.12
JST 0.033
BTC 64647.16
ETH 3160.49
USDT 1.00
SBD 4.13