your current location:首页 > news>[KJS Tricks] Biological blacklist [KJS] Kubejs Minecraft Game

[KJS Tricks] Biological blacklist [KJS] Kubejs Minecraft Game

2024-12-10 17:56:21|Myriagame |source:minecraft skins

When I was playing the world, I found that there were fairy maids everywhere. After clearing the /kill instructions, a lot of brushes were immediately brushed out. These guys are simply breeding in a large number of cockroaches, and anyone must stop them!

I know that there is a organism -generating control module like IN Control, but now that it can be done with Kubejs, there is no need to add another module, right?

<<<<<<<<] = "assh: none;" "> causeEvents.sPawND (e => {{

If (e.entity.type == 'Touhou_little_maid: failry') {{

If (e.entity.Level (). Dimension == 'Aether: the_aether') {

E.cancel

}

}

})

This is an event on the server, so of course, it is placed in the server_scripts folder.

The role of this code is very simple. When the fairy maid is generated, if she is in heaven, she will cancel the incident, so that she will not generate a fairy maid, and it will not work.

Later, when I played Alex's CAVES, I found that the fairy maid will also generate a lot in the original cave. Where is the maid in the dinosaur era?The main world is also prohibited, the previous code is not easy to use now.

<<<<<<<<] = "assh: none;" "> causeEvents.sPawND (e => {{

Let getbiome = () => {

Let POS = New Blockpos (math.floor (e.entity.x), math.floor (e.entity.y), math.floor (e.entity.z)))

Return e.entity.Level (). Getbiome (POS) .unwrap (). GET (). Location ().

}

If (e.entity.type == 'Touhou_little_maid: failry') {{

Let biome = getbiome ()

Let biomeblacklist =/(Alexscaves).*/

If (e.entity.Level (). Dimension == 'Aether: The_aether' || biomeblacklist.test (biome)) {

E.cancel () if (e.player) {

E.Player.tell.

}

}

}

})

The focus of the updated code is the Getbiome function. The principle is very simple, that is, the group system where the entity is located in the level, and then return.It's just that long chain call looks very unknown. The following explains what this string means.

Level () Return a level object;

The getBiome () method returns a Holder object equipped with a Biome object;

The unwrap () method is unpack the Holder back a Either object. There are two elements in the Either object: the left is the resourceKekey object with the Biome object.Either the one on the right ", here is left () to get the left side;

Use left () to get an Optional object, which is a resourceKey object equipped with a Biome object;

Use get () to get the ResourceKey in it;

Use local () to get ResourceLocation;

ResourceLocation is the modid: xxx we often see.

All in all, after a long string of packaging, we finally got the group system when the entity was generated, and then used a regular expression to match. If the matching was successful, or the dimension of the entity is on the blacklist, we stopped it from the blacklist, and it was prevented from the blacklist.Entity generation.

The primitive cave is much cleaner now.