Minecraft Data Packs / Adventure

Dialogue In Minecraft (CONCEPT)

  • check_circle Functions
  • 4,477 views, 1 today
  • 139 downloads, 0 today
  • 7
  • 5
  • 2
Amicdict's Avatar Amicdict
Level 57 : Grandmaster Engineer
43
Today, I have released a concept datapack concepts that adds generic, and regular dialogue to villagers in minecraft. And no, this doesn't just use CustomNames on villagers. I mean actual dialogue from any villager, even named ones! You can share this link on social media, hovever: NO UNAUTHORIZED DISTRIBUTION AS YOURSELF BEING THE CREATOR!

Explanations
This will explain how this works, so that you can do the same thing.

To start off, I first added the following scoreboards:
-clicked_villager (minecraft.custom:minecraft.talked_to_villager, activates when clicked on a villager, even a Nitwit.)
-traded_villager (minecraft.custom:minecraft.traded_with_villager)
-all_villager (dummy, to be a total action count.)
-timer (dummy, to be sure the scores are updated correctly.)

Now first 3 commands:




scoreboard players reset @a[scores={timer=3..}] traded_villager

scoreboard players reset @a[scores={timer=3..}] clicked_villager
scoreboard players reset @a[scores={timer=3..}] all_villager


The timer score will only increment whenever a action is made, I will explain that later. This ensures that the villager scores get reset.


scoreboard players add @a[tag=!remove_timer,scores={all_villager=1..}] timer 1
scoreboard players add @a[tag=remove_timer] timer 1
scoreboard players reset @a[tag=!remove_timer,scores={timer=3..}] timer
tag @a[scores={timer=2..}] add remove_timer
tag @a[scores={timer=3..}] remove remove_timer
scoreboard players add @e[tag=message] life 1


Lets start off with the top 3 commands. The top most one will increment timer score if they don't have the tag remove_timer but has atleast 1 for all_villager. The next command will continue incrementing timer to those who have the tag remove_timer.
Third command will reset the timer if their timer score is at least 3 and they don't have the remove_timer tag. I did this because if I didn't use a tag, the timer score would continously increment, messing up the commands. 4th and 5th commands just adds the remove_timer tag if their timer score is at least 2, and removes the remove_timer tag if their timer score is at least 3.
The bottom most command will add life to the messages to register how long have they existed.

Ok. Now lets move on to the messages function.

execute at @a[tag=!remove_timer,scores={traded_villager=1..,timer=1}] as @e[type=villager,distance=..3] facing entity @s eyes at @s run summon armor_stand ~ ~2 ~ {CustomName:"{\"text\":\"Come again!\",\"color\":\"green\"}",CustomNameVisible:1,Marker:1b,Tags:["message"],Invisible:1b,Small:1b}

execute at @a[tag=!remove_timer,scores={clicked_villager=1..,timer=1}] as @e[type=villager,distance=..3] facing entity @s eyes at @s run summon armor_stand ~ ~2 ~ {CustomName:"{\"text\":\"So what are your needs?\"}",CustomNameVisible:1,Marker:1b,Tags:["question_message"],Invisible:1b,Small:1b}

### Hurt Messages ###

execute at @a[tag=!remove_timer] as @e[type=villager,distance=..3,nbt={HurtTime:10s}] facing entity @s eyes at @s run summon armor_stand ~ ~2 ~ {CustomName:"{\"text\":\"JERK!\",\"color\":\"red\"}",CustomNameVisible:1,Marker:1b,Tags:["danger_message"],Invisible:1b,Small:1b}


This just summons the armor_stands at the villagers if a player is near and facing one, depending on the score they have. For some reason, marker armor_stands have a very low collision box, and their name tag is at their feet, so I have to summon them above the villager.


#########################################
# Keeps the message above the villager. #
#########################################

execute as @e[type=villager] at @s positioned ~ ~2 ~ run tp @e[tag=message,distance=..0.75] ~ ~ ~


This just keeps the message armor_stands above their separate villagers.


#########################################################
# Kills the oldest message armor Stand if they overlap, #
# lose their target, or last longer than 5 seconds. #
#########################################################

execute as @e[tag=message] at @s if score @s life > @e[tag=message,distance=..0.5,sort=random] life run kill @s

execute as @e[tag=message] at @s unless entity @e[type=villager,dy=-2] run kill @s

kill @e[tag=message,scores={life=100..}]


The middle and bottom commands just remove the messages if they lose their villager or lasted longer than 5 seconds.

