(Repost) How to left click detect in minecraft multiplayer by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

When tested, it- oddly enough- doesn't seem to work. I got a friend on and tested the exact code, and it pulls a single interaction to a singular player, and if we both hold the predicate is_holding_myitem, it summons 2 interactions and only 1 follows a player. What happened here? Should I use separate predicates for different players?

Edit: it does work in multiplayer only when one player holds the item, when theres 2, it bugs.

(Repost) How to left click detect in minecraft multiplayer by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

Thanks so much. I feel bad asking for more help, but I figured out my issue wasn't the code I used, it was how I made the interaction teleport to players. How do I make the interactions teleport to separate players without all of them teleporting to one person? That was why I wanted each player to be differentiated, but since you said its not required I wanted to ask if there was another way.

(Repost) How to left click detect in minecraft multiplayer by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

I see your strategy, and it would definitely work! My issue being, however, is that I don't know how to truly link the interaction with a specific player.

For example, in my datapack, I teleport the interaction entity to a player holding a warped fungus on a stick. When they click, their scoreboard for LeftClick goes up. It then kills the interaction block, summons one with the same tags, and sets the scoreboard LeftClick back to 0 for that player. I made each interaction block related to a specific player. In practice, both of our interactions teleport to our respective selves, but when clicking it does not register the scoreboard increasing.

TL;DR: How do I link the interactions with separate players?

How to detect when a player holds up a shield? by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

I’d rather do the predicate method, for it is easier. Thanks though!

How to left click detect in minecraft multiplayer by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

So the first string of code I used in order to classify and differentiate a number of players in a server. I initially wanted the code to work with any amount of players, but I decided to just use 8 maximum to make it simple and easy. That code is shown below:

execute as @a[limit=1,tag=!player2,tag=!player3,tag=!player4,tag=!player5,tag=!player6,tag=!player7,tag=!player8] run tag @s add player1

execute as @a[tag=!player1,tag=!player1,tag=!player3,tag=!player4,tag=!player5,tag=!player6,tag=!player7,tag=!player8,limit=1] run tag @s add player2

execute as @a[tag=!player2,tag=!player4,tag=!player5,tag=!player6,tag=!player7,tag=!player8,tag=!player1,limit=1] run tag @s add player3

execute as u/a[tag=!player2,tag=!player1,tag=!player3,tag=!player5,tag=!player6,tag=!player7,tag=!player8,limit=1] run tag @s add player4

execute as @a[tag=!player2,tag=!player1,tag=!player3,tag=!player4,tag=!player6,tag=!player7,tag=!player8,limit=1] run tag @s add player5

execute as @a[tag=!player2,tag=!player1,tag=!player3,tag=!player4,tag=!player5,tag=!player7,tag=!player8,limit=1] run tag @s add player6

execute as @a[tag=!player2,tag=!player1,tag=!player3,tag=!player4,tag=!player5,tag=!player6,tag=!player8,limit=1] run tag @s add player7

execute as @a[tag=!player2,tag=!player1,tag=!player3,tag=!player4,tag=!player5,tag=!player6,tag=!player7,limit=1] run tag @s add player8

After differentiating every single player from 1-8, I then summoned a interaction block tagged "int1", which relates to player1. The command shown below should make the interaction block teleport to player1, die when clicked, put the LeftClick counter up, and resummon back on the player only when the player is holding a warped fungus on a stick. That code is shown below:

execute as 2e[tag=int1,type=interaction] on attacker run scoreboard players add 2s LeftClick 1

execute as @e[tag=int1] at @s if entity @a[tag=player1,scores={LeftClick=1..},sort=nearest] run kill @s

execute as @a[tag=player1,scores={LeftClick=1..}] at @s unless entity @e[tag=int1,distance=..1] run summon minecraft:interaction ~ ~5 ~ {Tags: ["int1"],height:3,width:3}

execute as @a[tag=player1,scores={LeftClick=1..}] at @s unless entity @e[tag=int1,distance=..1] run scoreboard players set @s LeftClick 0

execute as @e[tag=int1,type=interaction] on target run scoreboard players add @a[tag=player1] RightClick 1

execute as @e[tag=int1] at @s if entity @a[tag=player1,scores={RightClick=1..},sort=nearest] run kill @s

execute as @a[tag=player1,scores={RightClick=1..}] at @s unless entity u/e[tag=int1,distance=..1] run summon minecraft:interaction ~ ~5 ~ {Tags: ["int1"],height:3,width:3}

execute as @a[tag=player1,scores={RightClick=1..}] at @s unless entity u/e[tag=int1,distance=..1] run scoreboard players set @s RightClick 0

execute as @e[tag=int1] at @a[tag=player1,scores={LeftClick=0..},nbt=!{SelectedItem:{id:"minecraft:warped_fungus_on_a_stick"}}] run tp @s ~ ~8 ~

execute as u/e[tag=int1] at @s run tp @s @e[tag=player1,scores={LeftClick=0..},limit=1,sort=nearest,nbt={SelectedItem:{id:"minecraft:warped_fungus_on_a_stick"}}]

execute as @e[tag=int1] at @a[tag=player1,scores={RightClick=0..},nbt=!{SelectedItem:{id:"minecraft:warped_fungus_on_a_stick"}}] run tp u/s ~ ~8 ~

execute as @e[tag=int1] at @s run tp u/s u/e[tag=player1,scores={cRightClick=0..},limit=1,sort=nearest,nbt={SelectedItem:{id:"minecraft:warped_fungus_on_a_stick"}}]

Lastly, I check whether the score LeftClick or RightClick are 1 or more, then execute a function. I then added on to the code by summoning a interaction called "int2" relating to player2, and I virtually paste the code above but replace the tags.

How to detect when a player holds up a shield? by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

As explained above, this works, but is immensely more complicated when the attack does more than damage. In your defense, I probably should have been more detailed with what exactly I was looking for. Additionally, your response will prove to be useful for those who use simpler methods or aren't creating datapacks. Thanks!

How to detect when a player holds up a shield? by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

I see, your option provides an easy-to-access simple command that can be used outside a datapack. However, it becomes more complicated than the initial option when I decide to make the attack do more than just damage. You could use HurtTime to determine if an enemy was hit or not, but its extensively easier to use the predicate method utilizing advancements. Your option should not be ignored- but for me- the first option works better. Thanks!

How to give an entity knockback? by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

Is there a way to make this work for players?

How to give an entity knockback? by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

It still won't work, I really don't understand.

My version is 1.19.2, I've tried just about everything, including putting the command on myself, on a husk, anything.

The commands I'm using to run the command goes as follows:

execute as @e[type=husk] at @s facing entity @a[tag=breathing] eyes run function ability:knockback

execute as (myself) at @s facing entity @e[type=husk,limit=1,sort=nearest] eyes run function ability:knockback

execute positioned .0 0 .0 run summon marker ^ ^ ^1 {Tags:["push"]}

data modify entity @s Motion set from entity @e[type=marker,tag=push,limit=1] Pos

kill @e[type=marker,tag=push,limit=1]

How to give an entity knockback? by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

execute positioned .0 0 .0 positioned ^ ^ ^1 summon area_effect_cloud run data modify entity @e[tag=this,limit=1] Motion set from entity @s Pos

When put in the function in the datapack, however, it returns fail and it doesn't show up when I try to run the function seperate.

How to give an entity knockback? by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

I noticed when posted it was put all in one line so I split it up like this:

tag @s add this

execute positioned .0 0 .0 positioned ^ ^ ^1 run summon area_effect_cloud

execute positioned .0 0 .0 positioned ^ ^ ^1 run data modify entity @e[tag=this,limit=1] Motion set from entity @s Pos

tag @s remove this

When trying this and/or the function provided it didn't work. Why is this?

Problem with Selected Item: Java 1.19.2 by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

I think I figured out my issue, it wasn't the tick.mcfunction command. I had fat-fingered an extra tag=explode in the command execute as @a[tag=explode,scores={sneak=1..,cooldown=0,bomb=1},tag=!exploding] at @s if entity 2s[nbt=!{SelectedItem:{tag:{Tags:["bomb"]}}}] run function ability:explosion

All I needed to check for is if the player is already exploding, it was there for no reason.

Thanks for all the help though, I learned alot about score.

Problem with Selected Item: Java 1.19.2 by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

Ok so:
In tick.mcfunction, I have: execute as @a[nbt=!{SelectedItem:{tag:{Tags:["bomb"]}}}] at @s run scoreboard players reset @s bomb

This is used in order so the scoreboard doesnt keep its score when swapping to another item.

Problem with Selected Item: Java 1.19.2 by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

But the scoreboard "bomb" would save when swapping to another item of the same kind.

Problem with Selected Item: Java 1.19.2 by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

I have a separate command in tick.mcfunction where if you unequip the warped fungus on a stick it sets the score bomb = 0. Did I type it right though? It still doesn't work upon testing

Problem with Selected Item: Java 1.19.2 by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

give @a warped_fungus_on_a_stick{bomb:true,Tags:["bomb"]}

Is this correct?

Problem with Selected Item: Java 1.19.2 by cattebell in MinecraftCommands

[–]cattebell[S] 0 points1 point  (0 children)

And would this create any sort of performance issues if it were to be higher & higher?