top of page
Writer's pictureBenny

Class 2 notes: Java Coding Class

Updated: Aug 7, 2021

Hi, everyone!


Last class, we learned about the give command. The give command is useful in a lot of different ways. It can give any item in the game, to any player, animal, or even multiple players and animals, and however many you want of that item as well.

This can be used in a puzzle to give you a secret key to an elevator, or to give you a full set of diamond armor when you walk into your house! It can even be used to give a zombie an item, then kill the zombie, thus dropping the item onto a pressure plate to activate some sort of machine!

You can use this command in a lot of ways, and that's why it's so important to learn.

The command looks like this:



/give @p dirt


Like we mentioned in the first class, the first parameter in every command is what command I want to use. If I want to use the setblock command, the first parameter is always "setblock", since that is what I want to use. This works the same with the give command, so the first parameter should be pretty straightforward.

The second parameter, @p, can be changed into a lot of different things. This is how you tell the command block who you want to give the item to, or who the command is going to take effect on. There are four ways of targeting players in Minecraft: @p, @a, @s, and @r. We are only going to focus on @p and @a for now though, as those two are the only ones coders use most.

"@p" means whoever is closest to the command block is going to get the item. So if my friend was closer to the command block and I pressed the button, he would get it rather than me, because even though I pressed the button, he was closer and therefore the command block targeted him.

The second way of targeting players, which is the last way we will focus on for this lesson, is @a. This means the command block will target all players, regardless of who is closer or who presses the button. If I press the button, everyone on the server will get the item. That pretty much wraps up the second parameter, and now on to the third.

The third parameter in /give @p dirt is, you guessed it, "dirt". This just signifies what item I want to give. I can change this to diamond, or diamond_ore, or redstone_block. Whatever I change it to, as long as it has the right ID, it will give it to me.

Now, there is a fourth secret parameter that you might have guessed, a number.

If you put a number after the third parameter in the give command, it will give that amount of items to whoever the command is targeting. So for example, if I executed the command


/give @a netherite_chestplate 5

it would give everyone on the server five netherite chestplates.

That pretty much wraps up the give command, but if you want, I made an extra tutorial on how to operate a generator, which automatically generates complicated give commands, so you don't have to spend a year writing a thousand lines of code for one Minecraft item.

You can find it here on the Wequil school website: Class 2 notes: Java Coding Class: Extra

See you next class!

22 views

תגובות


bottom of page