Welcome back everyone! I hope you all had a wonderful break, I know I did. I said I was going to post more over the break, but I have a valid reason why I didn’t. At the beginning of break I was thinking I was going to code a ton, try and get a lot done while I didn’t have school, but when I started, I wasn’t really into it. Since I’ve had many experiences with project burnout in the past, I decided I was just going to use break.. as a break. Didn’t do any coding, didn’t write any posts, simply sat around the house doing whatever I felt like on a day-to-day basis. Turns out it was quite effective, but by now I’m ready to continue work on ReLife! I’ve got a couple of thing to talk about here, the first being a random project I worked on over a couple of days at the end of break, and the second being a small addition to ReLife I’ve worked on over the past few days. In the immortal words of Phinneas and Ferb.. here we go again!

Manhunt Plugin

Alright, I’m going to start with the small project and then end with ReLife. As you can tell from the title of this section, I made a quick plugin to be able to play the popular Manhunt minigame. I simply made it because I felt like playing with my brother, and all of the plugins on the internet aren’t what I was looking for. Therin lies what I love about programming; if there isn’t already a way to do what you want, you can do it yourself. Anyway, it’s not very pretty and has several bugs, because I prioritized coding it quick over coding it well, but my goal was to make a extremely customizable Minecraft competition-based plugin. You can create different teams, set their win conditions (their end goal) and set their abilities, like having a tracker, being able to respawn, etc.

Again, it isn’t complete, and has some bugs, but at least it did what I wanted it to. I might revisit it in the future, if I want some small project to work on, and if I ever touch it up and make it have a nice user interface, I might publish it. However, for now I’m making my glorious return to ReLife!

Lightning Aspect

To start, I need to give a little bit of background. As I’ve mentioned, there are going to be 12 different zones shaped in a square. Each of these zones have some unique trap, trick, or treacherous thingamajig to trigger trepidation. Additionally, I want each zone to have some unique item, mechanic, something. For the Lightning Storm zone, that mechanic is imbuing lightning onto your tools. Essentially, you can place a tool (sword, axe, pickaxe, shovel, or hoe) that is made out of iron or diamond onto a lightning rod. You simply do this by right clicking the lightning rod block. Then, when that rod is struck, the item has a chance to be destroyed. I mean come on, you’re literally trying to channel a lightning strike into it. If it isn’t destroyed, it gains two enchantments. The first is called Brittle, and it gets a random level 1-3. The second is called Lightning Aspect, and gives a different benifit based on the type of tool.

I’m going to start by talking about placing an item onto a lightning rod. Essentially, my goal when I was starting, was to have an item just hovering about the block, spinning. Right click with a tool to place the tool on it, and right click again to take the item off. The first thing that I had to deal with was how to actually store that the item was there - the backend. The issue with just storing a map (where I can say “[this block] has [this item]”) is it wouldn’t keep that if the server were to restart. Theoretically the server won’t be restarting, however it’s good practice to account for everything. Lucky Minecraft has a persistent data storing system in place called metadata. Essentially, all entities, blocks, items, and a few other things can store metadata. Using this, you can store an object using a key. Using this, I simply store the item in the block’s metadata. That done, I now have to figure out how to render the item hovering above the block. My initial thought was have an acutal item entity just sitting there. Every time an item is on the ground, it’s an entity. However, the issue with that is items can merge with other items of the same type on the ground, can be picked up, and can die to a number of different things.

After Googling for a little, I came across the idea of using an armor stand. Armor stands can hold items in their hands and wear items as armor. I tried doing this by spawning an invisible armor stand, setting the item to be in the head armor slot, and then continuously rotating the armor stand. while this did create a spinning item, it was going in circles - not rotating in place. This is because when an item is rendered as a piece of armor, it renders a bit behind the head. Consequently, while the center of the head is spinning in place, the item is a bit behind the head and moving in circles. Since that wouldn’t work, I went back to the idea of having an actual item entity. After looking through some events, I found that everything that I thought would cause issues, called events that could be cancelled. Essentially I just spawn an item and then cancel every event that would make something happen to the item. That being said, at the time of writing there are still a few issues such as the item colliding with blocks, but those will be dealt with soon (I hope).

Ok, now we have rendering the item floating working. Next step is to make it so that when lightning strikes the rod, it will either enchant the tool or destroy it. Unfortunately, there isn’t an event for this already. There is, however, an event for lightning striking. In this event, I can just check if the lightning entity is directly above a rod, and then proceed if the rod is currently storing an item. If the destroy chance is met, the item is destroyed, otherwise it is given the enchantments and the metadata is updated. All told, this is the simplest part of the whole thing.

Final part. Now I just have to actually make the enchantments do something. To get the general idea, the Brittle enchantment is the downside, while the Lightning Aspect is the reward. As this is something that is readily available to everyone, I can’t make it super powerful. The Brittle enchantment essentially makes the tool take more damage every time it uses durability. There is an event for a tool taking damage, so in that event it multiplies the damage by the level of Brittle the tool has, plus 1. Essentially if your tool has Brittle I, it will take double damage. If it has Brittle II, it will take triple damage, and so on. That was the easy part. The hard part is Lightning Aspect. As a reward for possibly destroying your item, and making it take more damage, some aspect of it is improved, themed around lightning.

For example, swords make every attack a critical hit. In Minecraft you have to be falling to land a critical hit; you have to jump and hit them on the way down. This allows you to run around your oponent while still landing critical hits. This one was pretty easy, just had to look through NMS until I could find how it applied crits. For the axe, it strikes lightning whenever it breaks a shield. In Minecraft, any hit from an axe will make an oponent lower their shield and disable it for 5 seconds. Striking lightning after the shield is broken means that it will do a lot of damage to your oponent, however since you have to be in melee range to break a shield, it also will do damage to yourself. Again fairly simple, on attack if the attacker is weilding an axe with Lightning Aspect and the defender is blocking, strike lightning. For the pickaxe, it auto-smelts mined blocks. For this, on a block break, instead of letting it drop whatever it would normally, it loops through all the drops and instead drops the smelted version if there is one. To get the smelted version, I just loop through the furnace recipes and see if the input matches the drop. The hoe always drops apples when mining leaves. Apples are very important as they’re a good source of food, and also can be used to make golden apples which can heal you. Just like with the pickaxe, simply drop an apple on block break.

The final, and hardest, tool is the shovel. For all of the tools I tried to pick things that would amplify whatever they’re most used for. Swords make it easier to combat. Axes enhance breaking shields, and pickaxes make getting minerals easier. Hoes make it easier to get apples, and then there’s shovels. One of the least useful tools but for one thing; getting blocks. So, to make it easier to get blocks my plan was to make it mine in a 3x3, but that’s easier said than done. To start, I need the block face that the player is mining: top, bottom, north, south, east, or west. This is important because there’s no way to get the blocks to the “left” or “right” of the mined block. Unfortunately, the block breaking event doesn’t have that information, so instead, every time a player left clicks a block (as is required to break it), it stores the clicked face. Thankfully, the interact event stores that. Now, I could have figured out how to do the 3x3 part on my own, but to be honest I didn’t really feel like it, and it’s never a good idea to reinvent the wheel. I went ahead and just grabbed some code from the internet, and bam! 3x3 aquired. Now I just loop through all the blocks and destroy them if they can be destroyed by a shovel.

Wrapup

And that’s it! There are still a couple of bugs to finish with imbuing lightning, but it’s pretty much done. Thank you all for reading once again, and although I’m not so excited for the homework load to return, I am excited to return to ReLife and blogging. Have a wonderful week, and I will see you all next weekend.