Skip to content

Commit

Permalink
Rename data map
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Jan 24, 2025
1 parent c768f95 commit 7ab434a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

public static VillagerType byBiome(Holder<Biome> p_204074_) {
+ var fromDataMap = p_204074_.getData(net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps.BIOME_VILLAGERS);
+ var fromDataMap = p_204074_.getData(net.neoforged.neoforge.registries.datamaps.builtin.NeoForgeDataMaps.VILLAGER_TYPES);
+ if (fromDataMap != null) return fromDataMap.type();
+ // TODO - 1.22: remove fallback
return p_204074_.unwrapKey().map(BY_BIOME::get).orElse(PLAINS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import net.minecraft.world.level.storage.loot.LootTable;
import net.neoforged.fml.util.ObfuscationReflectionHelper;
import net.neoforged.neoforge.common.data.DataMapProvider;
import net.neoforged.neoforge.registries.datamaps.builtin.BiomeVillager;
import net.neoforged.neoforge.registries.datamaps.builtin.BiomeVillagerType;
import net.neoforged.neoforge.registries.datamaps.builtin.Compostable;
import net.neoforged.neoforge.registries.datamaps.builtin.FurnaceFuel;
import net.neoforged.neoforge.registries.datamaps.builtin.MonsterRoomMob;
Expand All @@ -58,9 +58,9 @@ public NeoForgeDataMapsProvider(PackOutput packOutput, CompletableFuture<HolderL

@Override
protected void gather(HolderLookup.Provider provider) {
final var biomeVillagers = builder(NeoForgeDataMaps.BIOME_VILLAGERS);
final var biomeVillagers = builder(NeoForgeDataMaps.VILLAGER_TYPES);
ObfuscationReflectionHelper.<Map<ResourceKey<Biome>, VillagerType>, VillagerType>getPrivateValue(VillagerType.class, null, "BY_BIOME")
.forEach((biome, type) -> biomeVillagers.add(biome, new BiomeVillager(type), false));
.forEach((biome, type) -> biomeVillagers.add(biome, new BiomeVillagerType(type), false));

final var compostables = builder(NeoForgeDataMaps.COMPOSTABLES);
final List<Item> villagerCompostables = ObfuscationReflectionHelper.getPrivateValue(WorkAtComposter.class, null, "COMPOSTABLE_ITEMS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import net.minecraft.world.entity.npc.VillagerType;

/**
* Data map value for {@linkplain NeoForgeDataMaps#BIOME_VILLAGERS biome villagers}.
* Data map value for {@linkplain NeoForgeDataMaps#VILLAGER_TYPES biome villager types}.
*
* @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(
public record BiomeVillagerType(VillagerType type) {
public static final Codec<BiomeVillagerType> TYPE_CODEC = BuiltInRegistries.VILLAGER_TYPE.byNameCodec()
.xmap(BiomeVillagerType::new, BiomeVillagerType::type);
public static final Codec<BiomeVillagerType> CODEC = Codec.withAlternative(
RecordCodecBuilder.create(in -> in.group(
BuiltInRegistries.VILLAGER_TYPE.byNameCodec().fieldOf("villager_type").forGetter(BiomeVillager::type)).apply(in, BiomeVillager::new)),
BuiltInRegistries.VILLAGER_TYPE.byNameCodec().fieldOf("villager_type").forGetter(BiomeVillagerType::type)).apply(in, BiomeVillagerType::new)),
TYPE_CODEC);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@
* synced so that mods can use them on the client side.
*/
public class NeoForgeDataMaps {
/**
* The {@linkplain Biome} data map that replaces {@link VillagerType#BY_BIOME}.
* <p>
* The location of this data map is {@code neoforge/data_maps/biome/biome_villagers.json}, and the values are objects with 1 field:
* <ul>
* <li>{@code villager_type}, villager type ID - the type of the villagers present in the biome</li>
* </ul>
*
* The use of a string as the value is also possible, though discouraged in case more options are added in the future.
*/
public static final DataMapType<Biome, BiomeVillager> BIOME_VILLAGERS = DataMapType.builder(
id("biome_villagers"), Registries.BIOME, BiomeVillager.CODEC).synced(BiomeVillager.TYPE_CODEC, false).build();

/**
* The {@linkplain Item} data map that replaces {@link ComposterBlock#COMPOSTABLES}.
* <p>
Expand Down Expand Up @@ -143,6 +130,19 @@ public class NeoForgeDataMaps {
public static final DataMapType<GameEvent, VibrationFrequency> VIBRATION_FREQUENCIES = DataMapType.builder(
id("vibration_frequencies"), Registries.GAME_EVENT, VibrationFrequency.CODEC).synced(VibrationFrequency.FREQUENCY_CODEC, false).build();

/**
* The {@linkplain Biome} data map that replaces {@link VillagerType#BY_BIOME}.
* <p>
* The location of this data map is {@code neoforge/data_maps/worldgen/biome/villager_types.json}, and the values are objects with 1 field:
* <ul>
* <li>{@code villager_type}, villager type ID - the type of the villagers present in the biome</li>
* </ul>
*
* The use of a string as the value is also possible, though discouraged in case more options are added in the future.
*/
public static final DataMapType<Biome, BiomeVillagerType> VILLAGER_TYPES = DataMapType.builder(
id("villager_types"), Registries.BIOME, BiomeVillagerType.CODEC).synced(BiomeVillagerType.TYPE_CODEC, false).build();

/**
* The {@linkplain Block} data map that replaces {@link HoneycombItem#WAXABLES}.
* <p>
Expand All @@ -162,14 +162,14 @@ private static ResourceLocation id(final String name) {

@SubscribeEvent
private static void register(final RegisterDataMapTypesEvent event) {
event.register(BIOME_VILLAGERS);
event.register(COMPOSTABLES);
event.register(FURNACE_FUELS);
event.register(MONSTER_ROOM_MOBS);
event.register(OXIDIZABLES);
event.register(PARROT_IMITATIONS);
event.register(RAID_HERO_GIFTS);
event.register(VIBRATION_FREQUENCIES);
event.register(VILLAGER_TYPES);
event.register(WAXABLES);
}
}

0 comments on commit 7ab434a

Please sign in to comment.