I want to explain the top command. I quickly registered a problem of overlaping messages if multiple actions are done quick enough. That is hard to read. So an execute is ran as and at a message armor stand. If their life score is greater than another random message armor_stand thats near, then it will kill itself.


So thats how this works. It makes use of execute if score and the now-normal execute command. I made this to tackle a weakness with custom dialogue without just changing a name to make it compatible with other datapacks.

Source Codes
Random Function
scoreboard objectives add clicked_villager minecraft.custom:minecraft.talked_to_villager
scoreboard objectives add traded_villager minecraft.custom:minecraft.traded_with_villager
scoreboard objectives add all_villager dummy
scoreboard objectives add timer dummy
team add message
team join message @e[tag=message]
team join message @e[tag=question_message]

scoreboard players set @a[scores={traded_villager=1..}] all_villager 1
scoreboard players set @a[scores={clicked_villager=1..}] all_villager 1
scoreboard players add @a[tag=!remove_timer,scores={all_villager=1..}] timer 1
scoreboard players add @a[tag=remove_timer] timer 1
scoreboard players reset @a[tag=!remove_timer,scores={timer=3..}] timer
scoreboard players reset @a[scores={timer=3..}] traded_villager
scoreboard players reset @a[scores={timer=3..}] clicked_villager
scoreboard players reset @a[scores={timer=3..}] all_villager
tag @a[scores={timer=2..}] add remove_timer
tag @a[scores={timer=3..}] remove remove_timer

scoreboard players add @e[tag=message] life 1


Messages Function
#################################
# Creates message armor stands. #
#################################

execute at @a[tag=!remove_timer,scores={traded_villager=1..,timer=1}] as @e[type=villager,distance=..3] facing entity @s eyes at @s run summon armor_stand ~ ~2 ~ {CustomName:"{\"text\":\"Come again!\",\"color\":\"green\"}",CustomNameVisible:1,Marker:1b,Tags:["message"],Invisible:1b,Small:1b}

execute at @a[tag=!remove_timer,scores={clicked_villager=1..,timer=1}] as @e[type=villager,distance=..3] facing entity @s eyes at @s run summon armor_stand ~ ~2 ~ {CustomName:"{\"text\":\"So what are your needs?\"}",CustomNameVisible:1,Marker:1b,Tags:["question_message"],Invisible:1b,Small:1b}

### Hurt Messages ###

execute at @a[tag=!remove_timer] as @e[type=villager,distance=..3,nbt={HurtTime:10s}] facing entity @s eyes at @s run summon armor_stand ~ ~2 ~ {CustomName:"{\"text\":\"HELP! I NEED HHHEEELLLLP!!\",\"color\":\"red\"}",CustomNameVisible:1,Marker:1b,Tags:["danger_message"],Invisible:1b,Small:1b}

execute at @e[tag=danger_message,name="HELP! I NEED HHHEEELLLLP!!"] as @e[type=villager,distance=1..8] at @s run summon armor_stand ~ ~2 ~ {CustomName:"{\"text\":\"SOMEONE GET HELP NOW!\",\"color\":\"red\"}",CustomNameVisible:1,Marker:1b,Tags:["danger_message"],Invisible:1b,Small:1b}


#########################################################
# Kills the oldest message armor Stand if they overlap, #
# lose their target, or last longer than 5 seconds. #
#########################################################

execute as @e[team=message] at @s if score @s life > @e[team=message,distance=..0.5,limit=1,sort=random] life run kill @s

execute as @e[team=message,scores={life=99..}] at @s unless entity @e[type=villager,dy=-2] run kill @s

kill @e[team=message,scores={life=100..}]

############################################
# Keeps the message armor stand above the villager. #
############################################

execute as @e[type=villager] at @s positioned ~ ~2 ~ run tp @e[team=message,distance=..0.75] ~ ~ ~

Fun fact: I actually discovered this thursday that forceload isn't supposed to work in functions or command blocks, because that could crash a server. At first, I thought it was a bug. I get that for servers, but why singleplayer too?
CompatibilityMinecraft 1.13
Tags

Create an account or sign in to comment.

1
11/08/2019 2:23 pm
Level 48 : Master Nerd
Awsomo1324
Awsomo1324's Avatar
Nice concept! Have you considered that this could override the names of villagers given with nametags?
2
11/08/2019 5:09 pm
Level 57 : Grandmaster Engineer
Amicdict
Amicdict's Avatar
This is an old datapack, but I made a Newer Version. Anyway, this actually uses armor stands to display the messages.
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome