#How do I detect block.right_click based on an Array or tag?

37 messages · Page 1 of 1 (latest)

craggy ravine
#

Here is my current script:

http://pastie.org/p/4BLhWZiXRNhhdEMxRCp1EJ
onEvent('block.right_click', event => {
var plankable = new Array("minecraft:stripped_oak_log")
if(event.block.id == "minecraft:stripped_oak_log" && event.hand == MAIN_HAND && event.item == "minecraft:iron_axe") {
Utils.server.tell("Axe")
}
})

I don't know how to paste it nicely like everyone does, please let me know how

So I want to replace "minecraft:stripped_oak_log" with either my arrary plankable or with a forge tag, however it stops working when I do. Same goes for event.item.

Let me know. Thanks!

analog oysterBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

tawdry lodgeBOT
#

You can write your code in a codeblock by typing it between the codeblock delimiters:

```js :arrow_left:

ServerEvents.recipes(event => {
event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})

``` :arrow_left:

As an example, :arrow_up: will look like this:

ServerEvents.recipes(event => {
  event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
left trail
#

event.item.hasTag('forge:loggy_logs') for a tag, or someArray.contains(event.item.id) for an array (it may be includes instead of contains, one of them is java the other is javascript and i can never remember which)

craggy ravine
#

For the array, am I listing the strings inside the ()?

left trail
#

wdym

#

an array is just let someArray = ['item1', 'item2']

craggy ravine
#

OH okay I see

#

Hmm okay I tried some variations of that but it is not happening. Let me send some examples. This is 1.18.2 btw not sure how much difference that makes

#
onEvent('block.right_click', event => {
    if(event.block.hasTag == 'forge:stripped_logs' && event.hand == MAIN_HAND && event.item == "minecraft:iron_axe") {
        Utils.server.tell("Axe")
    }
})
left trail
#

i can see that in your post tags
in this particular case it doesnt make a difference

craggy ravine
#
onEvent('block.right_click', event => {
    if(event.block.hasTag('forge:stripped_logs') && event.hand == MAIN_HAND && event.item == "minecraft:iron_axe") {
        Utils.server.tell("Axe")
    }
})
left trail
#

that looks better

craggy ravine
#

something is still wrong with that, but I don't know what

tawdry lodgeBOT
#

You can find your KubeJS server log in /minecraft/logs/kubejs/server.log.
If you are on 1.18 or below it will be called server.txt.
Please send it if asked, as it contains helpful information.

left trail
#

check that for an error

craggy ravine
#

hmmmmm I don't see anything about it at all

tawdry lodgeBOT
#

Paste version of server.txt from @craggy ravine

left trail
#

hm

#

try put ' around MAIN_HAND

#

so its == 'MAIN_HAND' &&

craggy ravine
#

nope, nothing

#

lol, I could always just do it for every single stripped log block in the game

left trail
#
onEvent('block.right_click', event => {
    event.server.tell(event.block.hasTag('forge:stripped_logs')) 
    event.server.tell(event.hand == 'MAIN_HAND')
    event.server.tell(event.item == "minecraft:iron_axe")
})
#

run that

#

see which one is false

craggy ravine
#

Uh unsure bc I got 6 replies:
false
true
true
false
false
false

#

Okay so even though kubejs hand says it has forge:stripped_logs, it's not working but i used a different tag and it was, so I might just make a custom tag

left trail
#

thats cause item tags and block tags are different things

craggy ravine
#

How am I to find a block tag?

left trail
#

when placed in world a block uses block tags, but when it is in item form (in your inventory) it uses item tags

craggy ravine
#

Ohhhhh

left trail
craggy ravine
#

I see! Okay then that should solve everything. Thank you very much, ArugChief 🙏

#
onEvent('block.tags', event => {
    event.add('forge:plankable', 'minecraft:stripped_oak_log')
})

onEvent('block.right_click', event => {
    if(event.block.hasTag('forge:plankable') && event.hand == MAIN_HAND && event.item.hasTag('forge:axes')) {
        Utils.server.tell("Axe")
    }
})