Whisperwoods

Whisperwoods

3M Downloads

Hidebehind isn't recognized as an entity by KubeJS

katubug opened this issue ยท 4 comments

commented

Describe the bug

I'm trying to write a script for the Hidebehind, where when you click on him with a certain item, he despawns. The script works on all other entities, but for some reason, clicking on the HideBehind isn't being logged as an entity. For example, my script looks like this:

ItemEvents.entityInteracted('minecraft:oak_planks', (event) => {
	const {
		player,
		hand,
		item,
		target,
		target: {
			x,
			y,
			z
		},
		server,
		level
	} = event;

    console.log(target.type)
	if (target.type != 'whisperwoods:hidebehind') return
	player.swing(hand, true);
	item.count--
	server.runCommandSilent(`particle heart ${target.x} ${target.y+1} ${target.z} 1 1 1 0 10 normal`)
	target.discard()
	server.runCommandSilent(`playsound minecraft:block.bubble_column.upwards_inside master @a ${target.x} ${target.y+1} ${target.z} 100000`)
	const itemEntity = level.createEntity('item');
	itemEntity.item = Item.of('kubejs:hidebehind_note')
	itemEntity.setPos(x + 1, y, z);
	itemEntity.spawn();
});

And the console log looks like this:

[10:41:16] [INFO] story_resolution.js#147: net.minecraft.world.entity.EntityType type() [dev.latvian.mods.rhino.NativeJavaMethod]
[10:41:46] [INFO] story_resolution.js#147: aquamirae:maze_mother

First line is me clicking on the Hidebehind. Second is me clicking on the Mother of the Maze from Aquamirae.

To Reproduce

Steps to reproduce the behavior:

  1. With KubeJS, install the above script in server_scripts
  2. Spawn Hidebehind
  3. Click on Hidebehind with Oak Planks in hand
  4. Nothing happens

Log output/error (if present)

Get your minecraft log and paste it here.

Expected behavior

I expect the console output to say "whisperwoods:hidebehind" and for the script to execute on the entity.

Versions

  • Minecraft Version: 1.20.1
  • Architectury API Version: 9.2.14
  • Platform (Forge/Fabric): Forge
  • Forge Version: 47.3.7
  • Mod Version: 2.1.2

Additional context

I'm guessing there's something about the Hidebehind's behavior that makes it not a true entity somehow? It was spawned via spawn egg, if that makes a difference. But if this is intended design and can't be altered, then I have a lot of changes to make to my pack haha. So any help is very appreciated! Thank you!

commented

No it's a real entity. I'm not sure what the "type" variable KubeJS is using is. WW has complex entity type logic so it may be that the type isn't fully resolved in the same way? It looks like the type field there is a method rather than an actual type object. To me it seems more like a bug with KubeJS interacting with my atypical type system?

commented

Try using type() instead of type

commented

Hmm, okay, so tentatively that works?

[17:07:12] [ERROR] ! story_resolution.js#147: Error in 'ItemEvents.entityInteracted': TypeError: Cannot call property type in object PosCow['Possessed Cow'/1227, l='ServerLevel[New New Testing Final For Real]', x=236.50, y=64.00, z=-1736.50]. It is not a function, it is "object".
[17:07:36] [INFO] story_resolution.js#147: entity.whisperwoods.hidebehind [net.minecraft.world.entity.EntityType]

The console.log part of the script breaks if I try to use it on another entity, but it works for HideBehind. Sorta, I'm just not sure how to edit the next part of the script to work with this. I'll poke around at it but any help would be appreciated.

Edit: Okay actually it was super easy to make the script work properly lol. I'm not sure how to check for other entities though, I'll have to figure that out. Thanks for your help!

commented

you can use "typeof" in JavaScript to verify the type of something (it will be "function" for functions lol)