How do I select specific mob types?

Started by CaptainShark on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I select specific mob types?

Currently messing around with a villager related mod but it relies on 4 types.

I have 4 new chests, a farmer, butcher, shepherd and then an "all villager types" chest.
How do I use a procedure to work with just the one type of villager, for example a farmer?
 

Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Testing to see if I got it…
Sun, 07/10/2022 - 06:47

Testing to see if I got it working by doing the following. It ends up crashing the game when right clicking a villager though.

Global Trigger: Player right click on Entity.

 

                      Is event target/entity sub type of villager
 IF -  (and)  -  Is event target/entity tagged in entity tags as {VillagerData:{Profession:cleric}}
 DO - Spawn at x y z living entity iron golem

I am guessing I have done it wrong lol?

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
"tagged in entity tags" uses…
Sun, 07/10/2022 - 19:39

"tagged in entity tags" uses mob id "minecraft:villager" or sth like this. 

 

You need something I don't think there's possible in mcreator (at least for now):

  • MCreator doesn't support CompoundTag (nbt tag containing other nbt tags).
  • I fast checked (I'm not sure if im right about this one) and i don't know if it's possible to get profession through nbt tags. 
  • There's way to check profession without nbt tags, but you'd need to code file yourself since mcreator doesn't support this. 
Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ah that would explain why…
Sun, 07/10/2022 - 20:47

Ah that would explain why right clicking any mob when using a compound was crashing the game.

For the time being I will just let any villagers work with the blocks. With coding can that all be done inside each elements  Code Editor on Mcreator or would I also need other sites/modding programs? I don't mind having to code but I am new to it so will probably make a test workspace purely for simple code testing, it's just knowing where to start/what I need to begin it all.

Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
As a test I have it so right…
Tue, 07/12/2022 - 04:58

As a test I have it so right clicking a villager summons a fox. I am under the impression I need to change this part of the code. In the code editor at "If (entity instanceof Villager) but I can't seem to work out what to change it to so that it's only ( for example ) a farmer that can trigger the spawn

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Normally I'd check this…
Tue, 07/12/2022 - 10:41

Normally I'd check this myself but i don't have time for this and i understand you have some code writing knowledge, let's try something basic.

You can try this:

First use if statement to check if entity from dependencies is instance of Villager (you can use built in mcreator is sub type of entity) 

Then in if use code snippet:

Village vilager = entity;

If minecraft won't crush there's hope to work without source code editing. If it works, it should give you access to all Villager data. 

 

Under it use another if but with code snippet:

villager.getVillagerData().getProfession() == VillagerProfession.FARMER

This snippet should return true if clicked villager is a farmer. You can replace FARMER with any profession but it has to have all letters uppercase.

 

In this if body you can do whatever you want it to do. 

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry, ill show in…
Tue, 07/12/2022 - 10:47

Sorry, ill show in pseudocode:

if entity is (sub) type of Villager
	code snippet(Villager villager = entity)
	if code snippet(villager.getVillagerData().getProfession() ==  VillagerProfession.FARMER)
		your procedures

 

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Again me, i forgot about…
Tue, 07/12/2022 - 11:01

Again me, i forgot about casting. 

Im first snippet:

Villager villager = (Villager) entity;

Sorry for spam 😅

Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Currently my code writing…
Tue, 07/12/2022 - 11:48

Currently my code writing knowledge is very little lol. Some basic stuff I worked out like how to change recipes in the code since it's a pretty short and straight forward code that gets generated ( so I had an example basically ). When the built in code gets quite lengthy I get confused on where exactly to add new parts as well as how to add them in.

I so far have just guessed a few parts like "if statements" being the green text "IF" 
I've tried to look up some tutorials but the search results are mostly for "without coding" or for more advanced tutorials so currently I have just been noting down a bunch of things I want to learn to code on a notepad to eventually post on this forum. I suppose it's just all part of the overwhelming "where to start" part of learning to code aha. No worries about the spam, spams better than me being confused for hours and hours lmao

 

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I am thinking about making a…
Tue, 07/12/2022 - 11:56

I am thinking about making a plugin which would add possibility to get and set villager professions and other vanilla mob data. 

Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I've not touched plugins…
Tue, 07/12/2022 - 12:07

I've not touched plugins/things that add more triggers and all sorts out of fear they might stop getting updated and then mods I make would all completely break down, assuming that is what would happen, mcreator plugins do seem quite handy though

I think my best bet at the moment is to gather up all the things I am attempting at the moment, posting them and seeing if people have examples. I feel like if there are examples I can then sort of dumb it down a little/word it I understand it better and then save it for future references. 

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
After small think, i think…
Tue, 07/12/2022 - 12:28

After small think, i think you can use one code snippet in one if statement:

((Villager) entity).getVillagerData().getProfession() == VillagerProfession.FARMER

In pseudocode code:

If (entity is (sub) type of Villager) and (code snippet) {
	ur stuff
} 

It really should do the work. 

Professions are the same like on site i gave before but they are uppercase. 

Eventually, you can use this, it's not official forge documentation, but it's pretty helpful for self written code. However you have to know how to read docs. 

Here villager professions:

https://nekoyue.github.io/ForgeJavaDocs-NG/javadoc/1.18.2/net/minecraft/world/entity/npc/VillagerProfession.html

 

And here main page of it: 

https://nekoyue.github.io/ForgeJavaDocs-NG/

 

About plugins, they might be discontinued and i think that if you want to make mods, it's good to know at least java basics.

 

Ps. Personally i am learning C++, not Java XD. However i have java man (friend learning java) and i spam him if i wanna ask sth about java 😇. 

Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
https://imgur.com/a/hmdn8VA…
Wed, 07/13/2022 - 02:34

https://imgur.com/a/hmdn8VA

I am imaging it's a case of just "IF" then pasting "((Villager) entity).getVillagerData().getProfession() == VillagerProfession.FARMER" ( if i even understood that correctly aha. But I am not sure which part/line/section to add that statement in. Having a Java friend certainly sounds quite helpful. In terms of learning to code minecraft is this villager idea a lot more complex than some more basic starting ideas? I will also most likely make  a post about all the things I am trying to learn later on in a fairly more in depth explanation

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
In code blocks you use one…
Wed, 07/13/2022 - 08:37

In code blocks you use one if

if (is Entity/target entity (sub)type of Villager) 

 

use AND statement to have two conditions so its

If (is Entity/Target entity (sub)type of Villager) AND (((Villager) entity).getVillagerData().getProfession() == VillagerProfession.FARMER)

 

"((Villager) entity).getVillagerData().getProfession() == VillagerProfession.FARMER)" use in code snippet that can connect to if.

 

It should work and should allow you to continue working in mcreator's procedure blocks.