-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a biome villagers data map to replace
VillagerType#BY_BIOME
This PR adds a `neoforge:biome_villagers` biome data map to replace `VillagerType#BY_BIOME`, allowing mods to change the type of the villagers spawned in their own biomes. To avoid a sudden breaking change, the map will still be used for now, but the fallback to it will be removed in 1.22.
- Loading branch information
1 parent
1fabdf8
commit c768f95
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
patches/net/minecraft/world/entity/npc/VillagerType.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- a/net/minecraft/world/entity/npc/VillagerType.java | ||
+++ b/net/minecraft/world/entity/npc/VillagerType.java | ||
@@ -21,6 +_,8 @@ | ||
public static final VillagerType SWAMP = register("swamp"); | ||
public static final VillagerType TAIGA = register("taiga"); | ||
private final String name; | ||
+ /** Neo: use the {@link net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps.BIOME_VILLAGERS data map} instead as this field will be ignored in future versions */ | ||
+ @Deprecated | ||
private static final Map<ResourceKey<Biome>, VillagerType> BY_BIOME = Util.make(Maps.newHashMap(), p_35834_ -> { | ||
p_35834_.put(Biomes.BADLANDS, DESERT); | ||
p_35834_.put(Biomes.DESERT, DESERT); | ||
@@ -67,6 +_,9 @@ | ||
} | ||
|
||
public static VillagerType byBiome(Holder<Biome> p_204074_) { | ||
+ var fromDataMap = p_204074_.getData(net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps.BIOME_VILLAGERS); | ||
+ if (fromDataMap != null) return fromDataMap.type(); | ||
+ // TODO - 1.22: remove fallback | ||
return p_204074_.unwrapKey().map(BY_BIOME::get).orElse(PLAINS); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/generated/resources/data/neoforge/data_maps/worldgen/biome/biome_villagers.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{ | ||
"values": { | ||
"minecraft:badlands": { | ||
"villager_type": "minecraft:desert" | ||
}, | ||
"minecraft:bamboo_jungle": { | ||
"villager_type": "minecraft:jungle" | ||
}, | ||
"minecraft:deep_frozen_ocean": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:desert": { | ||
"villager_type": "minecraft:desert" | ||
}, | ||
"minecraft:eroded_badlands": { | ||
"villager_type": "minecraft:desert" | ||
}, | ||
"minecraft:frozen_ocean": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:frozen_peaks": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:frozen_river": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:grove": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:ice_spikes": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:jagged_peaks": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:jungle": { | ||
"villager_type": "minecraft:jungle" | ||
}, | ||
"minecraft:mangrove_swamp": { | ||
"villager_type": "minecraft:swamp" | ||
}, | ||
"minecraft:old_growth_pine_taiga": { | ||
"villager_type": "minecraft:taiga" | ||
}, | ||
"minecraft:old_growth_spruce_taiga": { | ||
"villager_type": "minecraft:taiga" | ||
}, | ||
"minecraft:savanna": { | ||
"villager_type": "minecraft:savanna" | ||
}, | ||
"minecraft:savanna_plateau": { | ||
"villager_type": "minecraft:savanna" | ||
}, | ||
"minecraft:snowy_beach": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:snowy_plains": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:snowy_slopes": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:snowy_taiga": { | ||
"villager_type": "minecraft:snow" | ||
}, | ||
"minecraft:sparse_jungle": { | ||
"villager_type": "minecraft:jungle" | ||
}, | ||
"minecraft:swamp": { | ||
"villager_type": "minecraft:swamp" | ||
}, | ||
"minecraft:taiga": { | ||
"villager_type": "minecraft:taiga" | ||
}, | ||
"minecraft:windswept_forest": { | ||
"villager_type": "minecraft:taiga" | ||
}, | ||
"minecraft:windswept_gravelly_hills": { | ||
"villager_type": "minecraft:taiga" | ||
}, | ||
"minecraft:windswept_hills": { | ||
"villager_type": "minecraft:taiga" | ||
}, | ||
"minecraft:windswept_savanna": { | ||
"villager_type": "minecraft:savanna" | ||
}, | ||
"minecraft:wooded_badlands": { | ||
"villager_type": "minecraft:desert" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/net/neoforged/neoforge/registries/datamaps/builtin/BiomeVillager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.registries.datamaps.builtin; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.entity.npc.VillagerType; | ||
|
||
/** | ||
* Data map value for {@linkplain NeoForgeDataMaps#BIOME_VILLAGERS biome villagers}. | ||
* | ||
* @param type the type of the villagers present in this biome | ||
*/ | ||
public record BiomeVillager(VillagerType type) { | ||
public static final Codec<BiomeVillager> TYPE_CODEC = BuiltInRegistries.VILLAGER_TYPE.byNameCodec() | ||
.xmap(BiomeVillager::new, BiomeVillager::type); | ||
public static final Codec<BiomeVillager> CODEC = Codec.withAlternative( | ||
RecordCodecBuilder.create(in -> in.group( | ||
BuiltInRegistries.VILLAGER_TYPE.byNameCodec().fieldOf("villager_type").forGetter(BiomeVillager::type)).apply(in, BiomeVillager::new)), | ||
TYPE_CODEC); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters