There is currently 1 player online.

Connect now using the IP

Internet Explorer

Internet Explorer is not supported. Please upgrade to a more modern browser.

Devlog #1 - Items
Started by zProxxy



07 Feb 2023
Last Seen
26 Jun 2024


This is the first devlog! In this thread I will talk about our items system, what we have changed and how this may improve future development.


Items are an extremely essential part of SurviveTheNight. They give you some stats, they allow you to use certain abilities and you can customize them! Or atleast some of them.

While it looked like our items were working fine and there was no reason for us to change them: No! They weren't fine nor were they easy to work with.

The previous system

Before I get into how our previous system was like, you have to understand how an item (or ItemStack) is constructed.

An ItemStack can be split up into atleast three different parts:

  • The general information: This includes the Material type (For example STICK, BOOK, STONE, so basically what the item looks like), the amount (How many of them should be in that stack we're creating) and the sub ID (STONE:0 would be stone while STONE:3 would be diorite)
  • The ItemMeta: This contains a bunch of different data such as the item description (also known as the item lore), the displayname, vanilla enchants, some special attributes to hide certain properties and much more.
  • Custom NBT: You may also add custom NBT to the items. Why would this be useful? It allows us to save custom data on an item without it being visible for casual players. These can be useful to store certain values such as an NPC value, a UUID, etc. on the item.

So how did our previous system look like?

Every STN item was coded manually. Each item has its individual STN ID which is used to identify the original item when it's modified, add certain abilities to it and just check for items in general.

All the possible modifiers were coded manually and whenever joining a server a brand new copy of the original itemstack (depending on their STN ID) would be loaded from the plugin and then every applied modifier of the original item would be applied to the new item.

This basically allowed us to keep all the items updated when switching servers but also make them not lose any of your applied modifiers. However the main issue was applying the modifiers in the first place.

As I already said every modifier was coded manually instead of having a modular design.
There was a bunch of code repitition (which is never fun and not what you should be doing when coding), which lead into the modifiers class containing about 4.000 lines of code and the entire modifier system not being modular at all. Adding new modifiers would be a pain as I'd have to implement that modifier at like 30 different locations in various classes in the entire code.

     Creating/Crafting new items:
As you may have noticed: Loading in items or crafting new items in the crafting menu would take a couple ticks for them to actually load in and update properly.
This was caused by another issue we've had: This issue required us to wait a couple ticks for the server to properly create a new copy of the original itemstack before being able to modify it, otherwise it would modify the original itemstack and apply the modifier to EVERY item with the same STN ID on the entire instance - crazy, I know! (This issue caused me alot of pain in the past btw, I really hate it.)

    The NBT structure:
Aswell as all of that, the NBT on the items were kinda confusing and hard to read - not like you should read them, however for us for debugging purposes it was really annoying to work with:

All of our custom NBT was saved into "STNData" on the item and a pickaxe for example would end up looking like this:

STNData: {
            itemUUID: "0abd2c29-b306-4082-8522-cdeac2f1718e",
            itemType: "Pickaxe",
            stnID: "CRYSTALLIZED_PICKAXE",
            efficiency: 5,
            pickaxeUnlockedModes: "engine:handle:prism",
            doubleDrop: 0,
            npcValue: 720,
            miningExpReq: 25,
            handMiningFortune: 350,
            itemUUIDDC: "ca30a282-0a61-4c60-818f-a4a0f9c6e160",
            breakingPower: 7,
            pickaxeModeSelected: "handle",
            handDiggingRate: 1950,
            propertyOne: "multiblocks5",
            propertyTwo: "overflow5"

As you can see: Nothing is sorted nor are the values or names easy to understand.

The new system

The main reason we did the revamp was because of the difficulty when it comes to adding new modifiers to items.

I managed to figure out a system where I can just add one line of code which contains all the necessary information to add a whole new modifier - and trust me: This is way way easier to work with than before.

This would be how a modifier in the new system looks like:

MAGICIMBUED(ModifierTypes.GLOBAL, "MAGICIMBUED", new Object[]{"STNData", "magicImbued"}, null, true) {@Override public <t> ItemStack addNBTTags(ItemStack iS, T additionalData, boolean update, ItemStack... prevStack){return new GlobalModifiers().addNBTAndLoreMAGICIMBUED(iS);}},</t>

It may look a little confusing, however this is probably the easiest I could do.

It contains a ModifierType which basically says which item types this modifier can be applied to,
a modifier name which is required for updating the item,
an NBT "path" to the data of the modifier on the item and
an STN ID blacklist which contains IDs with items that cannot have this modifier ("null" in this example as there's no exception).

I also reworked the system which made new items require a couple ticks before being able to be modified, so that any types of delay when it comes to creating new items, crafting new items or loading new items should be completely gone.

The NBT structure of items is way easier to read now, even tho it may not seem like it at first sight:

STNData: {
            coreItem: {
                itemType: "pickaxe",
                stnID: "CRYSTALLIZED_PICKAXE"
            miningExpReq: 25,
            itemUUID: "ca30a282-0a61-4c60-818f-a4a0f9c6e160",
            enchants: {
                efficiency: 5
            npcValue: 720,
            modifiers: {
                pickaxePerk: {
                    extradrops: 1
                breakingPower: 7,
                pickaxeMode: {
                    draconicPrism: "true",
                    active: "reinforcedHandle",
                    reinforcedHandle: "true",
                    pickaxeEngine: "true"
                propertyOne: {
                    multiblocks: 5
                propertyTwo: {
                    overflow: 5
            profileStats: {
                diggingSpeed: 1950L,
                miningFortune: 350L

And saving the itemstacks to databases has also been improved. Instead of being saved as some type of yml "string" (which is like a million characters long), they're now being saved as Base64 encoded itemstacks.

I also took some time to rework the design of item descriptions! This is what a pickaxe will look like when the changes come to the main server:

The overall structure of modifiers has been changed, every modifier now has its own section.
The pickaxe now also not only shows the selected pickaxe mode but also the already unlocked ones on the pickaxe.

Future development

If you took a look at the new NBT structure you may have noticed an enchants section.
Yes! We are finally able to properly add multiple enchants to the game without any issues.

Aswell as that we are able to easily add new pickaxe perks, modifiers, attributes, stats and make changes to the current ones.

Every item now has a proper item category so that we can make global changes to every item in a certain category.

Overall it's just much much easier to modify, add and remove new items, their stats and modifiers.



This system took a lot of time to rework. Obviously a system like this wasn't my first approach when thinking of a new modular item modifier system, so it took a couple days to experiment with NBTs and much more.

After about two weeks of coding, trying and fixing bugs this system does seem to work decently fine. It does require more testing and if you notice anything disappearing on your items once the servers are back online, please immediately report issues!

However especially when looking into the future, reworking this system was necessary and will allow us to bring new enchants, modifiers or items almost effortlessly to the server!


Systems that must still be reworked

This is more like a checklist with systems that will probably receive their own devlog once they're done.

  • Items
  • Achievements
  • STN Creatures
  • Inventories
  • NPCs

That's it! Hope you learned something new! I didn't go too much into detail on this one, otherwise you'd read for another 2 hours probably.

I'm sorry for not including too many pictures, I'll try and add more in the upcoming devlogs.

zProxxy · 3 months ago