#[1.21.10] Spawn A ZombieVillagerEntity whit an especific Job and village type

12 messages · Page 1 of 1 (latest)

proven thorn
#

hi i was playing resident evil3 again
wanna resemble some features from there
i made a BlockEntity using as base the Pedestal from kaupenjoe so it can hold an item and Model it using the ZombieVillager Model from CER
...get stuck on the code

i want this block Entity to spawn back the same type of zombie it resembles if:
the player steps on the blockEntity
or the players take the item the BlockEntity is holding

how do i spawn a Zombie from code and give him a job ???
if(!world.isClient()){
ZombieVillagerEntity zve = new ZombieVillagerEntity(Entities. .world, pos );
}

i wanna make a custome tag list for villager job type
way sheperd block entity only spawns whith shepperd things
and bookkepper BE has only book related items
not a loot json file but kinda same funtionality

how to ?? get an ramdom item from a taglist or
iterate the taglist contains
or dump a collection from the taglist

ArrayList<Items> items = ItemTags.AXES.get(??)

this two things are the thing i get stuck
can you helpme ??

pine dawn
#

For a random axe, either a loot table or you have to get all items in a tag and then get a random item from that list (kinda annoying)

proven thorn
#

.....
Dont get it

the only way i get to get the ItemTag list as a list is to iterate all items filtering whats in the axe taglist
Item item;
List<Item> itemlist = new ArrayList<>();
for( Identifier key : Registries.ITEM.getIds() ){
item = Registries.ITEM.get(key);
if( item.getDefaultStack().isIn(ItemTags.AXES) ) {
itemlist.add( item );
}
}

for( Item i : itemlist ){
    System.out.println( i.getName() );
}

can you provide an example .... please

the other spawning thing
well i can spawn a villager zombie the traditional way
but cannot get this registries thing to aply the villagerData other thing and change type and profecion

i have spend a while just trying ramdon

ZombieVillagerEntity zve = new ZombieVillagerEntity(EntityType.ZOMBIE_VILLAGER, world );
zve.setPosition( user.getBlockPos().north(3).toCenterPos()  );

//VillagerData.withProfession(VillagerProfession.CLERIC profession)

/*
zve.setVillagerData(
        new VillagerData((RegistryEntry<VillagerType>) VillagerType.JUNGLE, (RegistryEntry<VillagerProfession>) VillagerProfession.CLERIC, 1)
);
zve.getVillagerData()
        .withProfession( VillagerProfession.CLERIC.getRegistryRef()  )
        .withType((RegistryEntry<VillagerType>) VillagerType.JUNGLE)
);*/
world.spawnEntity( zve );

java.lang.ClassCastException: class net.minecraft.registry.RegistryKey cannot be cast to class net.minecraft.registry.entry.RegistryEntry (net.minecraft.registry.RegistryKey and net.minecraft.registry.entry.RegistryEntry are in unnamed module of loader 'knot' @57fffcd7)
at knot/duum.modid.item.custom.testItem.use(testItem.java:109) ~[main/:?]

pine dawn
#

For the zombie thing, you're casting a key to an entry. That doesn't work.

proven thorn
#

yaa absolutely
but dont get how to get the RegistryEntry for the register key
VillagerProfession.CLERIC.getRegistry() only gets an identifier
i guest i must call RegistryEntry and iterate for that identifier but dont seems to work like that

#

alredy check the SpawnEggItem the ZombieVillagerEntity and the VillagerEntity and dint find something i could use a example

pine dawn
#

Pretty sure you want the villager profession registry

proven thorn
#

yaa i made it work

ZombieVillagerEntity zve = new ZombieVillagerEntity(EntityType.ZOMBIE_VILLAGER, world );
zve.setPosition( user.getBlockPos().north(3).toCenterPos()  );

zve.setVillagerData(
        new VillagerData(
                world.getRegistryManager().getEntryOrThrow(VillagerType.JUNGLE),
                world.getRegistryManager().getEntryOrThrow(VillagerProfession.CLERIC),
                1) );

world.spawnEntity( zve );

is not intuitive
not a bite

also weird google dint find
there must be plenty of people doing this before

wicked trench
#

why would plenty of people be doing this, mechanically all zombie villagers are indentical

#

as far as jobs go anyways