Jump to content

[1.16] How to remove a villagers default clothes when he changes his profession?


Recommended Posts

Posted (edited)

Sorry if I explain this badly: Basically, I have made a Villager texture and I want to not have the texture for the Villager biome variant appear on them.

Screenshot_600.png?width=264&height=427

This is how I want the Villager to look in-game

Screenshot_602.png?width=334&height=427

This is how he looks in-game.

As you can see, the clothes (In this example the regular Plains Villager) still appear. Is there any way to change this?

Thanks in advance.

 

 

 

Edited by ChonkoTheGreat
Posted

In the Main Class i have:

    private void setup(final FMLCommonSetupEvent event) {
		
		VillagerUtil.fixPOITypeBlockStates(PointOfInterestTypes.HATMAKER);

Then I have VillagerUtil:

public class VillagerUtil
{
    private static Method blockStatesInjector;
    
    static
    {
        VillagerUtil.blockStatesInjector = ObfuscationReflectionHelper.findMethod(PointOfInterestType.class, "func_221052_a", PointOfInterestType.class);
    }
    
    public static Set<BlockState> getAllStates(Block block)
    {
        return ImmutableSet.copyOf(block.getStateContainer().getValidStates());
    }
    
    public static void fixPOITypeBlockStates(PointOfInterestType poiType)
    {
        try
        {
            VillagerUtil.blockStatesInjector.invoke(null, poiType);
        }
        catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
        {
            e.printStackTrace();
        }
    }
    
    public static PointOfInterestType pointOfInterestType(String p1, Set<BlockState> p2, int p3, int p4)
    {
        try
        {
            //          Constructor<PointOfInterestType> c = (Constructor<PointOfInterestType>)PointOfInterestType.class.getDeclaredConstructors()[1];
            Constructor<PointOfInterestType> c = PointOfInterestType.class.getDeclaredConstructor(String.class, Set.class, Integer.TYPE, Integer.TYPE);
            c.setAccessible(true);
            return c.newInstance(p1, p2, p3, p4);
        }
        catch (NoSuchMethodException e)
        {
            e.printStackTrace();
        }
        catch (SecurityException e)
        {
            e.printStackTrace();
        }
        catch (InstantiationException e)
        {
            e.printStackTrace();
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }
        catch (IllegalArgumentException e)
        {
            e.printStackTrace();
        }
        catch (InvocationTargetException e)
        {
            e.printStackTrace();
        }
        
        return null;
    }
    
    public static VillagerProfession villagerProfession(String p1, PointOfInterestType p2, ImmutableSet<Item> p3, ImmutableSet<Block> p4, @Nullable SoundEvent p5)
    {
        try
        {
            Constructor<VillagerProfession> c = VillagerProfession.class.getDeclaredConstructor(String.class, PointOfInterestType.class, ImmutableSet.class, ImmutableSet.class, SoundEvent.class);
            c.setAccessible(true);
            return c.newInstance(p1, p2, p3, p4, p5);
        }
        catch (NoSuchMethodException e)
        {
            e.printStackTrace();
        }
        catch (SecurityException e)
        {
            e.printStackTrace();
        }
        catch (InstantiationException e)
        {
            e.printStackTrace();
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }
        catch (IllegalArgumentException e)
        {
            e.printStackTrace();
        }
        catch (InvocationTargetException e)
        {
            e.printStackTrace();
        }
        
        return null;
    }

}

ProfessionInit:

@EventBusSubscriber(modid = MikesFancyContent.MOD_ID, bus = Bus.MOD)
@ObjectHolder(MikesFancyContent.MOD_ID)
public class ProfessionInit {
  
        public static final VillagerProfession HATMAKER = null;
        
        @SubscribeEvent
        public static void registerVillagerProfessions(Register<VillagerProfession> event)
        {
            IForgeRegistry<VillagerProfession> registry = event.getRegistry();
            
             registry.register(VillagerUtil.villagerProfession("hatmaker", PointOfInterestTypes.HATMAKER, ImmutableSet.of(), ImmutableSet.of(), null).setRegistryName(MikesFancyContent.MOD_ID, "hatmaker"));



   }  
}

TradeRegistration:

@Mod.EventBusSubscriber(modid = MikesFancyContent.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)

public class TradeRegistration {
	
	@SubscribeEvent
    public static void registerTrades(VillagerTradesEvent event){

        if (event.getType() == ProfessionInit.HATMAKER)
        {
        	event.getTrades().get(1).add((new TradeBuilder(64, 25, 0.05F).setPrice(Items.EMERALD, 1,1).setForSale(Items.STRING, 5, 1).build()));
        	event.getTrades().get(1).add((new TradeBuilder(64, 25, 0.05F).setPrice(Items.EMERALD, 1,1).setForSale(Items.FEATHER, 5, 1).build()));
        	
        	event.getTrades().get(2).add((new TradeBuilder(64, 25, 0.2F).setPrice(Items.EMERALD, 1,1).setForSale(Items.WHITE_WOOL, 5, 2).build()));
        	event.getTrades().get(2).add((new TradeBuilder(64, 25, 0.2F).setPrice(Items.EMERALD, 1,1).setForSale(Items.BLACK_WOOL, 1, 2).build()));
        	
            //gonna change the rest soon -mike
        	event.getTrades().get(3).add((new TradeBuilder(64, 25, 0.05F).setPrice(Items.EMERALD, 1,1).setForSale(Items.DIRT, 1, 2).build()));
        	event.getTrades().get(3).add((new TradeBuilder(64, 25, 0.05F).setPrice(Items.EMERALD, 1,1).setForSale(Items.DIRT, 1, 2).build()));
        	
        	event.getTrades().get(4).add((new TradeBuilder(64, 25, 0.2F).setPrice(Items.EMERALD, 1,1).setForSale(Items.DIRT, 1, 2).build()));
        	event.getTrades().get(4).add((new TradeBuilder(64, 25, 0.2F).setPrice(Items.EMERALD, 1,1).setForSale(Items.DIRT, 1, 2).build()));
        	
        	event.getTrades().get(5).add((new TradeBuilder(64, 25, 0.2F).setPrice(Items.EMERALD, 1,1).setForSale(Items.DIRT, 1, 2).build()));    
        	event.getTrades().get(5).add((new TradeBuilder(64, 50, 0.05F).setPrice(Items.EMERALD, 3,6).setForSale(Items.DIRT, 1, 1).build()));    
        }

TradeBuilder:

public class TradeBuilder {
    private static final ArrayList<ArrayList<TradeBuilder>> TRADES_LIST = new ArrayList<>();
    
    static
    {
        for(int i = 0; i <= 6; ++i)
        {
            TradeBuilder.TRADES_LIST.add(new ArrayList<TradeBuilder>());
        }
    }
    
    private static ArrayList<TradeBuilder> getList(int i)
    {
        return TradeBuilder.TRADES_LIST.get(i);
    }
    
    private static void register(int i, TradeBuilder tradeBuilder)
    {
        TradeBuilder.getList(i).add(tradeBuilder);
    }
    
    public static void forEachLevel(BiConsumer<Integer, TradeBuilder> consumer)
    {
        ArrayList<TradeBuilder> list;
        
        for(int i = 1; i <= 5; ++i)
        {
            list = TradeBuilder.TRADES_LIST.get(i - 1);
            
            for(TradeBuilder tradeBuilder : list)
            {
                consumer.accept(i, tradeBuilder);
            }
        }
    }
    
    public static void forEachLevel(Consumer<TradeBuilder> consumer)
    {
        TradeBuilder.forEachLevel((level, tradeBuilder) -> consumer.accept(tradeBuilder));
    }
    
    public static void forEachWanderer(Consumer<TradeBuilder> consumer)
    {
        ArrayList<TradeBuilder> list = TradeBuilder.TRADES_LIST.get(5);
        
        for(TradeBuilder tradeBuilder : list)
        {
            consumer.accept(tradeBuilder);
        }
    }
    
    public static void forEachWandererRare(Consumer<TradeBuilder> consumer)
    {
        ArrayList<TradeBuilder> list = TradeBuilder.TRADES_LIST.get(6);
        
        for(TradeBuilder tradeBuilder : list)
        {
            consumer.accept(tradeBuilder);
        }
    }
    
    protected Function<Random, ItemStack> price;
    protected Function<Random, ItemStack> price2;
    protected Function<Random, ItemStack> forSale;
    
    protected final int maxTrades;
    protected final int xp;
    protected final float priceMult;
    
    protected boolean rare;
    
    public TradeBuilder(int maxTrades, int xp, float priceMult)
    {
        this.price = null;
        this.price2 = (random) -> ItemStack.EMPTY;
        this.forSale = null;
        this.maxTrades = maxTrades;
        this.xp = xp;
        this.priceMult = priceMult;
        this.rare = false;
    }
    
    public TradeBuilder setPrice(Function<Random, ItemStack> price)
    {
        this.price = price;
        return this;
    }
    
    public TradeBuilder setPrice(Item item, int min, int max)
    {
        return this.setPrice(TradeBuilder.createFunction(item, min, max));
    }
    
    public TradeBuilder setPrice2(Function<Random, ItemStack> price2)
    {
        this.price2 = price2;
        return this;
    }
    
    public TradeBuilder setPrice2(Item item, int min, int max)
    {
        return this.setPrice2(TradeBuilder.createFunction(item, min, max));
    }
    
    public TradeBuilder setForSale(Function<Random, ItemStack> forSale)
    {
        this.forSale = forSale;
        return this;
    }
    
    public TradeBuilder setForSale(Item item, int min, int max)
    {
        return this.setForSale(TradeBuilder.createFunction(item, min, max));
    }
    
    public TradeBuilder setForSale(MusicDiscItem item, int min, int max)
    {
        return this.setForSale(TradeBuilder.createFunction(item, min, max));
    }

    public TradeBuilder setForSale(RegistryObject<MusicDiscItem> item, int min, int max)
    {
        return this.setForSale(TradeBuilder.createFunction(item, min, max));
    }
    

	public TradeBuilder setEmeraldPrice(int emeralds)
    {
        return this.setPrice((random) -> new ItemStack(Items.EMERALD, emeralds));
    }
    
    public TradeBuilder setEmeraldPriceFor(int emeralds, Item item, int amt)
    {
        this.setEmeraldPrice(emeralds);
        return this.setForSale((random) -> new ItemStack(item, amt));
    }
    
    public TradeBuilder setEmeraldPriceFor(int emeralds, Item item)
    {
        return this.setEmeraldPriceFor(emeralds, item, 1);
    }
    
    public TradeBuilder setEmeraldPrice(int min, int max)
    {
        return this.setPrice(Items.EMERALD, min, max);
    }
    
    public TradeBuilder setEmeraldPriceFor(int min, int max, Item item, int amt)
    {
        this.setEmeraldPrice(min, max);
        return this.setForSale((random) -> new ItemStack(item, amt));
    }
    
    public TradeBuilder setEmeraldPriceFor(int min, int max, Item item)
    {
        return this.setEmeraldPriceFor(min, max, item, 1);
    }
    
    public TradeBuilder setRare()
    {
        this.rare = true;
        return this;
    }
    
    public boolean canBuild()
    {
        return this.price != null && this.forSale != null;
    }
    
    public ITrade build()
    {
        return (entity, random) -> !this.canBuild() ? null : new MerchantOffer(this.price.apply(random), this.price2.apply(random), this.forSale.apply(random), this.maxTrades, this.xp, this.priceMult);
    }
    
    public static Function<Random, ItemStack> createFunction(Item item, int min, int max)
    {
        return (random) -> new ItemStack(item, random.nextInt(max) + min);
    }
    
    protected TradeBuilder register(int index)
    {
        TradeBuilder.register(index, this);
        return this;
    }
    
    /**
     * @param level 1-5
     */
    public TradeBuilder registerLevel(int level)
    {
        return this.register(level - 1);
    }
    
    public TradeBuilder registerWanderer(boolean rare)
    {
        return this.register(rare ? 6 : 5);
    }
}

and lastly, PointOfInterestTypes:

@EventBusSubscriber(modid = MikesFancyContent.MOD_ID, bus = Bus.MOD)
@ObjectHolder(MikesFancyContent.MOD_ID)
public class PointOfInterestTypes {
	
	public static final PointOfInterestType HATMAKER = null;
	
	@SubscribeEvent
    public static void registerPointOfInterestTypes(Register<PointOfInterestType> event)
    {	
        IForgeRegistry<PointOfInterestType> registry = event.getRegistry();

        registry.register(VillagerUtil.pointOfInterestType("hatmaker", VillagerUtil.getAllStates(BlockInit.HATMAKER_POI.get()), 1, 1).setRegistryName(MikesFancyContent.MOD_ID, "hatmaker"));

        

   }
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Sorry for the late response, but the game opened and I made a world but it's stuck at 0% Here's the latest.log https://mclo.gs/peEb1R8 I disabled The Factory Must Grow and soulsweapons
    • Hey everyone! Two of my friends downloaded this modpack and are having an issue with the blocks loading in correctly. Grass looks like bamboo, waystones look like two barrels stacked on eachother, and wheat looks like water and stairs. What is this problem? How can we fix it? Neither of my other friends or myself had this issue. 
    • I removed Yung's cave biome mod and It wasnt in one of those biomes however the log file said the same line (([25Apr2025 21:20:15.500] [Flywheel Task Executor #5/WARN] [Embeddium-MixinTaintDetector/]: Mod(s) [oculus] are modifying Embeddium class me.jellysquid.mods.sodium.client.render.vertex.serializers.VertexSerializerRegistryImpl, which may cause instability.))
    • Note: i had a couple of ideas, but i just don't know how to execute them. The main idea was to make the new block (let's exemplify with a mixer) be essentially a clone of the mechanical mixer (different texture tho) that would have a different recipe type (instead of mixing, advanced_mixing) and i would copy all the create mod recipes and edit the processing time while also adding the tier dependent ones.
    • Hi! Before everything, thank you for even reading. I'm coming here in need of help making a few aspects for a create mod addon. It's an addon that aims to add almost the full periodic table with realistic ways of obtaining all the elements and capability of almost full automation. For what purpose? A techy armor and to go to the moon and rocky planets of the solar system. It'll have 3 different tiers of machines (mixer, millstone, crushing wheels): basic (just the normal create mod machines but renamed), advanced (25% faster and has recipes only possible for this tier and above) end elite (75% faster than basic and recipes only available for this tier). The problem is, I'm not a coder. I know less than the basics. I know how to do everything else but these machine tiers and i need some help if you can.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.