[Open Source] SkyBlock Minecraft Addon - Storage unit added [New feature #12]

in utopian-io •  6 years ago  (edited)

Hello everyone,

I have a new add-on to show, which has been suggested by the players of SKYBLOCK.SK, a Minecraft game mode. Additional to that, I reduced the size and readability of the SkyBlock/SKYBLOCK.SK/Commands.sk by using more functions which are now called instead of executing the code directly within one big file.

1. Repository

https://github.com/Abwasserrohr/SKYBLOCK.SK

2. Index

  1. Repository
  2. Index
  3. New Features
    3.1. Added new functions
    3.2. Phantom spawning and fire spread is now toggleable
    3.3. gui.sk add-on now supports normal and shift-clicks
    3.4. Added storage unit add-on
  4. Pull requests
  5. GitHub Account
  6. How to contribute

3. New Features

3.1. Added new functions

With the new functions which I added, the SkyBlock/SKYBLOCK.SK/Commands.sk file is now easier to read than before. With these new functions, the files can be maintained easier.

  • createisland(player,"name of island"):
    The creation process of creating an island is now happening within the createisland function.
    SkyBlock/SKYBLOCK.SK/createisland.sk

  • islandmember(player,"action","target"):
    If a player should be invited, join, leave or get kicked out of an island, this is now the function which can get called and does the job.
    SkyBlock/SKYBLOCK.SK/islandmember.sk

  • islandhelp(player,"site number as text"):
    Instead of just having this within the SkyBlock/SKYBLOCK.SK/Commands.sk, it has now its own file. I also plan to make the /island help better in the future.
    SkyBlock/SKYBLOCK.SK/islandhelp.sk

  • islandinfo(player,"player as text"):
    This function gives the player the island info of the current island, where the player stands. Also a text parameter containing a player is possible. If it is set, the island of the player is used to display.
    SkyBlock/SKYBLOCK.SK/islandinfo.sk

Pull request: https://github.com/Abwasserrohr/SKYBLOCK.SK/pull/102


3.2. Phantom spawning and fire spread is now toggle able

Toggling the phantoms on is not very nice on a multiplayer server, because most of the times, nobody wants to sleep. Also having fire spread disabled is pretty useful, since some islands would already have burned down by fire. But some server operators might want to give the players some hard-core difficulty and enable this.

If the server operator wants, these both settings can now be toggled within the SkyBlock/config.sk file.

Pull request: https://github.com/Abwasserrohr/SKYBLOCK.SK/pull/105


3.3. gui.sk add-on now supports normal and shift-clicks

The gui.sk add-on now can run another function if the user clicks while holding shift.

To allow backwards compatibility, more functions can be separated within the function with ||.

This is how it looks now:

      set {_exec::*} to {SK::GUI::items::%{_player}%::%{_slot}%} split at "||"
      if {_exec::2} is not set:
        set {_exec::2} to {_exec::1}
      if event.isShiftClick() is true:
        evaluate "%{_exec::2}%"
      else:
        evaluate "%{_exec::1}%"

If there is a second function defined, which has been separated by ||, it can run it if the player clicks with shift. I want to look into skript-mirror's custom syntax which would allow better handling of such functions.

Pull request: https://github.com/Abwasserrohr/SKYBLOCK.SK/pull/106


3.4. Added storage unit add-on

The newly added storage unit has been requested by the users of the test server yesterday. They argued that it would reduce the amount of chests and hoppers, which could help with server performance. They are also a nice tool to have a better and easier overview.

Now, it has been added to the game and it seems that the people like it how it has been done. It works without variables or any storage outside of vanilla. I used the internal storage of the Minecraft map itself to store the data within the inventory of the block; this not only makes this easier but also reduces any extra setup or loading time.


Here are some parts to show off how it works:

If the player crafted one of the new storage units, most of the time, they are going to get placed somewhere. The following part is responsible for a correct placement of the storage unit.


on place of {@item}:
  if line 1 of lore of player's tool is "{@itemidentfier}":
    set {_allowed} to checkislandaccess(player,location of event-block,"build")
    if {_allowed} is true:

Once the player places a block like defined in the options of the add-on, it is checked if the first line of the lore has the item identifier for storage units. If it has, it is checked if the player also has rights to build at the location. Only if the player can build there, go forward:

      if block below event-location is hopper:
        if {@preventhopperbelow} is true:
          cancel event
          set {_uuid} to uuid of {_p}
          set {_lang} to {SK::lang::%{_uuid}%}
          if {SB::lang::storage::hopperbelowdisabled::%{_lang}%} is set:
            message "%{SB::lang::prefix::%{_lang}%}% %{SB::lang::storage::hopperbelowdisabled::%{_lang}%}%"
          else:
            message "{@prefix} {@hopperbelowdisabled}"
          stop

The server operator can toggle if it should be allowed or disallowed to have a hopper below the storage unit. Because of how the storage units are built, it can create some lag if there are any. That is why these are disabled by default and blocked.

      set {_loc} to event-location
      set {_inv} to block at {_loc}'s inventory
      set slot 26 of {_inv} to 1 of clay
      set line 1 of lore of slot 26 of {_inv} to "0"
      set line 2 of lore of slot 26 of {_inv} to "STORAGE"

If the storage unit is at a valid spot, it is going to be placed. The slot 26 of the inventory, which is the last available slot, is being used to store the amount of items within the lore of the item. That way, I don't need to save it anywhere, I can just directly access the item and the lore of it in the inventory anytime I need it.

Now, we have a storage unit placed. It can be filled either directly by a user or using hoppers. Here, I show how items are stored if they are filled with a hopper.

on InventoryMoveItemEvent:

The InventoryMoveItemEvent is called always if an item is moved on the server, this is used quite often.

  if {@hopperhook} is false:
    if slot 26 of event.getDestination() is clay:
      if line 2 of lore of slot 26 of event.getDestination() is "STORAGE":
        cancel event
    stop

If the server operator disabled the hopper feature, we just have to cancel out the event if the destination is a storage unit.

  if slot 26 of event.getDestination() is clay:
    set {_inv} to event.getDestination()
    set {_itemdata} to slot 26 of {_inv}
    if line 2 of lore of {_itemdata} is "STORAGE":

Here, it is checked if this is a storage unit or a regular inventory.

      set {_item} to slot 0 of {_inv}
      set {_itemdata} to slot 26 of {_inv}
      set {_eitem} to event.getItem()

To make the file easier to read, I use local variables which hopefully help the eyes. =)

      if {_item} is air:
        set line 1 of lore of slot 26 of {_inv} to "1"
        set {_loc} to event.getDestination().getHolder().getLocation()
        storagesignupdater({_loc},{_item},1)

