Villager Profession?

Started by BetaDv_ on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Villager Profession?

How could I make a villager with a Proffesion: "Scammer", what he does, is setup fake trades, and whenever the user trades, he gets nothing in Exchange, and just gets scammed overall. I know I can make a gui and all that, but if I could use the default gui so it looks credible, and make it spawn in villages it would be best, if anyone has any idea how I could get this done (even if it involves code) I would really apreciate if you could help me! :)

 

Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Just use default vanilla gui…
Thu, 10/21/2021 - 19:16

Just use default vanilla gui and apply it

In trade you can get something like AIR

Make villagers spawn in villages with return conditions

 

Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
like woodcreatures said,…
Thu, 10/21/2021 - 20:16

like woodcreatures said, just make a new villager with the exact same texture and download the GUI from Google or .minecraft folder and use this: MCreator Tutorial: How to make NPC Trades | 2020.3 - YouTube

a workaround could be with commands, by summoning a Vanilla Villager with a custom trade Minecraft 1.16.4: How to make a custom villager trades - Bing video however I don't think this is a good option

 

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well.. you can make custom…
Thu, 10/21/2021 - 20:23

Well.. you can make custom professions and trades for villagers, there is even registry for that.

This feature is going to be in MCreator in future.

But you can make it right now with coding.

I can explain this too you and even provide example(from my mod).

 

 

Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'd love if you could help…
Thu, 10/21/2021 - 22:43

I'd love if you could help me do this, Frostygames. Any time you are available, could you send me the code and stuff?

 

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sure, here: https://github…
Fri, 10/22/2021 - 04:23

Sure, here: https://github.com/Frostygames0/Elemental-Amulets/blob/master/src/main/java/frostygames0/elementalamulets/init/ModVillagers.java

This is how to register villagers. Use register method in the constructor of your main class.

Also, anything lower than registerWandererTrades is not needed.

 To give your villager a working outfit: https://github.com/Frostygames0/Elemental-Amulets/tree/master/src/main/resources/assets/elementalamulets/textures/entity

 

 

 

 

 

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Also a small note: if you…
Fri, 10/22/2021 - 04:27

Also a small note: if you copy the code, then the license of your mod should be GPL v3 or any compatible license and not “all rights reserved”

 

Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hey, I understand how this…
Fri, 10/22/2021 - 07:44

Hey, I understand how this code works, but doesn't this actually give me the item? I want it to not give anything back xd

 

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If you want it to return…
Fri, 10/22/2021 - 10:10

If you want it to return empty item then use ItemStack.EMPTY in BasicTrade's constructor instead of new ItemStack(Item instance).

Or you can create your own trade class. 

 

Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well yes, but wouldn't work…
Fri, 10/22/2021 - 14:50

Well yes, but wouldn't work as I intended. I want to show the item, but when the user goes to take it, it removes it and it takes his emeralds and stuff

 

Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
That's at least what I think…
Fri, 10/22/2021 - 14:50

That's at least what I think it will do

 

Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I have a question. Since I…
Fri, 10/22/2021 - 15:04

I have a question. Since I don't know any bit of Java really, only Javascript, which is very different. Could you explain to me a bit how to port this to my mod? If it helps my package name is:
me.betadv.better_vanilla

Thx in Advance, you are nice! :)

 

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
package me.betadv.better…
Sat, 10/23/2021 - 09:53

package me.betadv.better_vanilla;

import com.google.common.collect.ImmutableSet;
import net.minecraft.block.Blocks;
import net.minecraft.entity.merchant.villager.VillagerProfession;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.SoundEvents;
import net.minecraft.village.PointOfInterestType;
import net.minecraftforge.common.BasicTrade;
import net.minecraftforge.event.village.VillagerTradesEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

@Mod.EventBusSubscriber(modid = "YOUR_MOD_ID")
public class ScammerVillager {
    public static final DeferredRegister<VillagerProfession> PROFESSIONS = DeferredRegister.create(ForgeRegistries.PROFESSIONS, "YOUR_MOD_ID");
    public static final DeferredRegister<PointOfInterestType> POI_TYPES = DeferredRegister.create(ForgeRegistries.POI_TYPES, "YOUR_MOD_ID");

    public static final RegistryObject<PointOfInterestType> SCAMMER_POI = POI_TYPES.register("scammer",
            () -> new PointOfInterestType("scammer", PointOfInterestType.getBlockStates(Blocks.AIR), 1, 1));
    public static final RegistryObject<VillagerProfession> SCAMMER = PROFESSIONS.register("scammer",
            () -> new VillagerProfession("scammer", SCAMMER_POI.get(), ImmutableSet.of(), ImmutableSet.of(), SoundEvents.VILLAGER_NO));

    // PUT THIS METHOD IN YOUR MAIN CLASS CONSTRUCTOR(Method that has the name of main class) (It's called like your mod)
    public static void register() {
        IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
        POI_TYPES.register(bus);
        PROFESSIONS.register(bus);
    }

    @SubscribeEvent
    public static void registerTrades(final VillagerTradesEvent event) {
        if(event.getType() == SCAMMER.get()) {
            event.getTrades().get(1).add(new BasicTrade(1, new ItemStack(Items.DIAMOND, 5), 10, 1, 1f));
            // EXAMPLE TRADE (price, Item, max amount of trades before the "recharge", xp villager gets, price multiplier)
        }
    }
}

1.Replace YOUR MOD ID with your mod id, also call your file as ScammerVillager

2.Call register method in your mod constructor like that: ScammerVillager.register()

3. That should be all

Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
YOO, thanks so much man! You…
Sat, 10/23/2021 - 17:18

YOO, thanks so much man! You are so good! This has worked for me!

Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
NP, if you have any…
Sat, 10/23/2021 - 18:42

NP, if you have any questions just ask!