Skip to content

Commit 40b96ee

Browse files
committed
Added villager trade
1 parent b65361b commit 40b96ee

File tree

6 files changed

+82
-4
lines changed

6 files changed

+82
-4
lines changed

src/main/resources/forge-1.12.2/mappings/villagerprofessions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
_default: VillagerRegistry.getById(3).getCareer(0)
2-
_mcreator_map_template: "@JavaModNameVillagerProfessions.@REGISTRYNAME"
2+
_mcreator_map_template: "@JavaModNameVillagerProfessions.@REGISTRYNAME_CAREER"
33
ARMORER: VillagerRegistry.getById(3).getCareer(0)
44
BUTCHER: VillagerRegistry.getById(4).getCareer(0)
55
CARTOGRAPHER: VillagerRegistry.getById(1).getCareer(1)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<#--
2+
# MCreator (https://mcreator.net/)
3+
# Copyright (C) 2012-2020, Pylo
4+
# Copyright (C) 2020-2025, Pylo, opensource contributors
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
#
19+
# Additional permission for code generator templates (*.ftl files)
20+
#
21+
# As a special exception, you may create a larger work that contains part or
22+
# all of the MCreator code generator templates (*.ftl files) and distribute
23+
# that work under terms of your choice, so long as that work isn't itself a
24+
# template for code generation. Alternatively, if you modify or redistribute
25+
# the template itself, you may (at your option) remove this special exception,
26+
# which will cause the template and the resulting code generator output files
27+
# to be licensed under the GNU General Public License without this special
28+
# exception.
29+
-->
30+
31+
<#-- @formatter:off -->
32+
<#include "../mcitems.ftl">
33+
/*
34+
* MCreator note: This file will be REGENERATED on each build.
35+
*/
36+
package ${package}.init;
37+
38+
public class ${JavaModName}Trades {
39+
40+
<#if w.getGElementsOfType("villagertrade")?filter(e -> e.hasVillagerTrades(false))?size != 0>
41+
public static void load() {
42+
<#list villagertrades as trade>
43+
<#list trade.tradeEntries as tradeEntry>
44+
<#if tradeEntry.villagerProfession != "WanderingTrader">
45+
<#list tradeEntry.entries as entry>
46+
${tradeEntry.villagerProfession}.addTrade(${entry.level}, (merchant, recipeList, random) -> {
47+
NBTTagCompound nbtTag = new NBTTagCompound();
48+
nbtTag.setTag("buy", ${mappedMCItemToItemStackCode(entry.price1, entry.countPrice1)}.serializeNBT());
49+
<#if !entry.price2.isEmpty()>nbtTag.setTag("buyB", ${mappedMCItemToItemStackCode(entry.price2, entry.countPrice2)}.serializeNBT());</#if>
50+
nbtTag.setTag("sell", ${mappedMCItemToItemStackCode(entry.offer, entry.countOffer)}.serializeNBT());
51+
nbtTag.setInteger("maxUses", ${entry.maxTrades});
52+
<#if (entry.xp > 0)>nbtTag.setBoolean("rewardExp", false);</#if>
53+
recipeList.add(new MerchantRecipe(nbtTag));
54+
});
55+
</#list>
56+
</#if>
57+
</#list>
58+
</#list>
59+
}
60+
</#if>
61+
}

src/main/resources/forge-1.12.2/templates/modbase/mod.java.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import org.apache.logging.log4j.Logger;
4949
<#if w.hasElementsOfType("loottable")>${JavaModName}Loottables.load();</#if>
5050
<#if w.hasElementsOfType("keybind")>${JavaModName}KeyMappings.registerKeyBindings();</#if>
5151
<#if w.getGElementsOfType('itemextension')?filter(e -> e.hasDispenseBehavior)?size != 0>${JavaModName}ItemExtensions.load();</#if>
52+
<#if w.hasElementsOfType("villagertrade")>${JavaModName}Trades.load();</#if>
5253
proxy.init(event);
5354
}
5455

src/main/resources/forge-1.12.2/templates/potioneffect.java.ftl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<#--
22
# MCreator (https://mcreator.net/)
33
# Copyright (C) 2012-2020, Pylo
4-
# Copyright (C) 2020-2023, Pylo, opensource contributors
4+
# Copyright (C) 2020-2025, Pylo, opensource contributors
55
#
66
# This program is free software: you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -35,6 +35,7 @@ package ${package}.potion;
3535

3636
<#compress>
3737
public class ${name}MobEffect extends Potion {
38+
private final ResourceLocation potionIcon;
3839

3940
public ${name}MobEffect() {
4041
super(${data.mobEffectCategory == "BENEFICIAL"}, ${data.color.getRGB()});
@@ -43,7 +44,8 @@ public class ${name}MobEffect extends Potion {
4344
this.registerPotionAttributeModifier(${modifier.attribute}, "${w.getUUID(registryname + "_" + modifier?index)}", ${modifier.amount},
4445
${getAttributeOperation(modifier.operation)});
4546
</#list>
46-
}
47+
potionIcon = new ResourceLocation("${modid}:textures/mob_effect/${registryname}.png");
48+
}
4749

4850
<#if data.mobEffectCategory == "BENEFICIAL">
4951
@Override public boolean isBeneficial() {
@@ -122,6 +124,16 @@ public class ${name}MobEffect extends Potion {
122124
}
123125
</#if>
124126
</#if>
127+
128+
@Override @SideOnly(Side.CLIENT) public void renderInventoryEffect(PotionEffect effect, Gui gui, int x, int y, float z) {
129+
Minecraft.getMinecraft().getTextureManager().bindTexture(potionIcon);
130+
gui.drawModalRectWithCustomSizedTexture(x + 6, y + 7, 0, 0, 18, 18, 18, 18);
131+
}
132+
133+
@Override @SideOnly(Side.CLIENT) public void renderHUDEffect(PotionEffect effect, Gui gui, int x, int y, float z, float alpha) {
134+
Minecraft.getMinecraft().getTextureManager().bindTexture(potionIcon);
135+
gui.drawModalRectWithCustomSizedTexture(x + 3, y + 3, 0, 0, 18, 18, 18, 18);
136+
}
125137
}
126138
</#compress>
127139
<#-- @formatter:on -->

src/main/resources/forge-1.12.2/villagerprofession.definition.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ global_templates:
33
name: "@SRCROOT/@BASEPACKAGEPATH/init/@JavaModNameVillagerProfessions.java"
44

55
localizationkeys:
6-
- key: entity.minecraft.villager.@modid.@registryname
6+
- key: entity.Villager.@registryname
77
mapto: displayName
88

99
field_exclusions: [pointOfInterest, actionSound, hat]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
global_templates:
2+
- template: elementinits/villagertrades.java.ftl
3+
writer: java
4+
name: "@SRCROOT/@BASEPACKAGEPATH/init/@JavaModNameTrades.java"

0 commit comments

Comments
 (0)