Skip to content

Commit

Permalink
move datamaps in own class and separate registry keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Feb 26, 2024
1 parent d7c6a19 commit fc7362e
Show file tree
Hide file tree
Showing 50 changed files with 210 additions and 173 deletions.
32 changes: 32 additions & 0 deletions src/api/java/de/teamlapen/vampirism/api/VampirismDataMaps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.teamlapen.vampirism.api;

import com.google.common.base.Suppliers;
import de.teamlapen.vampirism.api.datamaps.IConverterEntry;
import de.teamlapen.vampirism.api.datamaps.IEntityBlood;
import de.teamlapen.vampirism.api.datamaps.IFluidBloodConversion;
import de.teamlapen.vampirism.api.datamaps.IItemBlood;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.registries.RegistryManager;
import net.neoforged.neoforge.registries.datamaps.DataMapType;

import java.util.function.Supplier;

@SuppressWarnings({"unused", "unchecked"})
public class VampirismDataMaps {

public static final Supplier<DataMapType<Item, IItemBlood>> ITEM_BLOOD = Suppliers.memoize(() -> (DataMapType<Item, IItemBlood>) RegistryManager.getDataMap(Registries.ITEM, Keys.ITEM_BLOOD));
public static final Supplier<DataMapType<EntityType<?>, IEntityBlood>> ENTITY_BLOOD = Suppliers.memoize(() -> (DataMapType<EntityType<?>, IEntityBlood>) RegistryManager.getDataMap(Registries.ENTITY_TYPE, Keys.ENTITY_BLOOD));
public static final Supplier<DataMapType<Fluid, IFluidBloodConversion>> FLUID_BLOOD_CONVERSION = Suppliers.memoize(() -> (DataMapType<Fluid, IFluidBloodConversion>) RegistryManager.getDataMap(Registries.FLUID, Keys.FLUID_BLOOD_CONVERSION));
public static final Supplier<DataMapType<EntityType<?>, IConverterEntry>> ENTITY_CONVERTER = Suppliers.memoize(() -> (DataMapType<EntityType<?>, IConverterEntry>) RegistryManager.getDataMap(Registries.ENTITY_TYPE, Keys.ENTITY_CONVERTER));

public static class Keys {
public static final ResourceLocation ITEM_BLOOD = new ResourceLocation(VReference.MODID, "item_blood");
public static final ResourceLocation ENTITY_BLOOD = new ResourceLocation(VReference.MODID, "entity_blood");
public static final ResourceLocation FLUID_BLOOD_CONVERSION = new ResourceLocation(VReference.MODID, "fluid_blood_conversion");
public static final ResourceLocation ENTITY_CONVERTER = new ResourceLocation(VReference.MODID, "entity_converter");
}
}
88 changes: 35 additions & 53 deletions src/api/java/de/teamlapen/vampirism/api/VampirismRegistries.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import com.google.common.base.Suppliers;
import com.mojang.serialization.Codec;
import de.teamlapen.vampirism.api.datamaps.IConverterEntry;
import de.teamlapen.vampirism.api.datamaps.IEntityBlood;
import de.teamlapen.vampirism.api.datamaps.IFluidBloodConversion;
import de.teamlapen.vampirism.api.datamaps.IItemBlood;
import de.teamlapen.vampirism.api.entity.actions.IEntityAction;
import de.teamlapen.vampirism.api.entity.convertible.Converter;
import de.teamlapen.vampirism.api.entity.factions.ISkillNode;
Expand All @@ -19,14 +15,8 @@
import de.teamlapen.vampirism.api.items.oil.IOil;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.material.Fluid;
import net.neoforged.neoforge.registries.RegistryManager;
import net.neoforged.neoforge.registries.datamaps.DataMapType;
import org.jetbrains.annotations.NotNull;

import java.util.function.Supplier;
Expand All @@ -37,53 +27,45 @@
@SuppressWarnings({"unused", "unchecked", "rawtypes"})
public class VampirismRegistries {

// builtin registries registries
public static final ResourceKey<Registry<ISkill<?>>> SKILLS_ID = key("skills");
public static final ResourceKey<Registry<IAction<?>>> ACTIONS_ID = key("actions");
public static final ResourceKey<Registry<IEntityAction>> ENTITY_ACTIONS_ID = key("entityactions");
public static final ResourceKey<Registry<IMinionTask<?, ?>>> MINION_TASKS_ID = key("miniontasks");
public static final ResourceKey<Registry<IRefinement>> REFINEMENT_ID = key("refinement");
public static final ResourceKey<Registry<IRefinementSet>> REFINEMENT_SET_ID = key("refinement_set");
public static final ResourceKey<Registry<IOil>> OILS_ID = key("oil");
public static final ResourceKey<Registry<Codec<? extends TaskReward>>> TASK_REWARD_ID = key("task_reward");
public static final ResourceKey<Registry<Codec<? extends TaskUnlocker>>> TASK_UNLOCKER_ID = key("task_unlocker");
public static final ResourceKey<Registry<Codec<? extends TaskRequirement.Requirement<?>>>> TASK_REQUIREMENT_ID = key("task_requirement");
public static final ResourceKey<Registry<Codec<? extends ITaskRewardInstance>>> TASK_REWARD_INSTANCE_ID = key("task_reward_instance");
public static final ResourceKey<Registry<Codec<? extends Converter>>> ENTITY_CONVERTER_ID = key("converting_handler");

// data pack registries
public static final ResourceKey<Registry<Task>> TASK_ID = key("tasks");
public static final ResourceKey<Registry<ISkillNode>> SKILL_NODE_ID = key("skill_node");
public static final ResourceKey<Registry<ISkillTree>> SKILL_TREE_ID = key("skill_tree");
// for registry access in the api
public static final Supplier<Registry<ISkill<?>>> SKILL = Suppliers.memoize(() -> (Registry<ISkill<?>>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.SKILL));
public static final Supplier<Registry<IAction<?>>> ACTION = Suppliers.memoize(() -> (Registry<IAction<?>>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.ACTION));
public static final Supplier<Registry<IEntityAction>> ENTITY_ACTION = Suppliers.memoize(() -> (Registry<IEntityAction>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.ENTITY_ACTION));
public static final Supplier<Registry<IMinionTask<?, ?>>> MINION_TASK = Suppliers.memoize(() -> (Registry<IMinionTask<?, ?>>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.MINION_TASK));
public static final Supplier<Registry<IRefinement>> REFINEMENT = Suppliers.memoize(() -> (Registry<IRefinement>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.REFINEMENT));
public static final Supplier<Registry<IRefinementSet>> REFINEMENT_SET = Suppliers.memoize(() -> (Registry<IRefinementSet>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.REFINEMENT_SET));
public static final Supplier<Registry<IOil>> OIL = Suppliers.memoize(() -> (Registry<IOil>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.OIL));
public static final Supplier<Registry<Codec<? extends TaskReward>>> TASK_REWARD = Suppliers.memoize(() -> (Registry<Codec<? extends TaskReward>>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.TASK_REWARD));
public static final Supplier<Registry<Codec<? extends TaskUnlocker>>> TASK_UNLOCKER = Suppliers.memoize(() -> (Registry<Codec<? extends TaskUnlocker>>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.TASK_UNLOCKER));
public static final Supplier<Registry<Codec<? extends TaskRequirement.Requirement<?>>>> TASK_REQUIREMENT = Suppliers.memoize(() -> (Registry<Codec<? extends TaskRequirement.Requirement<?>>>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.TASK_REQUIREMENT));
public static final Supplier<Registry<Codec<? extends ITaskRewardInstance>>> TASK_REWARD_INSTANCE = Suppliers.memoize(() -> (Registry<Codec<? extends ITaskRewardInstance>>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.TASK_REWARD_INSTANCE));
public static final Supplier<Registry<Codec<? extends Converter>>> ENTITY_CONVERTER = Suppliers.memoize(() -> (Registry<Codec<? extends Converter>>) BuiltInRegistries.REGISTRY.get((ResourceKey) Keys.ENTITY_CONVERTER));

// data maps
public static final ResourceLocation ITEM_BLOOD_MAP_ID = new ResourceLocation(VReference.MODID, "item_blood");
public static final ResourceLocation ENTITY_BLOOD_MAP_ID = new ResourceLocation(VReference.MODID, "entity_blood");
public static final ResourceLocation FLUID_BLOOD_CONVERSION_MAP_ID = new ResourceLocation(VReference.MODID, "fluid_blood_conversion");
public static final ResourceLocation ENTITY_CONVERTER_MAP_ID = new ResourceLocation(VReference.MODID, "entity_converter");
public static class Keys {

// for registry access in the api
public static final Supplier<Registry<ISkill<?>>> SKILLS = Suppliers.memoize(() -> (Registry<ISkill<?>>) BuiltInRegistries.REGISTRY.get((ResourceKey) SKILLS_ID));
public static final Supplier<Registry<IAction<?>>> ACTIONS = Suppliers.memoize(() -> (Registry<IAction<?>>) BuiltInRegistries.REGISTRY.get((ResourceKey) ACTIONS_ID));
public static final Supplier<Registry<IEntityAction>> ENTITY_ACTIONS = Suppliers.memoize(() -> (Registry<IEntityAction>) BuiltInRegistries.REGISTRY.get((ResourceKey) ENTITY_ACTIONS_ID));
public static final Supplier<Registry<IMinionTask<?, ?>>> MINION_TASKS = Suppliers.memoize(() -> (Registry<IMinionTask<?, ?>>) BuiltInRegistries.REGISTRY.get((ResourceKey) MINION_TASKS_ID));
public static final Supplier<Registry<IRefinement>> REFINEMENTS = Suppliers.memoize(() -> (Registry<IRefinement>) BuiltInRegistries.REGISTRY.get((ResourceKey) REFINEMENT_ID));
public static final Supplier<Registry<IRefinementSet>> REFINEMENT_SETS = Suppliers.memoize(() -> (Registry<IRefinementSet>) BuiltInRegistries.REGISTRY.get((ResourceKey) REFINEMENT_SET_ID));
public static final Supplier<Registry<IOil>> OILS = Suppliers.memoize(() -> (Registry<IOil>) BuiltInRegistries.REGISTRY.get((ResourceKey) OILS_ID));
public static final Supplier<Registry<Codec<? extends TaskReward>>> TASK_REWARDS = Suppliers.memoize(() -> (Registry<Codec<? extends TaskReward>>) BuiltInRegistries.REGISTRY.get((ResourceKey) TASK_REWARD_ID));
public static final Supplier<Registry<Codec<? extends TaskUnlocker>>> TASK_UNLOCKER = Suppliers.memoize(() -> (Registry<Codec<? extends TaskUnlocker>>) BuiltInRegistries.REGISTRY.get((ResourceKey) TASK_UNLOCKER_ID));
public static final Supplier<Registry<Codec<? extends TaskRequirement.Requirement<?>>>> TASK_REQUIREMENTS = Suppliers.memoize(() -> (Registry<Codec<? extends TaskRequirement.Requirement<?>>>) BuiltInRegistries.REGISTRY.get((ResourceKey) TASK_REQUIREMENT_ID));
public static final Supplier<Registry<Codec<? extends ITaskRewardInstance>>> TASK_REWARD_INSTANCES = Suppliers.memoize(() -> (Registry<Codec<? extends ITaskRewardInstance>>) BuiltInRegistries.REGISTRY.get((ResourceKey) TASK_REWARD_INSTANCE_ID));
public static final Supplier<Registry<Codec<? extends Converter>>> ENTITY_CONVERTER = Suppliers.memoize(() -> (Registry<Codec<? extends Converter>>) BuiltInRegistries.REGISTRY.get((ResourceKey) ENTITY_CONVERTER_ID));
// builtin registries
public static final ResourceKey<Registry<ISkill<?>>> SKILL = key("skills");
public static final ResourceKey<Registry<IAction<?>>> ACTION = key("actions");
public static final ResourceKey<Registry<IEntityAction>> ENTITY_ACTION = key("entityactions");
public static final ResourceKey<Registry<IMinionTask<?, ?>>> MINION_TASK = key("miniontasks");
public static final ResourceKey<Registry<IRefinement>> REFINEMENT = key("refinement");
public static final ResourceKey<Registry<IRefinementSet>> REFINEMENT_SET = key("refinement_set");
public static final ResourceKey<Registry<IOil>> OIL = key("oil");
public static final ResourceKey<Registry<Codec<? extends TaskReward>>> TASK_REWARD = key("task_reward");
public static final ResourceKey<Registry<Codec<? extends TaskUnlocker>>> TASK_UNLOCKER = key("task_unlocker");
public static final ResourceKey<Registry<Codec<? extends TaskRequirement.Requirement<?>>>> TASK_REQUIREMENT = key("task_requirement");
public static final ResourceKey<Registry<Codec<? extends ITaskRewardInstance>>> TASK_REWARD_INSTANCE = key("task_reward_instance");
public static final ResourceKey<Registry<Codec<? extends Converter>>> ENTITY_CONVERTER = key("converting_handler");

// for data maps access in the api
public static final Supplier<DataMapType<Item, IItemBlood>> ITEM_BLOOD_MAP = Suppliers.memoize(() -> (DataMapType<Item, IItemBlood>) RegistryManager.getDataMap(Registries.ITEM, ITEM_BLOOD_MAP_ID));
public static final Supplier<DataMapType<EntityType<?>, IEntityBlood>> ENTITY_BLOOD_MAP = Suppliers.memoize(() -> (DataMapType<EntityType<?>, IEntityBlood>) RegistryManager.getDataMap(Registries.ENTITY_TYPE, ENTITY_BLOOD_MAP_ID));
public static final Supplier<DataMapType<Fluid, IFluidBloodConversion>> FLUID_BLOOD_CONVERSION_MAP = Suppliers.memoize(() -> (DataMapType<Fluid, IFluidBloodConversion>) RegistryManager.getDataMap(Registries.FLUID, FLUID_BLOOD_CONVERSION_MAP_ID));
public static final Supplier<DataMapType<EntityType<?>, IConverterEntry>> ENTITY_CONVERTER_MAP = Suppliers.memoize(() -> (DataMapType<EntityType<?>, IConverterEntry>) RegistryManager.getDataMap(Registries.ENTITY_TYPE, ENTITY_CONVERTER_MAP_ID));
// data pack registries
public static final ResourceKey<Registry<Task>> TASK = key("tasks");
public static final ResourceKey<Registry<ISkillNode>> SKILL_NODE = key("skill_node");
public static final ResourceKey<Registry<ISkillTree>> SKILL_TREE = key("skill_tree");

private static <T> @NotNull ResourceKey<Registry<T>> key(@NotNull String name) {
return ResourceKey.createRegistryKey(new ResourceLocation(VReference.MODID, name));
private static <T> @NotNull ResourceKey<Registry<T>> key(@NotNull String name) {
return ResourceKey.createRegistryKey(new ResourceLocation(VReference.MODID, name));
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean canBeUsedBy(T player) {
@Override
public @NotNull String getTranslationKey() {
if (this.translationId == null) {
this.translationId = Util.makeDescriptionId("action", VampirismRegistries.ACTIONS.get().getKey(this));
this.translationId = Util.makeDescriptionId("action", VampirismRegistries.ACTION.get().getKey(this));
}
return this.translationId;
}
Expand Down Expand Up @@ -98,6 +98,6 @@ public ISkill<T> asSkill() {
protected abstract boolean activate(T player, ActivationContext context);

private @Nullable ResourceLocation getRegistryName() {
return VampirismRegistries.ACTIONS.get().getKey(this);
return VampirismRegistries.ACTION.get().getKey(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DefaultSkill(@Range(from = 0, to = 9) int skillPointCost) {
@Override
public String getTranslationKey() {
if (this.translationId == null) {
this.translationId = Util.makeDescriptionId("skill", VampirismRegistries.SKILLS.get().getKey(this));
this.translationId = Util.makeDescriptionId("skill", VampirismRegistries.SKILL.get().getKey(this));
}
return translationId;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ private void removeAttributesModifiersFromEntity(@NotNull Player player) {
}

private @Nullable ResourceLocation getRegistryName() {
return VampirismRegistries.SKILLS.get().getKey(this);
return VampirismRegistries.SKILL.get().getKey(this);
}

@Range(from = 0, to = 9)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public interface ITaskRewardInstance {

Codec<ITaskRewardInstance> CODEC = ExtraCodecs.lazyInitializedCodec(() -> VampirismRegistries.TASK_REWARD_INSTANCES.get().byNameCodec()).dispatch(ITaskRewardInstance::codec, Function.identity());
Codec<ITaskRewardInstance> CODEC = ExtraCodecs.lazyInitializedCodec(() -> VampirismRegistries.TASK_REWARD_INSTANCE.get().byNameCodec()).dispatch(ITaskRewardInstance::codec, Function.identity());

/**
* applies the reward to the player upon task completion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Task {
ComponentSerialization.CODEC.fieldOf("title").forGetter(i -> i.title)
).apply(inst, Task::new);
});
public static final Codec<Holder<Task>> HOLDER_CODEC = RegistryFileCodec.create(VampirismRegistries.TASK_ID, CODEC);
public static final Codec<Holder<Task>> HOLDER_CODEC = RegistryFileCodec.create(VampirismRegistries.Keys.TASK, CODEC);

@NotNull
private final TaskRequirement requirements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public boolean isStatBased() {

public interface Requirement<T> {

Codec<Requirement<?>> CODEC = ExtraCodecs.lazyInitializedCodec(() -> VampirismRegistries.TASK_REQUIREMENTS.get().byNameCodec()).dispatch(Requirement::codec, Function.identity());
Codec<Requirement<?>> CODEC = ExtraCodecs.lazyInitializedCodec(() -> VampirismRegistries.TASK_REQUIREMENT.get().byNameCodec()).dispatch(Requirement::codec, Function.identity());

/**
* @return the needed amount of the {@link #getStat(IFactionPlayer)} to complete this requirement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public interface TaskReward {

Codec<TaskReward> CODEC = ExtraCodecs.lazyInitializedCodec(() -> VampirismRegistries.TASK_REWARDS.get().byNameCodec()).dispatch(TaskReward::codec, Function.identity());
Codec<TaskReward> CODEC = ExtraCodecs.lazyInitializedCodec(() -> VampirismRegistries.TASK_REWARD.get().byNameCodec()).dispatch(TaskReward::codec, Function.identity());

ITaskRewardInstance createInstance(IFactionPlayer<?> player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ default void addOilDescTooltip(@NotNull ItemStack stack, @Nullable Level worldIn
if (!stack.hasTag()) return;
CompoundTag tag = stack.getTag().getCompound("applied_oil");
if (tag.contains("oil")) {
IOil oil = VampirismRegistries.OILS.get().get(new ResourceLocation(tag.getString("oil")));
IOil oil = VampirismRegistries.OIL.get().get(new ResourceLocation(tag.getString("oil")));
int duration = tag.getInt("duration");
if (oil instanceof IApplicableOil && duration > 0) {
((IApplicableOil) oil).getToolTipLine(stack, ((IApplicableOil) oil), duration, flagIn).ifPresent(tooltip::add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static <T extends IFactionPlayer<T>> Map<IAction<T>, ISkill<T>> getAction
}

public record EmptyActionSkill<T extends IFactionPlayer<T>>(IAction<T> action) implements IActionSkill<T> {
private static final TagKey<ISkillTree> key = TagKey.create(VampirismRegistries.SKILL_TREE_ID, new ResourceLocation(VReference.MODID, "empty"));
private static final TagKey<ISkillTree> key = TagKey.create(VampirismRegistries.Keys.SKILL_TREE, new ResourceLocation(VReference.MODID, "empty"));
@Override
public @Nullable Component getDescription() {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/teamlapen/vampirism/VampirismMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void prepareAPI() {
.addTag(Registries.POINT_OF_INTEREST_TYPE, ModTags.PoiTypes.IS_VAMPIRE)
.addTag(Registries.VILLAGER_PROFESSION, ModTags.Professions.IS_VAMPIRE)
.addTag(Registries.ENTITY_TYPE, ModTags.Entities.VAMPIRE)
.addTag(VampirismRegistries.TASK_ID, ModTags.Tasks.IS_VAMPIRE)
.addTag(VampirismRegistries.Keys.TASK, ModTags.Tasks.IS_VAMPIRE)
.register();
VReference.HUNTER_FACTION = VampirismAPI.factionRegistry()
.createPlayableFaction(VReference.HUNTER_FACTION_ID, IHunterPlayer.class, () -> (AttachmentType<IHunterPlayer>)(Object) ModAttachments.HUNTER_PLAYER.get())
Expand All @@ -293,7 +293,7 @@ private void prepareAPI() {
.addTag(Registries.POINT_OF_INTEREST_TYPE, ModTags.PoiTypes.IS_HUNTER)
.addTag(Registries.VILLAGER_PROFESSION, ModTags.Professions.IS_HUNTER)
.addTag(Registries.ENTITY_TYPE, ModTags.Entities.HUNTER)
.addTag(VampirismRegistries.TASK_ID, ModTags.Tasks.IS_HUNTER)
.addTag(VampirismRegistries.Keys.TASK, ModTags.Tasks.IS_HUNTER)
.register();

VReference.vision_nightVision = VampirismAPI.vampireVisionRegistry().registerVision(new ResourceLocation(REFERENCE.MODID, "night_vision"), new NightVision());
Expand Down
Loading

0 comments on commit fc7362e

Please sign in to comment.