If the item in slot 0 is air, the storage unit is empty.

      else if {_item} is {_eitem}:
        set {_amount} to number of {_item} in {_inv}
        remove 1 of {_item} from {_inv}
        set {_savedamount} to line 1 of lore of {_itemdata}
        set {_savedamount} to {_savedamount} parsed as integer
        add {_amount} to {_savedamount}
        set line 1 of lore of {_itemdata} to "%{_savedamount}%"
        set {_loc} to event.getDestination().getHolder().getLocation()
        storagesignupdater({_loc},{_item},{_savedamount})
        set slot 26 of {_inv} to 1 of {_itemdata}

This part above happens, if the item, which should be filled into the storage unit is the same as the one which is already in the storage unit.
Because there would be two items of the same type and it is supposed to only have always only one item in slot 0, it removes one of the item to always only keep one of it in slot 0.
After that, it updates the amount of the stored items into the lore of the clay ball, which is in slot 26 of the storage unit inventory.

      else:
        cancel event
If the item, which should be filled into the storage unit is not the same as the one in the storage unit, we have to cancel the event to not destroy our storage unit inventory.

While this process is fast and doesn't create any extra database just for this purpose. We also have the opportunity to store enchantments and even books with enchantments or text within the storage unit without removing the contents of it. It would be possible to use Skript variables for this, but with the inventory, they don't have to be loaded and they are only loaded if they actually active. Also, since we need to access to the inventory of the storage unit anyway, it doesn't even cost that much resources, since the inventory access and catching the InventoryMoveItemEvent event is necessary anyways.

