Dismiss Notice
Wynncraft, the Minecraft MMORPG. Play it now on your Minecraft client at (IP): play.wynncraft.com. No mods required! Click here for more info...

Command Block Help

Discussion in 'Minecraft' started by AcadeeAlkana, Jan 9, 2021.

Thread Status:
Not open for further replies.
  1. AcadeeAlkana

    AcadeeAlkana . . .

    Messages:
    349
    Likes Received:
    434
    Trophy Points:
    83
    Minecraft:
    So does anybody know their way around Command Blocks? I'd personally like to get into using them myself, so that I can hopefully create and test out Wynncraft Spells of my own making. Y'know, so I can legitimately get a gameplay feel for the ideas which I cook up.
    Plus, as a future game dev, any sort of coding experience is going to be helpful, even if it's just Minecraft Command Block. So, with my motives explained and out of the way, I need help with commands for CBs which will...
    • Detect if Player is holding a specific Item/give an Item an ID of sorts which Command Blocks can detect.
    • Detect Right Clicks - Obviously, I need to be able to detect right Clicks. Otherwise, Spells are a no-go, and we can't have that.
    • Store, Check For, and Delete Data - This is for the Spell System, if not a Mana system, too. Plus, it could help if there was a way to make it invisible to other players besides an Admin of sorts (aka me).
    • Pose/Summon Invisible Armor Stands/Boats/Arrows/etc. - For various things.
    • Check for Player in Boat - Again, various purposes.
    • Make different Scoreboards for different Players - display different things on a Scoreboard for different Players.
    • Display Text between the Health and Mana bars - for displaying the Spells you're casting, among other stuff.
    I'll add more if I think of more to add which I need help with. I'd appreciate any and all answers/links to easy-to-follow tutorials on the above bullet points! Maybe if this all goes smoothly enough, and if I can get good enough at coding CBs, I could try to run a server on Minehut to let people test out my ideas!
    Disclaimer: I have no intent of ripping off Wynncraft, nor am I interested in monetary gain via a hypothetical store which affects in-game players on my server. This would basically all be for funsies!
     
  2. IzzSt

    IzzSt Nephilim CHAMPION

    Messages:
    102
    Likes Received:
    45
    Trophy Points:
    55
    Guild:
    Minecraft:
    I don't believe spells are made with command blocks but rather with actual plugins if im not wrong
     
  3. Pianoplayer1

    Pianoplayer1 Well-Known Adventurer HERO GM

    Messages:
    68
    Likes Received:
    61
    Trophy Points:
    49
    Creator Karma:
    Guild:
    Minecraft:
    To detect if a player holds an item, just use this command: /execute as @a[nbt={SelectedItem:{id:"minecraft:stick"}}] run say hi. This will execute a command you can put after the word "run" at the end (in this example, everybody holding a stick will constantly say hi in chat). Also, a command block will give a redstone comparator output when it recognizes at least one player in the world holding that item.

    You can give items custom NBT tags. Simply do that by /give @p item{tag:value}, for example /give @p minecraft:stick{item:"magic wand"}. The name you choose for the tag (in the example "item") can be anything you want, but some tags like "name" or "lore" do change the appearance of the item. You cannot see a custom tag on the item info, but you can reference it with commands. To come back to the first example, you would have to replace id:"minecraft:stick" by tag:{item:"magic wand"} to let every player holding any item with the tag "item" set to "magic wand" say hi in chat.

    Yes, definitely. With plugins, many things are easier to code into the game than with command blocks. You cannot detect right clicks directly, although there are some workarounds. None of those are actually good, so a right click detection as it is on Wynncraft is not possible in vanilla minecraft. Right click detection only works flawlessly with one item, the carrot on a stick. If you would try to use any other item, you would have to summon armor stands or villagers around the player to detect if the player interacts with them by right clicking. Those methods work fine, but because your right clicks will be blocked, players won't be able to use buttons, chests, doors and everything else you need to right click anymore.
    I can still explain you the carrot on a stick method or the villager / armor stand workarounds if you want.

    Storing data makes use of scoreboards, so I will combine your two questions.
    Each scoreboard has an objective and a list of players that have scored points in that objective. You create a scoreboard by typing /scoreboard objectives add <name> <criteria>. You can freely choose the name. There are several minecraft statistics you can use for <criteria>, for example let the scoreboard count the numbers of deaths the players have by using "deathCount". The minecraft wiki provides a full list of criteria to choose from. If you just want to use the scoreboard to store and modify data by commands, use the criteria "dummy". To display a scoreboard, you can do /scoreboard objectives setdisplay <position> <objective name>. For position, you can use belowName (a number will appear below the username in multiplayer), list (a number will appear after every playername on the [tab] player list) or sidebar (every player will have their own line at the side of your screen when the value has changed at least once). To edit a player's scoreboard value, you can use /scoreboard players set|add|remove|reset <value> <player>. "set" will use an absolute value you enter, "reset" sets a player's value to zero and removes it from the sidebar list, "add" and "remove" increase or decrease a player's value by the given amount.
    The easiest ways to use scoreboard values in commands are when you select specific players in your world: /execute as @a[scores={objective name:value}] run <command> or by executing a command if (or unless) a scoreboard value matches / is bigger /smaller than a limit you have set: /execute if score <player> <objective name> = <number>. Instead of =, you can of course write < (smaller), <= (smaller or equal) etc.. So if you would have a mana bar that fills up to 20 in steps of 1, you could repeatedly use this command: /execute as @a unless score @s mana >= 20 run scoreboard players add @s mana 1. Whenever you would run this command, the mana bar of every player would fill up by 1 unless it's already full.
    Sadly there is no way to display different scoreboards for different players in vanilla minecraft. If you only have fifteen or less players, you can give everyone a seperate scoreboard team and display different things in each team, but teams are another scoreboard topic I won't get into now.

    Use the website mcstacker.net and click on "/summon", the site provides many different command block features to summon blocks or entities and has intuitive services for other command stuff as well (including scoreboards!).

    You can get nbt data about a player's "root vehicle", in a command it would look like this: /execute as @a[nbt={RootVehicle:{Entity:{id:"minecraft:boat"}}}] run <command>. This command runs from every player that sits in a boat; you could for example use the command effect give @s minecraft:night_vision 1 1 true as <command> to give every player in a boat night vision.

    This text is called "action bar" and is part of minecraft's title system. To display something there, you have to specify the location of the text in the title command: /title <player> actionbar <text>. The text is required to be in JSON format, for example {"text":"Hi"}. Instead of text, you can directly display scoreboard values or even NBT data. Again, the website mcstacker.net is very helpful for titles.
     
    Last edited: Jan 10, 2021
    :3, Eryndir, Namakobushi and 2 others like this.
  4. AcadeeAlkana

    AcadeeAlkana . . .

    Messages:
    349
    Likes Received:
    434
    Trophy Points:
    83
    Minecraft:
    Thank you so much for the help!
     
  5. Ankarin

    Ankarin Wise Mystical Tree CHAMPION

    Messages:
    793
    Likes Received:
    2,158
    Trophy Points:
    146
    Guild:
    Minecraft:
    i view people who know things things as like einstein or something lol
     
  6. AcadeeAlkana

    AcadeeAlkana . . .

    Messages:
    349
    Likes Received:
    434
    Trophy Points:
    83
    Minecraft:
    If you wouldn't mind, could you please explain the villager method? Also, I would like to know if you'd recommend me any good plugins which would help code commands in the game!
     
  7. Pianoplayer1

    Pianoplayer1 Well-Known Adventurer HERO GM

    Messages:
    68
    Likes Received:
    61
    Trophy Points:
    49
    Creator Karma:
    Guild:
    Minecraft:
    It's pretty late for me so I'll just post a link for now: https://www.planetminecraft.com/blog/right-click-detection-1-13/, maybe tomorrow I'll explain more and tell you how you can use it for multiplayer worlds...

    I'm sorry, but I have absolutely zero experience with plugins. Maybe I can find some blog entries tomorrow that I can post here.
     
    AcadeeAlkana likes this.
  8. Pianoplayer1

    Pianoplayer1 Well-Known Adventurer HERO GM

    Messages:
    68
    Likes Received:
    61
    Trophy Points:
    49
    Creator Karma:
    Guild:
    Minecraft:
    Okay, after a lot of researching I have finally managed to make right click and left click detection work at the same time. It doesn't always work when the player sprints or turns around fastly, also you get weird particles when left clicking because of a villager dying. Still, it's a pretty good system, so I'll try to explain it here as easy as I can.

    The system is based on an invisible villager that constantly teleports to the player. When the player right clicks, a minecraft stat called "talked_to_villager" increases, and you can detect that change by scoreboards. When the player left clicks, the villager gets killed due to a very low health, you can also detect that change by a command block / function.
    A problem when teleporting a villager into a player is that the villager will push the player away because of mob collision. To avoid that, you first have to create a scoreboard team with any name you want (I would suggest a name like "collision" to recognize the team's function) by typing /team add <name> and /team modify <name> collisionRule never to avoid mob collision for every player in that team. Now you have to put every player in your world into that team, for example by letting a repeating command block execute /team join <name> @a. That way, whenever a new player joins your world, they will automatically be put in that collision team.

    The next step is to assign a villager to each player in your world and get excess villagers killed once a player leaves your world or teleports far away. For that, you will need two repeating command blocks with these commands: /execute as @a at @s unless entity @e[tag=click,distance=..2] run summon villager ~ ~ ~ {Silent:1b,NoAI:1b,Health:1f,Tags:["click"],ActiveEffects:[{Id:14b,Amplifier:1b,Duration:1000000,ShowParticles:0b}]} and /execute as @e[tag=click] at @s unless entity @p[distance=..2] run kill @s. The first command summons a villager at every player's (@a) position (at @s ... ~ ~ ~) unless there already is an entity with the tag "click" at a distance of two blocks around the player. The villager that gets summoned is silent, has no AI (= doesn't move or regenerate health), is almost dead (Health:1 = 1/2 heart left) and the tag "click". Additionally, it has the "invisibility"-effect (id 14) for 1000000 ticks (almost 14 hours). The other command kills every villager (@e[tag=click]) when there is no player at a distance of two. If you run both commands in repeating command blocks, you will see nothing (because the villagers are invisible), but if you fly around in spectator mode, you will notice a villager gets spawned at your position every two blocks, and all villagers behind get killed. Of course you don't want a new villager every two blocks, so you have to make use of another repeating command block that teleports villagers (@e[tag=click]) to their nearest player (@p): /execute as @e[tag=click] run teleport @s @p. Now you should see a villager following you when you are in spectator mode.

    Now you'll build the actual right click detection system. As already mentioned, it triggers when you talk to the villager, so you will need a scoreboard to capture the event: /scoreboard objectives add <name> minecraft.custom:minecraft.talked_to_villager. You may give it a name like "click", but it doesn't really matter. If you do /scoreboard objectives setdisplay sidebar <name> to see the scoreboard, you'll see that it increases every time you right click (when the two repeating command blocks are active). Since you don't want a counter but an actual event that triggers at every right click, you have to add two more repeating command blocks: /execute as @a[scores={<name>=1..}] run <command> and /execute as @a[scores={<name>=1..}] run scoreboard players set @s <name> 0. The first part of the commands checks for every player with a score of at least 1. You can insert any command you want in the first command block, the second one resets the scoreboard for that player afterwards. Make sure to activate the first repeating command block before you activate the other one, otherwise it won't work. Now you can insert a test command like "say Right" in the first one, and you will see a message in chat every time you right click the villager.

    The left click detection system is quite easy when you already have the other repeating command blocks activated, it's just one more repeating command block: /execute as @a at @s unless entity @e[tag=click,distance=..2] run <command>. If you kill the villager by left clicking, the command block will trigger since there'll be no entity with tag "click" around the player. Since you already have a command blocks that spawns new villagers whenever a player doesn't have one, the killed villager will automatically get replaced. To make it work, you have to activate this command block before you activate the one that spawns a new villager. Again, you can enter a test command like "say Left" and you should be able to see right and left clicks in chat now. To deactiavte the command blocks, you may have to sprint to them and reach them before the villager runs into you, because you cannot right click anything else while the villager is inside of you.

    I'll now sum up the commands you have to enter, the best order to activate the command blocks and include test commands and names for the scoreboard / team.
    Commands you only have to enter once (either through a command block or the chat):
    • /team add collision
    • /team modify collision collisionRule never
    • /scoreboard objectives add click minecraft.custom:minecraft.talked_to_villager
    • /scoreboard objectives setdisplay sidebar click (optional)
    Commands in repeating command blocks (you can also write a function with the commands in this order):
    • /team join collision @a
    • /execute as @e[tag=click] at @s unless entity @p[distance=..2] run kill @s
    • /execute as @a at @s unless entity @e[tag=click,distance=..2] run say Left Click (this will spam the command until you activate the next command block)
    • /execute as @a at @s unless entity @e[tag=click,distance=..2] run summon villager ~ ~ ~ {Silent:1b,NoAI:1b,Health:1f,Tags:["click"],ActiveEffects:[{Id:14b,Amplifier:1b,Duration:1000000,ShowParticles:0b}]}
    • /execute as @a[scores={click=1..}] run say Right Click
    • /execute as @a[scores={click=1..}] run scoreboard players set @s click 0
    • /execute as @e[tag=click] run teleport @s @p

    When deactivating, you should deactivate the teleport one first so it won't annoy you while trying to right click, the rest doesn't really matter.
    I hope this helped you a little bit, but as already said, without plugins it's hard to code click detections. It seems fairly easy to code plugins yourself, things like a click detection work with a single line of code in plugins...
     
    Eryndir and Namakobushi like this.
  9. quick007

    quick007 Master Adventurer

    Messages:
    715
    Likes Received:
    382
    Trophy Points:
    95
    Guild:
    Minecraft:
    there's a language called "skript", its like fake java code, would recommend you use that. here's some snippets:

    https://pastebin.com/t7x6NDfj
     
Thread Status:
Not open for further replies.