5

In specific, I'm looking to code a sword that, when used to block, advances the time of day by 4800. Hopefully this can be accomplished with command blocks only, as I'd rather stick to vanilla minecraft.

So far, I've only figured out how to correctly employ custom names and enchantments, so this is all I've got for the command:

/give @p iron_sword 1 0 {display:{Name:"Longdark Blade",Lore:"[Long ago, it was thought that metals","could control the stars themselves...]"}}
3
  • 1
    Will the sword only be used for blocking, or for fighting too? Commented Jul 8, 2015 at 6:02
  • Originally the sword was meant to have a special right click ability, but I've since scrapped that in exchange for having a sword that lengthens the time of day when used, allowing you to either stave off the darkness or grind with impunity.
    – Nutwit
    Commented Jul 9, 2015 at 0:57
  • 1
    @Nutwit I rolled back your edit as it completely invalidated the existing answer. If you have a new question (which you do), ask a new question. You can copy-paste the text from the revision history by clicking on "edited X ago" and select "side-by-side-markdown". You can also reference this question in the new question.
    – MrLemon
    Commented Jul 9, 2015 at 10:32

1 Answer 1

5

This method works by handing over the sword to an invisible armor stand to detect the right-click (block). I haven't tested it but it should work. If it doesn't please tell me. This won't work when using the sword to fight as you will hit the armor stand.

First run the following commands once to create the scoreboard objectives used:

  1. /scoreboard objectives add holdSword dummy
  2. /scoreboard objectives add rightClick dummy
  3. /scoreboard objectives add summoned dummy

Create a fill clock that runs the following commands in the correct order (from lowest to highest coordinate):

  1. /scoreboard players add @a summoned 0
  2. /scoreboard players set @a holdSword 0
  3. /scoreboard players set @a holdSword 1 {SelectedItem:{id:"minecraft:iron_sword",tag:{display:{Name:"Longdark Blade",Lore:"[Long ago, it was thought that metals","could control the stars themselves...]"}}}}
  4. /scoreboard players set @e[type=ArmorStand] rightClick 0
  5. /scoreboard players set @e[type=ArmorStand] rightClick 1 {Equipment:[{id:"minecraft:iron_sword",tag:{display:{Name:"Longdark Blade",Lore:"[Long ago, it was thought that metals","could control the stars themselves...]"}}}]}
  6. /execute @e[type=ArmorStand,score_rightClick_min=1] ~ ~ ~ /time add 4800
  7. /execute @e[score_holdSword_min=1,score_summoned=0] ~ ~ ~ /summon ArmorStand ~ ~ ~ {CustomName:rightclick,Invisible:1,Invulnerable:1,NoBasePlate:1,NoGravity:1,ShowArms:1}
  8. /scoreboard players set @a[score_holdSword_min=1,score_summoned=0] summoned 1
  9. /execute @a[score_holdSword_min=1,score_summoned_min=1] ~ ~ ~ /tp @e[type=ArmorStand,name=rightclick,r=1] @p
  10. /execute @a[score_holdSword=0,score_summoned_min=1] ~ ~ ~ /kill @e[type=ArmorStand,name=rightclick,r=1]
  11. /give @a[score_holdSword=0,score_summoned_min=1] iron_sword 1 0 {display:{Name:"Longdark Blade",Lore:"[Long ago, it was thought that metals","could control the stars themselves...]"}}
  12. /scoreboard players set @a[score_holdSword=0,score_summoned_min=1] summoned 0

Explanation

The first command block is just to ensure that the score summoned can be used for all players. The second command will reset all players' scores of holdSword, while the third command will set the score back to 1 when holding the sword in their hand. When the sword is held in the player's hand an armour stand will summon at them (seventh command) which will be used to check for right click. It will check for right click by checking if the armour stand is holding the specific sword (fourth command reset score and fifth command set score if holding item), because when you right click an armour stand with an item, it gives the item to the armour stand. When the right click is detected and the armour stand is holding the item in his hand, the time will be advanced by 4800 (sixth command). The ninth command will teleport the armour stand to the player 20 times a second, which will ensure it will detect the right click. The tenth command will kill the armour stand if the item is not held anymore. The eleventh command will reset the score of the summoned armour stand so that the whole process can happen again.

8
  • 1
    You might want to add some explanation to this. It took me quite some time to figure out why or how it works.
    – MrLemon
    Commented Jul 8, 2015 at 7:57
  • @MrLemon Edited. Commented Jul 8, 2015 at 8:13
  • This seems like it could work, but also seems like it could get really complicated and leggy if I try to implement more than one custom item like this. I might use portions of this code for other things, though.
    – Nutwit
    Commented Jul 9, 2015 at 0:31
  • @Nutwit There is a much easier way to add an event when a player hits with the sword, rather than blocking. Maybe, if you really want this to happen, you can rather make the time add 4800 when they hit, not block. Commented Jul 9, 2015 at 5:27
  • 1
    @ReaLord It should yes. It depends on what command you are talking about, but most commands should still work. Commented Sep 11, 2016 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.