Until I got this running without problems, it took quite a while. But now it runs and it seems the users like how it turned out. I'm also looking forward to get some feedback here on Steem, of course. =D

Making a storage unit is not only about storing the items. But it is also needed to create a unique menu for it, be sure to not leave any leak open where players could access the normal inventory of the block or duplicate items.

At the beginning I though I could get this done within some hours but it turned out to take more than a day only because of duplication gliches and other small things that are now how I would like to see it.

As example, if a player opens the storage unit, they get the current stock. But if there are hoppers connected, this stock is changing. I thought it would be neat to see the stock live in the inventory if it changes and I added it into the add-on. But it also took some time to find how to do it the proper way.

Then I tested it and it works now. One user also requested to have a status sign above the storage unit, which displays the current item and the amount. This is now added too. Thank you for the suggestion, @altonos.

I also found out about the checklists on GitHub, didn't know about them before, that's a neat feature! =D


Pull request: https://github.com/Abwasserrohr/SKYBLOCK.SK/pull/107

4. Pull requests

https://github.com/Abwasserrohr/SKYBLOCK.SK/pull/102
https://github.com/Abwasserrohr/SKYBLOCK.SK/pull/105
https://github.com/Abwasserrohr/SKYBLOCK.SK/pull/106
https://github.com/Abwasserrohr/SKYBLOCK.SK/pull/107

5. GitHub Account

https://github.com/Abwasserrohr

6. How to contribute

I'm looking forward to find contributors for SKYBLOCK.SK, are you interested? Meet me on Discord on the link below. :)

Discord: https://discord.gg/FRuK5BC


Thank you for reading this contribution post. As I said in the last post, I now watching out for new Ideas users have and try to add them into the game. Once the people are happy and there aren't any new ideas, I will then focus on creating a documentation and localization of the game to English. Then, the first release isn't that much away. :3

I'm still looking at the roadmap of SKYBLOCK.SK and working towards a nice end product which can be enjoyed by both players and server operators in the future.

If you got any feedback about this post, the new storage system or SKYBLOCK.SK in general, just leave a comment. New feature requests or ideas have also high chances of being added, if they make sense. =) Thank you for your effort.

Keep on steeming and a nice weekend

@immanuel94

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  • Great post that includes animated gifs with links.
  • Good code samples and awesome comments in the code,

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? Chat with us on Discord.

[utopian-moderator]

Thank you for reviewing my contribution post.^^

Thank you for your review, @helo! Keep up the good work!

Cool das es jetzt auch Lagersysteme gibt. Im SV sind die ja schon top.

Ja, wobei diese Lagersysteme viel ausgereifter sind und mehr Möglichkeiten bieten. =)

Tolle funktion. Mal sehen was noch so alles kommt.

Alles, was man dort so sehen kann, kommt meistens auch, wenn es dich genauer interessiert: https://github.com/Abwasserrohr/SKYBLOCK.SK/issues ^^

Ich finde es cool das es ein lagersystem im Skyblock gibt. Ich finde der preis ist auch angemessen.

Ja, das Lagersystem hat durchaus Vorteile, auch, wenn die etwas kosten...^^

Ich finde das Lagersystem sehr schön gemacht. Der Preis passt auch :D

Hi @skyroadfan. Vielen Dank für die Anregungen. Freut mich, dass dir der Preis passt.

das lagersytem ist ziemlich praktisch und spart viel platz

Ja, finde ich auch. Lagersysteme sind schon was sehr praktisches, spart viel Kisten und Trichter... =D

nun gibt es sogar ein neues lagersystem, klasse!

Hallo @sausemaus! =D

Ja, ein neues Lagersystem. ^^ Wenn du Feedback dazu hast oder dir was nicht gefällt, melde dich gerne.

Hi @immanuel94!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @immanuel94!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!