diff --git a/src/api/java/de/teamlapen/vampirism/api/APIUtil.java b/src/api/java/de/teamlapen/vampirism/api/APIUtil.java index 44c06c06d4..5584c056b5 100644 --- a/src/api/java/de/teamlapen/vampirism/api/APIUtil.java +++ b/src/api/java/de/teamlapen/vampirism/api/APIUtil.java @@ -1,15 +1,16 @@ package de.teamlapen.vampirism.api; import com.google.common.base.Suppliers; -import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; -import de.teamlapen.vampirism.api.entity.player.actions.IAction; -import de.teamlapen.vampirism.api.entity.player.actions.ILastingAction; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; +import de.teamlapen.vampirism.api.registries.DeferredFaction; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.component.DataComponentType; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.RegistryManager; import net.neoforged.neoforge.registries.datamaps.DataMapType; @@ -36,4 +37,9 @@ static Supplier supplyRegistry(ResourceKey key) { static ResourceKey> registryKey(String name) { return ResourceKey.createRegistryKey(new ResourceLocation(VReference.MODID, name)); } + + @SuppressWarnings("unchecked") + static > DeferredFaction factionHolder(ResourceLocation key) { + return DeferredFaction.createFaction((ResourceKey) ResourceKey.create(VampirismRegistries.Keys.FACTION, key)); + } } diff --git a/src/api/java/de/teamlapen/vampirism/api/VReference.java b/src/api/java/de/teamlapen/vampirism/api/VReference.java index 6a0d904bcb..ed991745b2 100755 --- a/src/api/java/de/teamlapen/vampirism/api/VReference.java +++ b/src/api/java/de/teamlapen/vampirism/api/VReference.java @@ -40,14 +40,14 @@ public class VReference { */ public static MobCategory VAMPIRE_CREATURE_TYPE = MobCategory.create("vampirism_vampire", "vampirism_vampire", 30, false, false, 128); /** - * Vampire Player Faction - * Filled during pre-init. + * @deprecated use {@link de.teamlapen.vampirism.api.VampirismFactions#VAMPIRE} */ + @Deprecated public static IPlayableFaction VAMPIRE_FACTION; /** - * Hunter Player Faction - * Filled during pre-init. + * @deprecated use {@link de.teamlapen.vampirism.api.VampirismFactions#HUNTER} */ + @Deprecated public static IPlayableFaction HUNTER_FACTION; public static IVampireVision vision_nightVision; public static IVampireVision vision_bloodVision; diff --git a/src/api/java/de/teamlapen/vampirism/api/VampirismFactions.java b/src/api/java/de/teamlapen/vampirism/api/VampirismFactions.java new file mode 100644 index 0000000000..b55d0eb8c7 --- /dev/null +++ b/src/api/java/de/teamlapen/vampirism/api/VampirismFactions.java @@ -0,0 +1,19 @@ +package de.teamlapen.vampirism.api; + +import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; +import de.teamlapen.vampirism.api.entity.player.hunter.IHunterPlayer; +import de.teamlapen.vampirism.api.entity.player.vampire.IVampirePlayer; +import de.teamlapen.vampirism.api.registries.DeferredFaction; +import net.minecraft.resources.ResourceLocation; + +import static de.teamlapen.vampirism.api.APIUtil.*; + +public class VampirismFactions { + public static final DeferredFaction> VAMPIRE = factionHolder(Keys.VAMPIRE); + public static final DeferredFaction> HUNTER = factionHolder(Keys.HUNTER); + + public static class Keys { + public static final ResourceLocation VAMPIRE = new ResourceLocation(VReference.MODID, "vampire"); + public static final ResourceLocation HUNTER = new ResourceLocation(VReference.MODID, "hunter"); + } +} diff --git a/src/api/java/de/teamlapen/vampirism/api/VampirismRegistries.java b/src/api/java/de/teamlapen/vampirism/api/VampirismRegistries.java index 35dafb8933..f7c72b6668 100644 --- a/src/api/java/de/teamlapen/vampirism/api/VampirismRegistries.java +++ b/src/api/java/de/teamlapen/vampirism/api/VampirismRegistries.java @@ -2,6 +2,7 @@ import com.mojang.serialization.MapCodec; import de.teamlapen.vampirism.api.entity.convertible.Converter; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.ISkillNode; import de.teamlapen.vampirism.api.entity.factions.ISkillTree; import de.teamlapen.vampirism.api.entity.minion.IMinionTask; @@ -37,6 +38,7 @@ public class VampirismRegistries { public static final Supplier>>> TASK_REQUIREMENT = supplyRegistry(Keys.TASK_REQUIREMENT); public static final Supplier>> TASK_REWARD_INSTANCE = supplyRegistry(Keys.TASK_REWARD_INSTANCE); public static final Supplier>> ENTITY_CONVERTER = supplyRegistry(Keys.ENTITY_CONVERTER); + public static final Supplier>> FACTION = supplyRegistry(Keys.FACTION); public static class Keys { @@ -53,6 +55,7 @@ public static class Keys { public static final ResourceKey>>> TASK_REQUIREMENT = registryKey("task_requirement"); public static final ResourceKey>> TASK_REWARD_INSTANCE = registryKey("task_reward_instance"); public static final ResourceKey>> ENTITY_CONVERTER = registryKey("converting_handler"); + public static final ResourceKey>> FACTION = registryKey("faction"); // data pack registries public static final ResourceKey> TASK = registryKey("tasks"); diff --git a/src/api/java/de/teamlapen/vampirism/api/VampirismTags.java b/src/api/java/de/teamlapen/vampirism/api/VampirismTags.java new file mode 100644 index 0000000000..0d171f0fb3 --- /dev/null +++ b/src/api/java/de/teamlapen/vampirism/api/VampirismTags.java @@ -0,0 +1,20 @@ +package de.teamlapen.vampirism.api; + +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import org.jetbrains.annotations.NotNull; + +public class VampirismTags { + + public static class Factions { + public static final TagKey> ALL_FACTIONS = tag("all"); + public static final TagKey> IS_HUNTER = tag("is_hunter"); + public static final TagKey> IS_VAMPIRE = tag("is_vampire"); + + private static @NotNull TagKey> tag(@NotNull String name) { + return TagKey.create(VampirismRegistries.Keys.FACTION, new ResourceLocation(VReference.MODID, name)); + } + + } +} diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IDisguise.java b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IDisguise.java index 0da744bd17..757e0079a5 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IDisguise.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IDisguise.java @@ -1,22 +1,23 @@ package de.teamlapen.vampirism.api.entity.factions; +import net.minecraft.core.Holder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public interface IDisguise { @NotNull - IPlayableFaction getOriginalFaction(); + Holder> getOriginalFaction(); @Nullable - IPlayableFaction getViewedFaction(@Nullable IFaction viewerFaction); + Holder> getViewedFaction(@Nullable Holder> viewerFaction); @Nullable - default IPlayableFaction getViewedFaction(@Nullable IFaction viewerFaction, boolean ignoreDisguise) { + default Holder> getViewedFaction(@Nullable Holder> viewerFaction, boolean ignoreDisguise) { return ignoreDisguise ? getOriginalFaction() : getViewedFaction(viewerFaction); } - void disguiseAs(@Nullable IPlayableFaction faction); + void disguiseAs(@Nullable Holder> faction); void unDisguise(); diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFaction.java b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFaction.java index 1a91ecc5fb..535bdcbed6 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFaction.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFaction.java @@ -3,6 +3,7 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import de.teamlapen.vampirism.api.VampirismAPI; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextColor; @@ -11,6 +12,7 @@ import net.minecraft.tags.TagKey; import net.minecraft.world.entity.PathfinderMob; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -19,8 +21,6 @@ */ public interface IFaction { - Codec> CODEC = RecordCodecBuilder.create(ins -> ins.group(ResourceLocation.CODEC.fieldOf("id").forGetter(IFaction::getID)).apply(ins, (id) -> VampirismAPI.factionRegistry().getFactionByID(id))); - /** * If not set returns white */ @@ -61,9 +61,30 @@ public interface IFaction { /** * @return Whether entities of this faction are hostile towards neutral entities + * @deprecated use HostileTowardsNeutral tag instead */ + @Deprecated boolean isHostileTowardsNeutral(); Optional> getTag(ResourceKey> registryKey); + @SuppressWarnings({"deprecation", "unchecked", "rawtypes"}) + static boolean is(@Nullable Holder> first, @Nullable Holder> second) { + if (first == null) { + return second == null; + } + return second != null && first.is((Holder) second); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + static > boolean is(@Nullable Holder> first, @Nullable TagKey second) { + if (first == null) { + return second == null; + } + return second != null && first.is((TagKey) second); + } + + static , Z extends IFaction> boolean is(TagKey first, TagKey second) { + return first.location().equals(second.location()); + } } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionEntity.java b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionEntity.java index 837b987214..38fec5e44f 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionEntity.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionEntity.java @@ -1,6 +1,7 @@ package de.teamlapen.vampirism.api.entity.factions; import de.teamlapen.vampirism.api.extensions.IEntity; +import net.minecraft.core.Holder; import net.minecraft.world.entity.LivingEntity; import org.jetbrains.annotations.NotNull; @@ -12,7 +13,7 @@ public interface IFactionEntity extends IEntity { * @return the faction this entity belongs to */ @NotNull - IFaction getFaction(); + Holder> getFaction(); /** * Can be the same object or for Player Capabilities the player object diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionPlayerHandler.java b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionPlayerHandler.java index 76c06ab823..0433d3be6e 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionPlayerHandler.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionPlayerHandler.java @@ -3,6 +3,7 @@ import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.ILordPlayer; import de.teamlapen.vampirism.api.extensions.IPlayer; +import net.minecraft.core.Holder; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.NotNull; @@ -23,6 +24,8 @@ public interface IFactionPlayerHandler extends ILordPlayer, IPlayer { */ boolean canJoin(IPlayableFaction faction); + boolean canJoin(Holder> faction); + /** * Checks currents factions {@link IFactionPlayer#canLeaveFaction()} */ @@ -34,6 +37,9 @@ public interface IFactionPlayerHandler extends ILordPlayer, IPlayer { @Nullable > IPlayableFaction getCurrentFaction(); + @Nullable + Holder> getFaction(); + /** * @return The currently active faction player. Can be null */ @@ -56,6 +62,8 @@ public interface IFactionPlayerHandler extends ILordPlayer, IPlayer { */ int getCurrentLevel(IPlayableFaction f); + int getCurrentLevel(Holder> f); + /** * If not in faction returns 0f * @@ -76,12 +84,17 @@ public interface IFactionPlayerHandler extends ILordPlayer, IPlayer { */ boolean isInFaction(IFaction f); + > boolean isInFaction(Holder f); + /** * Join the given faction and set the faction level to 1. * Only successful if {@link IFactionPlayerHandler#canJoin(IPlayableFaction)} */ void joinFaction(@NotNull IPlayableFaction faction); + + void joinFaction(@NotNull Holder> faction); + /** * Should be called if the entity attacked. * If this returns false the attack should be canceled @@ -97,12 +110,17 @@ public interface IFactionPlayerHandler extends ILordPlayer, IPlayer { */ boolean setFactionAndLevel(@Nullable IPlayableFaction faction, int level); + boolean setFactionAndLevel(@Nullable Holder> faction, int level); + /** * Set the level for a faction. Only works if the player already is in the given faction. * Use {@link IFactionPlayerHandler#joinFaction(IPlayableFaction)} to join a faction first or {@link IFactionPlayerHandler#setFactionAndLevel(IPlayableFaction, int)} if you are sure what you do * * @return If successful */ + boolean setFactionLevel(@NotNull Holder> faction, int level); + + boolean setFactionLevel(@NotNull IPlayableFaction faction, int level); /** diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionRegistry.java b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionRegistry.java index 4bd5669304..8d5df56395 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionRegistry.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IFactionRegistry.java @@ -4,6 +4,8 @@ import de.teamlapen.vampirism.api.entity.minion.IMinionData; import de.teamlapen.vampirism.api.entity.minion.IMinionEntity; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; +import de.teamlapen.vampirism.api.util.RegUtil; +import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -29,31 +31,44 @@ public interface IFactionRegistry { * @param entity Can check any entity * @return The faction of the given entity or null */ + @Deprecated @Nullable IFaction getFaction(Entity entity); + Holder> getFactionHolder(Entity entity); + /** * Get a faction by its name */ + @Deprecated @Nullable IFaction getFactionByID(ResourceLocation id); /** * @return All factions after post init */ + @Deprecated IFaction[] getFactions(); /** * @return All playable factions after post init */ + @Deprecated IPlayableFaction[] getPlayableFactions(); + List>> playableFactions(); + /** * Get a cached or create a predicate which selects all other faction entities * * @param ignoreDisguise If disguised players should still be counted for their actual faction (disguised vampires will still be detected as vampires) */ - Predicate getPredicate(IFaction thisFaction, boolean ignoreDisguise); + @Deprecated + default Predicate getPredicate(IFaction thisFaction, boolean ignoreDisguise) { + return getPredicate(RegUtil.holder(thisFaction), ignoreDisguise); + } + + Predicate getPredicate(Holder> thisFaction, boolean ignoreDisguise); /** * Get a cached or create a predicate which selects entities from other factions. @@ -65,8 +80,11 @@ public interface IFactionRegistry { * @param ignoreDisguise If disguised players should still be counted for their actual faction (disguised vampires will still be detected as vampires) * @param otherFaction If this is not null, only entities of this faction are selected. */ + @Deprecated Predicate getPredicate(IFaction thisFaction, boolean player, boolean mob, boolean neutralPlayer, boolean ignoreDisguise, @Nullable IFaction otherFaction); + Predicate getPredicate(Holder> thisFaction, boolean player, boolean mob, boolean neutralPlayer, boolean ignoreDisguise, @Nullable Holder> otherFaction); + /** * Creates a faction builder. * @@ -75,6 +93,7 @@ public interface IFactionRegistry { * @param Interface all entities implement * @return a faction builder */ + @Deprecated @ThreadSafeAPI IFactionBuilder createFaction(ResourceLocation id, Class entityInterface); @@ -87,6 +106,7 @@ public interface IFactionRegistry { * @param Interface all entities or (the given capability for players) implement * @return a player faction builder */ + @Deprecated @ThreadSafeAPI > IPlayableFactionBuilder createPlayableFaction(ResourceLocation id, Class entityInterface, Supplier> playerCapabilitySupplier); diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/factions/ILordPlayerBuilder.java b/src/api/java/de/teamlapen/vampirism/api/entity/factions/ILordPlayerBuilder.java index ab5f1e6939..fb1ccc6a19 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/factions/ILordPlayerBuilder.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/factions/ILordPlayerBuilder.java @@ -40,7 +40,9 @@ public interface ILordPlayerBuilder> { * Enables this faction to have lord skills * * @return the builder + * @deprecated use HasLordSkills tag instead */ + @Deprecated ILordPlayerBuilder enableLordSkills(); IMinionBuilder minion(ResourceLocation minionId, Supplier data); diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IPlayableFaction.java b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IPlayableFaction.java index 50209b0c0f..e90f587707 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IPlayableFaction.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IPlayableFaction.java @@ -20,8 +20,6 @@ */ public interface IPlayableFaction> extends IFaction { - Codec> CODEC = RecordCodecBuilder.create(ins -> ins.group(ResourceLocation.CODEC.fieldOf("id").forGetter(IPlayableFaction::getID)).apply(ins, (id) -> (IPlayableFaction) VampirismAPI.factionRegistry().getFactionByID(id))); - Class getFactionPlayerInterface(); /** @@ -69,6 +67,7 @@ public interface IPlayableFaction> extends IFaction< /** * @return If the faction has lord skills */ + @Deprecated boolean hasLordSkills(); enum TitleGender implements StringRepresentable { diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IPlayableFactionBuilder.java b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IPlayableFactionBuilder.java index c818237193..26c677695d 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/factions/IPlayableFactionBuilder.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/factions/IPlayableFactionBuilder.java @@ -17,6 +17,10 @@ public interface IPlayableFactionBuilder> extends IF @Override IPlayableFactionBuilder color(int color); + /** + * @deprecated use HostileTowardsNeutral tag instead + */ + @Deprecated @Override IPlayableFactionBuilder hostileTowardsNeutral(); diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/factions/ISkillTree.java b/src/api/java/de/teamlapen/vampirism/api/entity/factions/ISkillTree.java index a7dce5d63b..4be87b0a08 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/factions/ISkillTree.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/factions/ISkillTree.java @@ -1,6 +1,7 @@ package de.teamlapen.vampirism.api.entity.factions; import net.minecraft.advancements.critereon.EntityPredicate; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; @@ -14,7 +15,7 @@ public interface ISkillTree { * The faction for which the skill tree is */ @NotNull - IPlayableFaction faction(); + Holder> faction(); /** * The unlocking predicate that will be checked against the player to see if the skill tree is unlocked
diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/hunter/IHunter.java b/src/api/java/de/teamlapen/vampirism/api/entity/hunter/IHunter.java index bf1472dc82..4783986d0a 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/hunter/IHunter.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/hunter/IHunter.java @@ -1,8 +1,11 @@ package de.teamlapen.vampirism.api.entity.hunter; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.VampirismFactions; +import de.teamlapen.vampirism.api.VampirismRegistries; import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; +import net.minecraft.core.Holder; import org.jetbrains.annotations.NotNull; /** @@ -12,7 +15,7 @@ public interface IHunter extends IFactionEntity { @NotNull @Override - default IFaction getFaction() { - return VReference.HUNTER_FACTION; + default Holder> getFaction() { + return VampirismFactions.HUNTER; } } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/minion/IFactionMinionTask.java b/src/api/java/de/teamlapen/vampirism/api/entity/minion/IFactionMinionTask.java index 28080e907d..baa2e60792 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/minion/IFactionMinionTask.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/minion/IFactionMinionTask.java @@ -1,6 +1,7 @@ package de.teamlapen.vampirism.api.entity.minion; import de.teamlapen.vampirism.api.entity.factions.IFaction; +import net.minecraft.core.Holder; import org.jetbrains.annotations.Nullable; public interface IFactionMinionTask, Q extends IMinionData> extends IMinionTask { @@ -10,5 +11,5 @@ public interface IFactionMinionTask, Q * @return The faction that is required to use this task. Null if no faction is required */ @Nullable - IFaction getFaction(); + Holder> getFaction(); } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/minion/IMinionTask.java b/src/api/java/de/teamlapen/vampirism/api/entity/minion/IMinionTask.java index 05a9e1404d..ab51c7e82e 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/minion/IMinionTask.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/minion/IMinionTask.java @@ -2,6 +2,8 @@ import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.ILordPlayer; +import de.teamlapen.vampirism.api.util.RegUtil; +import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -45,10 +47,15 @@ public interface IMinionTask, Q extends * @param player The lord player entity if loaded * @return Whether the task can currently be given by the lord player */ - default boolean isAvailable(@NotNull IPlayableFaction faction, @Nullable ILordPlayer player) { + default boolean isAvailable(@NotNull Holder> faction, @Nullable ILordPlayer player) { return true; } + @Deprecated + default boolean isAvailable(@NotNull IPlayableFaction faction, @Nullable ILordPlayer player) { + return isAvailable(RegUtil.holder(faction), player); + } + /** * Read the task description from NBT. * Counterpart to {@link IMinionTaskDesc#writeToNBT(CompoundTag)} diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/IFactionPlayer.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/IFactionPlayer.java index 66ebc38bdc..f6e2693d7a 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/IFactionPlayer.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/IFactionPlayer.java @@ -5,6 +5,7 @@ import de.teamlapen.vampirism.api.entity.player.skills.ISkillHandler; import de.teamlapen.vampirism.api.entity.player.task.ITaskManager; import de.teamlapen.vampirism.api.extensions.IPlayer; +import net.minecraft.core.Holder; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.NotNull; @@ -37,17 +38,12 @@ public interface IFactionPlayer> extends IFactionEnt @Nullable @Deprecated(forRemoval = true) default IFaction getDisguisedAs() { - return getDisguise().getViewedFaction(null); + var holder = getDisguise().getViewedFaction(null); + return holder == null ? null : holder.value(); } IDisguise getDisguise(); - /** - * @return the faction this faction player belongs to - */ - @NotNull - IPlayableFaction getFaction(); - /** * Preferably implement this by calling {@link IFactionPlayerHandler#getCurrentLevel(IPlayableFaction)} * @@ -60,6 +56,9 @@ default IFaction getDisguisedAs() { */ int getMaxLevel(); + @Override + @NotNull Holder> getFaction(); + /** * Careful this selects all {@link LivingEntity}'s including etc. Items * diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/ILordPlayer.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/ILordPlayer.java index 31aa437e20..f701c64f2b 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/ILordPlayer.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/ILordPlayer.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.entity.factions.ILordTitleProvider; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.NotNull; @@ -17,8 +18,8 @@ public interface ILordPlayer { /** * @return The faction of this lord player or null if not currently a lord */ - @Nullable - IPlayableFaction getLordFaction(); + @NotNull + Optional>> getLordFaction(); int getLordLevel(); diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IAction.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IAction.java index 1d3257bcf4..6889ed1607 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IAction.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IAction.java @@ -1,13 +1,16 @@ package de.teamlapen.vampirism.api.entity.player.actions; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.skills.ISkill; import de.teamlapen.vampirism.api.entity.player.skills.ISkillLike; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.tags.TagKey; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.NotNull; @@ -35,8 +38,12 @@ public interface IAction> extends ISkillLike { /** * @return the faction, which players can use this action */ + @Deprecated @NotNull - Optional> getFaction(); //TODO might be a good idea to have a more useful return type, that allow more that all or one faction + Optional> getFaction(); + + @NotNull + TagKey> factions(); /** * @param faction The faction to test @@ -49,6 +56,11 @@ default boolean matchesFaction(@Nullable IPlayableFaction faction) { return getFaction().map(f -> f == faction).orElse(true); } + default boolean matchesFaction(@Nullable Holder> faction) { + return IFaction.is(faction, factions()); + } + + default MutableComponent getName() { return Component.translatable(getTranslationKey()); } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IActionHandler.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IActionHandler.java index 8c430573a7..2e27755641 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IActionHandler.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IActionHandler.java @@ -2,7 +2,6 @@ import com.google.common.collect.ImmutableList; -import de.teamlapen.vampirism.api.DeferredAction; import de.teamlapen.vampirism.api.VampirismRegistries; import de.teamlapen.vampirism.api.annotations.FloatRange; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IActionManager.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IActionManager.java index d0ebbc970e..effec17078 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IActionManager.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/actions/IActionManager.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import java.util.List; @@ -14,10 +15,14 @@ public interface IActionManager { /** * A copied mutable list of all actions registered for this faction */ + @Deprecated > List> getActionsForFaction(IPlayableFaction faction); + List>> getActionsForFaction(Holder> faction); + /** * or use {@code net.minecraftforge.registries.RegistryManager.ACTIVE.getRegistry(new ResourceLocation("vampirism:actions"))} */ + @Deprecated Registry> getRegistry(); } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/hunter/DefaultHunterAction.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/hunter/DefaultHunterAction.java index a164c18cc0..c3c3ba4d33 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/hunter/DefaultHunterAction.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/hunter/DefaultHunterAction.java @@ -1,10 +1,11 @@ package de.teamlapen.vampirism.api.entity.player.hunter; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.VampirismTags; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.actions.DefaultAction; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderSet; +import net.minecraft.tags.TagKey; import org.jetbrains.annotations.NotNull; import java.util.Optional; @@ -13,9 +14,16 @@ * Basic implementation of IAction. It is recommended to extend this */ public abstract class DefaultHunterAction extends DefaultAction { + @NotNull @Override + @Deprecated public Optional> getFaction() { return Optional.of(VReference.HUNTER_FACTION); } + + @Override + public @NotNull TagKey> factions() { + return VampirismTags.Factions.IS_VAMPIRE; + } } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/hunter/IHunterPlayer.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/hunter/IHunterPlayer.java index 2565ac4e71..52e821b182 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/hunter/IHunterPlayer.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/hunter/IHunterPlayer.java @@ -1,9 +1,12 @@ package de.teamlapen.vampirism.api.entity.player.hunter; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.VampirismFactions; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.hunter.IHunter; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; +import net.minecraft.core.Holder; import org.jetbrains.annotations.NotNull; /** @@ -17,14 +20,14 @@ public interface IHunterPlayer extends IFactionPlayer, IHunter { */ void breakDisguise(); - @NotNull - @Override - default IPlayableFaction getFaction() { - return VReference.HUNTER_FACTION; - } - /** * updates attributes of all minions */ void updateMinionAttributes(boolean increasedStats); + + @Override + @NotNull + default Holder> getFaction() { + return VampirismFactions.HUNTER; + } } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/refinement/IRefinementSet.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/refinement/IRefinementSet.java index af29e76b1a..5784fe503d 100644 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/refinement/IRefinementSet.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/refinement/IRefinementSet.java @@ -18,7 +18,7 @@ public interface IRefinementSet { int getColor(); @NotNull - IFaction getFaction(); + Holder> getFaction(); @NotNull Component getName(); diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/skills/DefaultSkill.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/skills/DefaultSkill.java index 487ffc487b..c98caef6cd 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/skills/DefaultSkill.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/skills/DefaultSkill.java @@ -2,6 +2,7 @@ import com.google.common.base.Preconditions; import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.actions.IAction; import net.minecraft.Util; @@ -48,10 +49,10 @@ public String getTranslationKey() { public final void onDisable(@NotNull T player) { removeAttributesModifiersFromEntity(player.asEntity()); player.getActionHandler().relockActionHolder(getActionHolder()); - if (this.getFaction().map(f -> f.getFactionPlayerInterface().isInstance(player)).orElse(true)) { + if (IFaction.is(player.getFaction(), this.factions())) { onDisabled(player); } else { - throw new IllegalArgumentException("Faction player instance is of wrong class " + player.getClass() + " instead of " + this.getFaction().get().getFactionPlayerInterface()); + throw new IllegalArgumentException("Faction player instance is of wrong class " + player.getClass() + " for action " + VampirismRegistries.SKILL.get().getKey(this)); } } @@ -59,11 +60,11 @@ public final void onDisable(@NotNull T player) { public final void onEnable(@NotNull T player) { applyAttributesModifiersToEntity(player.asEntity()); - player.getActionHandler().unlockActionHolder(getActionHolder()); - if (this.getFaction().map(f -> f.getFactionPlayerInterface().isInstance(player)).orElse(true)) { + if (IFaction.is(player.getFaction(), this.factions())) { + player.getActionHandler().unlockActionHolder(getActionHolder()); onEnabled(player); } else { - throw new IllegalArgumentException("Faction player instance is of wrong class " + player.getClass() + " instead of " + this.getFaction().get().getFactionPlayerInterface()); + throw new IllegalArgumentException("skill is not allowed for player for skill " + VampirismRegistries.SKILL.get().getKey(this)); } } @@ -124,8 +125,8 @@ private void applyAttributesModifiersToEntity(@NotNull Player player) { Collection> collection = new ArrayList<>(); getActions(collection); collection.forEach((iAction -> { - if (iAction.getFaction().isPresent() && iAction.getFaction().get() != this.getFaction().orElse(null)) { - throw new IllegalArgumentException("Can't register action of faction " + iAction.getFaction().map(Object::toString).orElse(null) + " for skill of faction" + this.getFaction().map(Object::toString).orElse("all")); + if (!IFaction.is(factions(),iAction.factions())) { + throw new IllegalArgumentException("Can't register action with different factions than the skill"); } })); return collection; @@ -134,7 +135,7 @@ private void applyAttributesModifiersToEntity(@NotNull Player player) { public @NotNull Collection>> getActionHolder() { Collection>> collection = new ArrayList<>(); collectActions(collection); - Preconditions.checkState(collection.stream().map(Holder::value).allMatch(h -> h.getFaction().isEmpty() || h.getFaction().get() == getFaction().orElse(null)), "Can't register action of faction for skill of faction"); + Preconditions.checkState(collection.stream().map(Holder::value).allMatch(h -> IFaction.is(h.factions(), factions())), "Can't register action with different factions than the skill"); return collection; } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/skills/ISkill.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/skills/ISkill.java index cfb39fe836..f5203f4ae7 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/skills/ISkill.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/skills/ISkill.java @@ -1,6 +1,7 @@ package de.teamlapen.vampirism.api.entity.player.skills; import com.mojang.datafixers.util.Either; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.factions.ISkillTree; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; @@ -28,9 +29,12 @@ public interface ISkill> extends ISkillLike { * A skill can be either * @return The faction this skill belongs to */ + @Deprecated @NotNull Optional> getFaction(); + TagKey> factions(); + default MutableComponent getName() { return Component.translatable(getTranslationKey()); } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/vampire/DefaultVampireAction.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/vampire/DefaultVampireAction.java index ca7c54bcf0..1b11a30b81 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/vampire/DefaultVampireAction.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/vampire/DefaultVampireAction.java @@ -1,8 +1,11 @@ package de.teamlapen.vampirism.api.entity.player.vampire; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.VampirismTags; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.actions.DefaultAction; +import net.minecraft.tags.TagKey; import org.jetbrains.annotations.NotNull; import java.util.Optional; @@ -11,9 +14,15 @@ * Basic implementation of IAction. It is recommended to extend this */ public abstract class DefaultVampireAction extends DefaultAction { + @NotNull @Override public Optional> getFaction() { return Optional.of(VReference.VAMPIRE_FACTION); } + + @Override + public @NotNull TagKey> factions() { + return VampirismTags.Factions.IS_VAMPIRE; + } } diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/player/vampire/IVampirePlayer.java b/src/api/java/de/teamlapen/vampirism/api/entity/player/vampire/IVampirePlayer.java index 653e65a51f..632d360c38 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/player/vampire/IVampirePlayer.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/player/vampire/IVampirePlayer.java @@ -1,11 +1,14 @@ package de.teamlapen.vampirism.api.entity.player.vampire; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.VampirismFactions; import de.teamlapen.vampirism.api.entity.IBiteableEntity; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.actions.IActionHandler; import de.teamlapen.vampirism.api.entity.vampire.IVampire; +import net.minecraft.core.Holder; import net.minecraft.util.StringRepresentable; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.LivingEntity; @@ -53,6 +56,12 @@ public interface IVampirePlayer extends IVampire, IFactionPlayer @NotNull IActionHandler getActionHandler(); + @Override + @NotNull + default Holder> getFaction() { + return VampirismFactions.VAMPIRE; + } + /** * @return The currently active vision. May be null */ @@ -67,12 +76,6 @@ public interface IVampirePlayer extends IVampire, IFactionPlayer @NotNull IBloodStats getBloodStats(); - @NotNull - @Override - default IPlayableFaction getFaction() { - return VReference.VAMPIRE_FACTION; - } - /** * @return The amount of ticks the player has been in sun. Never higher than 100. */ diff --git a/src/api/java/de/teamlapen/vampirism/api/entity/vampire/IVampire.java b/src/api/java/de/teamlapen/vampirism/api/entity/vampire/IVampire.java index da973c9e0b..063981b280 100755 --- a/src/api/java/de/teamlapen/vampirism/api/entity/vampire/IVampire.java +++ b/src/api/java/de/teamlapen/vampirism/api/entity/vampire/IVampire.java @@ -2,9 +2,11 @@ import de.teamlapen.vampirism.api.EnumStrength; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.VampirismFactions; import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; import de.teamlapen.vampirism.api.entity.player.vampire.IDrinkBloodContext; +import net.minecraft.core.Holder; import net.minecraft.world.level.LevelAccessor; import org.jetbrains.annotations.NotNull; @@ -44,8 +46,8 @@ default void drinkBlood(int amt, float saturationMod, boolean useRemaining, IDri @NotNull @Override - default IFaction getFaction() { - return VReference.VAMPIRE_FACTION; + default Holder> getFaction() { + return VampirismFactions.VAMPIRE; } /** diff --git a/src/api/java/de/teamlapen/vampirism/api/event/PlayerFactionEvent.java b/src/api/java/de/teamlapen/vampirism/api/event/PlayerFactionEvent.java index 7bfc5db864..d7820ac444 100644 --- a/src/api/java/de/teamlapen/vampirism/api/event/PlayerFactionEvent.java +++ b/src/api/java/de/teamlapen/vampirism/api/event/PlayerFactionEvent.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.entity.factions.IFactionPlayerHandler; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; +import net.minecraft.core.Holder; import net.neoforged.bus.api.Event; import net.neoforged.bus.api.ICancellableEvent; import org.jetbrains.annotations.NotNull; @@ -13,11 +14,11 @@ public class PlayerFactionEvent extends Event { @Nullable - private final IPlayableFaction currentFaction; + private final Holder> currentFaction; @NotNull private final IFactionPlayerHandler player; - private PlayerFactionEvent(@NotNull IFactionPlayerHandler player, @Nullable IPlayableFaction currentFaction) { + private PlayerFactionEvent(@NotNull IFactionPlayerHandler player, @Nullable Holder> currentFaction) { this.currentFaction = currentFaction; this.player = player; } @@ -26,7 +27,7 @@ private PlayerFactionEvent(@NotNull IFactionPlayerHandler player, @Nullable IPla * @return The faction the respective player is currently in. */ @Nullable - public IPlayableFaction getCurrentFaction() { + public Holder> getCurrentFaction() { return currentFaction; } @@ -49,9 +50,9 @@ public static class FactionLevelChangePre extends PlayerFactionEvent implements private final int currentLevel; private final int newLevel; @Nullable - private final IPlayableFaction newFaction; + private final Holder> newFaction; - public FactionLevelChangePre(@NotNull IFactionPlayerHandler player, @Nullable IPlayableFaction currentFaction, int currentLevel, @Nullable IPlayableFaction newFaction, int newLevel) { + public FactionLevelChangePre(@NotNull IFactionPlayerHandler player, @Nullable Holder> currentFaction, int currentLevel, @Nullable Holder> newFaction, int newLevel) { super(player, currentFaction); this.currentLevel = currentLevel; this.newLevel = newLevel; @@ -69,7 +70,7 @@ public int getCurrentLevel() { * @return The faction the player is going to be */ @Nullable - public IPlayableFaction getNewFaction() { + public Holder> getNewFaction() { return newFaction; } @@ -88,9 +89,9 @@ public static class FactionLevelChanged extends PlayerFactionEvent { private final int oldLevel; private final int newLevel; @Nullable - private final IPlayableFaction oldFaction; + private final Holder> oldFaction; - public FactionLevelChanged(@NotNull IFactionPlayerHandler player, @Nullable IPlayableFaction oldFaction, int oldLevel, @Nullable IPlayableFaction newFaction, int newLevel) { + public FactionLevelChanged(@NotNull IFactionPlayerHandler player, @Nullable Holder> oldFaction, int oldLevel, @Nullable Holder> newFaction, int newLevel) { super(player, newFaction); this.oldLevel = oldLevel; this.newLevel = newLevel; @@ -108,7 +109,7 @@ public int getOldLevel() { * @return The faction the player was before */ @Nullable - public IPlayableFaction getOldFaction() { + public Holder> getOldFaction() { return oldFaction; } @@ -133,10 +134,10 @@ public int getNewLevel() { */ public static class CanJoinFaction extends PlayerFactionEvent { - private final IPlayableFaction toJoin; + private final Holder> toJoin; private Behavior behavior = Behavior.ONLY_WHEN_NO_FACTION; - public CanJoinFaction(@NotNull IFactionPlayerHandler player, @Nullable IPlayableFaction currentFaction, IPlayableFaction toJoin) { + public CanJoinFaction(@NotNull IFactionPlayerHandler player, @Nullable Holder> currentFaction, Holder> toJoin) { super(player, currentFaction); this.toJoin = toJoin; } @@ -144,7 +145,7 @@ public CanJoinFaction(@NotNull IFactionPlayerHandler player, @Nullable IPlayable /** * @return The faction the player wants to join */ - public IPlayableFaction getFactionToJoin() { + public Holder> getFactionToJoin() { return toJoin; } diff --git a/src/api/java/de/teamlapen/vampirism/api/event/VampirismVillageEvent.java b/src/api/java/de/teamlapen/vampirism/api/event/VampirismVillageEvent.java index 937b4a24ce..36452c4cf5 100644 --- a/src/api/java/de/teamlapen/vampirism/api/event/VampirismVillageEvent.java +++ b/src/api/java/de/teamlapen/vampirism/api/event/VampirismVillageEvent.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.world.ITotem; +import net.minecraft.core.Holder; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.npc.Villager; import net.minecraft.world.level.Level; @@ -24,12 +25,12 @@ public VampirismVillageEvent(ITotem totem) { } @Nullable - public IFaction getCapturingFaction() { + public Holder> getCapturingFaction() { return this.totem.getCapturingFaction(); } @Nullable - public IFaction getControllingFaction() { + public Holder> getControllingFaction() { return this.totem.getControllingFaction(); } @@ -80,7 +81,7 @@ public SpawnNewVillager(ITotem totem, @Nullable Mob oldEntity, @NotNull Villager /** * Faction that owns the village */ - public @Nullable IFaction getFaction() { + public @Nullable Holder> getFaction() { return this.totem.getControllingFaction(); } @@ -196,12 +197,12 @@ public boolean isEntityConversionDisabled() { public static class InitiateCapture extends VampirismVillageEvent { @NotNull - private final IFaction capturingFaction; + private final Holder> capturingFaction; @Nullable private String message; private boolean disallowCapture = false; - public InitiateCapture(ITotem totem, @NotNull IFaction capturingFaction) { + public InitiateCapture(ITotem totem, @NotNull Holder> capturingFaction) { super(totem); this.capturingFaction = capturingFaction; } @@ -211,7 +212,7 @@ public InitiateCapture(ITotem totem, @NotNull IFaction capturingFaction) { */ @Override @NotNull - public IFaction getCapturingFaction() { + public Holder> getCapturingFaction() { return capturingFaction; } diff --git a/src/api/java/de/teamlapen/vampirism/api/items/IFactionExclusiveItem.java b/src/api/java/de/teamlapen/vampirism/api/items/IFactionExclusiveItem.java index 50568c1fe2..8cc5f34422 100644 --- a/src/api/java/de/teamlapen/vampirism/api/items/IFactionExclusiveItem.java +++ b/src/api/java/de/teamlapen/vampirism/api/items/IFactionExclusiveItem.java @@ -5,6 +5,7 @@ import de.teamlapen.vampirism.api.components.IAppliedOilContent; import de.teamlapen.vampirism.api.entity.factions.IFaction; import net.minecraft.ChatFormatting; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; @@ -26,13 +27,13 @@ default void addFactionToolTips(@NotNull ItemStack stack, @Nullable Item.Tooltip tooltip.add(Component.empty()); tooltip.add(Component.translatable("text.vampirism.faction_specifics").withStyle(ChatFormatting.GRAY)); ChatFormatting color = ChatFormatting.GRAY; - IFaction faction = getExclusiveFaction(stack); + Holder> faction = getExclusiveFaction(stack); if (faction != null) { if (player != null) { - color = VampirismAPI.factionRegistry().getFaction(player) == faction ? ChatFormatting.DARK_GREEN : ChatFormatting.DARK_RED; + color = IFaction.is(VampirismAPI.factionRegistry().getFactionHolder(player), faction) ? ChatFormatting.DARK_GREEN : ChatFormatting.DARK_RED; } - tooltip.add(Component.literal(" ").append(faction.getName()).append(Component.translatable("text.vampirism.faction_only")).withStyle(color)); + tooltip.add(Component.literal(" ").append(faction.value().getName()).append(Component.translatable("text.vampirism.faction_only")).withStyle(color)); } } @@ -56,5 +57,5 @@ default void addOilDescTooltip(@NotNull ItemStack stack, @Nullable Item.TooltipC * @return The faction that can use this item or null if any */ @Nullable - IFaction getExclusiveFaction(@NotNull ItemStack stack); + Holder> getExclusiveFaction(@NotNull ItemStack stack); } diff --git a/src/api/java/de/teamlapen/vampirism/api/items/IFactionSlayerItem.java b/src/api/java/de/teamlapen/vampirism/api/items/IFactionSlayerItem.java index 745cd5ed1a..f0294eee19 100755 --- a/src/api/java/de/teamlapen/vampirism/api/items/IFactionSlayerItem.java +++ b/src/api/java/de/teamlapen/vampirism/api/items/IFactionSlayerItem.java @@ -1,6 +1,7 @@ package de.teamlapen.vampirism.api.items; import de.teamlapen.vampirism.api.entity.factions.IFaction; +import net.minecraft.core.Holder; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; import org.jetbrains.annotations.NotNull; @@ -19,5 +20,5 @@ public interface IFactionSlayerItem extends ItemLike { /** * @return Modify damage for this faction */ - IFaction getSlayedFaction(); + Holder> getSlayedFaction(); } diff --git a/src/api/java/de/teamlapen/vampirism/api/items/IRefinementItem.java b/src/api/java/de/teamlapen/vampirism/api/items/IRefinementItem.java index 807be6a3c5..c6eb470bcd 100644 --- a/src/api/java/de/teamlapen/vampirism/api/items/IRefinementItem.java +++ b/src/api/java/de/teamlapen/vampirism/api/items/IRefinementItem.java @@ -1,6 +1,9 @@ package de.teamlapen.vampirism.api.items; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.refinement.IRefinementSet; +import net.minecraft.core.Holder; import net.minecraft.util.StringRepresentable; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; @@ -36,6 +39,8 @@ public interface IRefinementItem extends IFactionExclusiveItem { */ boolean applyRefinementSet(ItemStack stack, IRefinementSet set); + Holder> getExclusiveFaction(@NotNull ItemStack stack); + /** * Slots types for {@link IRefinementItem} *
diff --git a/src/api/java/de/teamlapen/vampirism/api/items/IVampirismCrossbowArrow.java b/src/api/java/de/teamlapen/vampirism/api/items/IVampirismCrossbowArrow.java index 4765a70644..d05c8dc2f0 100644 --- a/src/api/java/de/teamlapen/vampirism/api/items/IVampirismCrossbowArrow.java +++ b/src/api/java/de/teamlapen/vampirism/api/items/IVampirismCrossbowArrow.java @@ -1,9 +1,11 @@ package de.teamlapen.vampirism.api.items; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.VampirismFactions; import de.teamlapen.vampirism.api.entity.factions.IFaction; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; @@ -19,10 +21,9 @@ public interface IVampirismCrossbowArrow extends IFactionExclusiveItem { - @Nullable @Override - default IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.HUNTER_FACTION; + default @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return VampirismFactions.HUNTER; } /** diff --git a/src/api/java/de/teamlapen/vampirism/api/package-info.java b/src/api/java/de/teamlapen/vampirism/api/package-info.java index 80c817e79f..e6516afc4f 100755 --- a/src/api/java/de/teamlapen/vampirism/api/package-info.java +++ b/src/api/java/de/teamlapen/vampirism/api/package-info.java @@ -3,7 +3,6 @@ */ @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault - @com.mojang.math.MethodsReturnNonnullByDefault package de.teamlapen.vampirism.api; import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/api/java/de/teamlapen/vampirism/api/DeferredAction.java b/src/api/java/de/teamlapen/vampirism/api/registries/DeferredAction.java similarity index 90% rename from src/api/java/de/teamlapen/vampirism/api/DeferredAction.java rename to src/api/java/de/teamlapen/vampirism/api/registries/DeferredAction.java index 458a66a9ae..edde9e31aa 100644 --- a/src/api/java/de/teamlapen/vampirism/api/DeferredAction.java +++ b/src/api/java/de/teamlapen/vampirism/api/registries/DeferredAction.java @@ -1,8 +1,8 @@ -package de.teamlapen.vampirism.api; +package de.teamlapen.vampirism.api.registries; +import de.teamlapen.vampirism.api.VampirismRegistries; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.actions.IAction; -import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.neoforged.neoforge.registries.DeferredHolder; diff --git a/src/api/java/de/teamlapen/vampirism/api/DeferredActionRegister.java b/src/api/java/de/teamlapen/vampirism/api/registries/DeferredActionRegister.java similarity index 96% rename from src/api/java/de/teamlapen/vampirism/api/DeferredActionRegister.java rename to src/api/java/de/teamlapen/vampirism/api/registries/DeferredActionRegister.java index 94a35c2450..d9005434ff 100644 --- a/src/api/java/de/teamlapen/vampirism/api/DeferredActionRegister.java +++ b/src/api/java/de/teamlapen/vampirism/api/registries/DeferredActionRegister.java @@ -1,5 +1,6 @@ -package de.teamlapen.vampirism.api; +package de.teamlapen.vampirism.api.registries; +import de.teamlapen.vampirism.api.VampirismRegistries; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.actions.IAction; import net.minecraft.core.Registry; diff --git a/src/api/java/de/teamlapen/vampirism/api/registries/DeferredFaction.java b/src/api/java/de/teamlapen/vampirism/api/registries/DeferredFaction.java new file mode 100644 index 0000000000..8ce95b9e5c --- /dev/null +++ b/src/api/java/de/teamlapen/vampirism/api/registries/DeferredFaction.java @@ -0,0 +1,38 @@ +package de.teamlapen.vampirism.api.registries; + +import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; +import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; +import de.teamlapen.vampirism.api.entity.player.actions.IAction; +import net.minecraft.core.Holder; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.registries.DeferredHolder; +import org.checkerframework.checker.units.qual.K; +import org.jetbrains.annotations.Nullable; + +public class DeferredFaction> extends DeferredHolder { + + protected DeferredFaction(ResourceKey key) { + super(key); + } + + public > boolean match(@Nullable Holder otherFaction) { + return IFaction.is(this, otherFaction); + } + + @SuppressWarnings("unchecked") + public ResourceKey> getRawKey() { + return (ResourceKey>) super.getKey(); + } + + public static > DeferredFaction createFaction(ResourceKey key) { + return new DeferredFaction<>(key); + } + + @SuppressWarnings("unchecked") + public static > DeferredFaction createFaction(ResourceLocation key) { + return createFaction((ResourceKey) ResourceKey.create(VampirismRegistries.Keys.FACTION, key)); + } +} diff --git a/src/api/java/de/teamlapen/vampirism/api/registries/DeferredFactionRegister.java b/src/api/java/de/teamlapen/vampirism/api/registries/DeferredFactionRegister.java new file mode 100644 index 0000000000..190b0ad4b7 --- /dev/null +++ b/src/api/java/de/teamlapen/vampirism/api/registries/DeferredFactionRegister.java @@ -0,0 +1,53 @@ +package de.teamlapen.vampirism.api.registries; + +import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; +import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; +import de.teamlapen.vampirism.api.entity.player.actions.IAction; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; + +import java.util.Objects; +import java.util.function.Function; +import java.util.function.Supplier; + +public class DeferredFactionRegister extends DeferredRegister> { + + protected DeferredFactionRegister(String namespace) { + super(VampirismRegistries.Keys.FACTION, namespace); + } + + public static DeferredFactionRegister create(String namespace) { + return new DeferredFactionRegister(namespace); + } + + @Deprecated + @Override + public > DeferredHolder, I> register(String name, Supplier sup) { + return super.register(name, sup); + } + + @SuppressWarnings({"unchecked", "RedundantCast"}) + public > DeferredFaction registerFaction(String name, Supplier sup) { + return (DeferredFaction) (Object) super.register(name, sup); + } + + @Override + public > DeferredHolder, I> register(String name, Function func) { + return super.register(name, func); + } + + @SuppressWarnings({"unchecked", "RedundantCast"}) + public > DeferredFaction registerFaction(String name, Function func) { + return (DeferredFaction) (Object) super.register(name, func); + } + + @Override + protected > DeferredHolder, I> createHolder(ResourceKey>> registryKey, ResourceLocation key) { + return ( DeferredHolder, I>) (Object)DeferredFaction.createFaction(key); + } +} diff --git a/src/api/java/de/teamlapen/vampirism/api/registries/package-info.java b/src/api/java/de/teamlapen/vampirism/api/registries/package-info.java new file mode 100644 index 0000000000..e08528dc0f --- /dev/null +++ b/src/api/java/de/teamlapen/vampirism/api/registries/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package de.teamlapen.vampirism.api.registries; + +import net.minecraft.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/src/api/java/de/teamlapen/vampirism/api/util/RegUtil.java b/src/api/java/de/teamlapen/vampirism/api/util/RegUtil.java index 20e74dc545..478d8e9749 100644 --- a/src/api/java/de/teamlapen/vampirism/api/util/RegUtil.java +++ b/src/api/java/de/teamlapen/vampirism/api/util/RegUtil.java @@ -1,6 +1,7 @@ package de.teamlapen.vampirism.api.util; import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.actions.IAction; import de.teamlapen.vampirism.api.entity.player.actions.ILastingAction; @@ -36,4 +37,9 @@ public static > Holder holderAnon(T skill) { public static Holder holder(T refinement) { return (Holder) VampirismRegistries.REFINEMENT.get().wrapAsHolder(refinement); } + + @SuppressWarnings("unchecked") + public static > Holder holder(T faction) { + return (Holder) VampirismRegistries.FACTION.get().wrapAsHolder(faction); + } } diff --git a/src/api/java/de/teamlapen/vampirism/api/util/SkillCallbacks.java b/src/api/java/de/teamlapen/vampirism/api/util/SkillCallbacks.java index 2aeededaed..3f150851aa 100644 --- a/src/api/java/de/teamlapen/vampirism/api/util/SkillCallbacks.java +++ b/src/api/java/de/teamlapen/vampirism/api/util/SkillCallbacks.java @@ -3,6 +3,7 @@ import com.mojang.datafixers.util.Either; import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.factions.ISkillTree; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; @@ -55,34 +56,41 @@ public static > Map, ISkill> getAction public record EmptyActionSkill>(Holder> actionHolder) implements IActionSkill { private static final TagKey key = TagKey.create(VampirismRegistries.Keys.SKILL_TREE, new ResourceLocation(VReference.MODID, "empty")); + @Override - public @Nullable Component getDescription() { - return null; - } + public @Nullable Component getDescription() { + return null; + } - @Override - public @NotNull Optional> getFaction() { - return this.actionHolder.value().getFaction(); - } + @Deprecated + @Override + public @NotNull Optional> getFaction() { + return this.actionHolder.value().getFaction(); + } - @Override - public String getTranslationKey() { - return this.actionHolder.value().getTranslationKey(); - } + @Override + public TagKey> factions() { + return this.actionHolder.value().factions(); + } - @Override - public void onDisable(T player) { + @Override + public String getTranslationKey() { + return this.actionHolder.value().getTranslationKey(); + } - } + @Override + public void onDisable(T player) { - @Override - public void onEnable(T player) { + } - } + @Override + public void onEnable(T player) { - @Override - public Either, TagKey> allowedSkillTrees() { - return Either.right(key); - } + } + + @Override + public Either, TagKey> allowedSkillTrees() { + return Either.right(key); + } } } diff --git a/src/api/java/de/teamlapen/vampirism/api/world/ICaptureAttributes.java b/src/api/java/de/teamlapen/vampirism/api/world/ICaptureAttributes.java index 3b7305817d..4073d3d98d 100644 --- a/src/api/java/de/teamlapen/vampirism/api/world/ICaptureAttributes.java +++ b/src/api/java/de/teamlapen/vampirism/api/world/ICaptureAttributes.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.world.phys.AABB; import org.jetbrains.annotations.Nullable; @@ -14,13 +15,13 @@ public interface ICaptureAttributes { * @return currently attacking faction of the village */ @Nullable - IFaction getAttackingFaction(); + Holder> getAttackingFaction(); /** * @return currently defending faction of the village */ @Nullable - IFaction getDefendingFaction(); + Holder> getDefendingFaction(); /** * @return totem position diff --git a/src/api/java/de/teamlapen/vampirism/api/world/ITotem.java b/src/api/java/de/teamlapen/vampirism/api/world/ITotem.java index df0e62ac04..6adfc1f7be 100644 --- a/src/api/java/de/teamlapen/vampirism/api/world/ITotem.java +++ b/src/api/java/de/teamlapen/vampirism/api/world/ITotem.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.level.Level; @@ -21,19 +22,19 @@ public interface ITotem { * @param faction the faction for the capture entity * @return entityType of a capture entity */ - Optional> getCaptureEntityForFaction(IFaction faction); + Optional> getCaptureEntityForFaction(Holder> faction); /** * @return current capturing faction of the totem or {@code null} if none */ @Nullable - IFaction getCapturingFaction(); + Holder> getCapturingFaction(); /** * @return current controlling faction of the totem or {@code null} if none */ @Nullable - IFaction getControllingFaction(); + Holder> getControllingFaction(); /** * support method for getting block entity level diff --git a/src/generated/resources/data/vampirism/advancements/hunter/become_hunter.json b/src/generated/resources/data/vampirism/advancements/hunter/become_hunter.json index 7282c9d654..21c07185f0 100644 --- a/src/generated/resources/data/vampirism/advancements/hunter/become_hunter.json +++ b/src/generated/resources/data/vampirism/advancements/hunter/become_hunter.json @@ -4,9 +4,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/hunter/betrayal.json b/src/generated/resources/data/vampirism/advancements/hunter/betrayal.json index e731970dd1..b764e1f2d8 100644 --- a/src/generated/resources/data/vampirism/advancements/hunter/betrayal.json +++ b/src/generated/resources/data/vampirism/advancements/hunter/betrayal.json @@ -4,9 +4,7 @@ "faction": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/hunter/cure_vampire_villager.json b/src/generated/resources/data/vampirism/advancements/hunter/cure_vampire_villager.json index b8f4d07d12..53ebd9a86d 100644 --- a/src/generated/resources/data/vampirism/advancements/hunter/cure_vampire_villager.json +++ b/src/generated/resources/data/vampirism/advancements/hunter/cure_vampire_villager.json @@ -7,9 +7,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/hunter/kill_mother.json b/src/generated/resources/data/vampirism/advancements/hunter/kill_mother.json index 329fc61762..4e0cf15911 100644 --- a/src/generated/resources/data/vampirism/advancements/hunter/kill_mother.json +++ b/src/generated/resources/data/vampirism/advancements/hunter/kill_mother.json @@ -7,9 +7,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/hunter/kill_resurrected_vampire.json b/src/generated/resources/data/vampirism/advancements/hunter/kill_resurrected_vampire.json index b4cc8010d4..60467df630 100644 --- a/src/generated/resources/data/vampirism/advancements/hunter/kill_resurrected_vampire.json +++ b/src/generated/resources/data/vampirism/advancements/hunter/kill_resurrected_vampire.json @@ -13,9 +13,7 @@ }, "type_specific": { "type": "vampirism:faction", - "faction": { - "id": "vampirism:vampire" - } + "faction": "vampirism:vampire" } } } @@ -26,9 +24,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/hunter/max_level.json b/src/generated/resources/data/vampirism/advancements/hunter/max_level.json index 85dc43906f..7bd74f00ee 100644 --- a/src/generated/resources/data/vampirism/advancements/hunter/max_level.json +++ b/src/generated/resources/data/vampirism/advancements/hunter/max_level.json @@ -4,9 +4,7 @@ "level": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 14 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/hunter/max_lord.json b/src/generated/resources/data/vampirism/advancements/hunter/max_lord.json index 150d980e4d..7d14fbd98a 100644 --- a/src/generated/resources/data/vampirism/advancements/hunter/max_lord.json +++ b/src/generated/resources/data/vampirism/advancements/hunter/max_lord.json @@ -4,9 +4,7 @@ "level": { "conditions": { "type": "lord", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 5 }, "trigger": "vampirism:faction" @@ -14,9 +12,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/hunter/stake.json b/src/generated/resources/data/vampirism/advancements/hunter/stake.json index 6e126f26c0..eae3f1cea7 100644 --- a/src/generated/resources/data/vampirism/advancements/hunter/stake.json +++ b/src/generated/resources/data/vampirism/advancements/hunter/stake.json @@ -10,9 +10,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/hunter/technology.json b/src/generated/resources/data/vampirism/advancements/hunter/technology.json index 4306cb3da9..a4e39ef5bf 100644 --- a/src/generated/resources/data/vampirism/advancements/hunter/technology.json +++ b/src/generated/resources/data/vampirism/advancements/hunter/technology.json @@ -24,9 +24,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/bat.json b/src/generated/resources/data/vampirism/advancements/vampire/bat.json index c42206cf4c..41e3664d69 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/bat.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/bat.json @@ -10,9 +10,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/become_vampire.json b/src/generated/resources/data/vampirism/advancements/vampire/become_vampire.json index 6390fecb6e..31f16c39aa 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/become_vampire.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/become_vampire.json @@ -4,9 +4,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/blood_cult.json b/src/generated/resources/data/vampirism/advancements/vampire/blood_cult.json index 1327ae5ec9..e314cba20d 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/blood_cult.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/blood_cult.json @@ -10,9 +10,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/extra_storage.json b/src/generated/resources/data/vampirism/advancements/vampire/extra_storage.json index 0fd8cf69c0..a1fd58dee6 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/extra_storage.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/extra_storage.json @@ -14,9 +14,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/first_blood.json b/src/generated/resources/data/vampirism/advancements/vampire/first_blood.json index 26920d287d..53fd37bc1e 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/first_blood.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/first_blood.json @@ -10,9 +10,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/freeze_kill.json b/src/generated/resources/data/vampirism/advancements/vampire/freeze_kill.json index bf875d396a..bc8409b718 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/freeze_kill.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/freeze_kill.json @@ -10,9 +10,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/kill_mother.json b/src/generated/resources/data/vampirism/advancements/vampire/kill_mother.json index 08ce8520fd..a41d037e25 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/kill_mother.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/kill_mother.json @@ -7,9 +7,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/max_level.json b/src/generated/resources/data/vampirism/advancements/vampire/max_level.json index 250a01cf9d..96f82da32f 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/max_level.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/max_level.json @@ -4,9 +4,7 @@ "level": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 14 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/max_lord.json b/src/generated/resources/data/vampirism/advancements/vampire/max_lord.json index cba17b6700..e1f50a2c55 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/max_lord.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/max_lord.json @@ -4,9 +4,7 @@ "level": { "conditions": { "type": "lord", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 5 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/resurrect.json b/src/generated/resources/data/vampirism/advancements/vampire/resurrect.json index 89fdc08f9c..145bd12a4e 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/resurrect.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/resurrect.json @@ -4,9 +4,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/sniped.json b/src/generated/resources/data/vampirism/advancements/vampire/sniped.json index bf71838010..84dfb266fc 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/sniped.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/sniped.json @@ -10,9 +10,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/advancements/vampire/yuck.json b/src/generated/resources/data/vampirism/advancements/vampire/yuck.json index e9b272045e..a5194704ed 100644 --- a/src/generated/resources/data/vampirism/advancements/vampire/yuck.json +++ b/src/generated/resources/data/vampirism/advancements/vampire/yuck.json @@ -10,9 +10,7 @@ "main": { "conditions": { "type": "level", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "level": 1 }, "trigger": "vampirism:faction" diff --git a/src/generated/resources/data/vampirism/loot_tables/chests/crypt.json b/src/generated/resources/data/vampirism/loot_tables/chests/crypt.json index e692999425..f90959b5b5 100644 --- a/src/generated/resources/data/vampirism/loot_tables/chests/crypt.json +++ b/src/generated/resources/data/vampirism/loot_tables/chests/crypt.json @@ -59,9 +59,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -71,9 +69,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -83,9 +79,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/chests/dungeon/vampire_dungeon.json b/src/generated/resources/data/vampirism/loot_tables/chests/dungeon/vampire_dungeon.json index 4b747d4f4c..c7aa364bc7 100644 --- a/src/generated/resources/data/vampirism/loot_tables/chests/dungeon/vampire_dungeon.json +++ b/src/generated/resources/data/vampirism/loot_tables/chests/dungeon/vampire_dungeon.json @@ -157,9 +157,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -169,9 +167,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -181,9 +177,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/chests/vampire_hut.json b/src/generated/resources/data/vampirism/loot_tables/chests/vampire_hut.json index acf3b5632a..ede0e04d3f 100644 --- a/src/generated/resources/data/vampirism/loot_tables/chests/vampire_hut.json +++ b/src/generated/resources/data/vampirism/loot_tables/chests/vampire_hut.json @@ -59,9 +59,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -71,9 +69,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -83,9 +79,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/entities/advanced_vampire.json b/src/generated/resources/data/vampirism/loot_tables/entities/advanced_vampire.json index 8368c0e41b..931b7b68a0 100644 --- a/src/generated/resources/data/vampirism/loot_tables/entities/advanced_vampire.json +++ b/src/generated/resources/data/vampirism/loot_tables/entities/advanced_vampire.json @@ -71,9 +71,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -83,9 +81,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -95,9 +91,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/entities/advanced_vampire_imob.json b/src/generated/resources/data/vampirism/loot_tables/entities/advanced_vampire_imob.json index 2120e3d5f5..380215639c 100644 --- a/src/generated/resources/data/vampirism/loot_tables/entities/advanced_vampire_imob.json +++ b/src/generated/resources/data/vampirism/loot_tables/entities/advanced_vampire_imob.json @@ -71,9 +71,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -83,9 +81,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -95,9 +91,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/entities/hunter.json b/src/generated/resources/data/vampirism/loot_tables/entities/hunter.json index 34cb968a1d..356013f61e 100644 --- a/src/generated/resources/data/vampirism/loot_tables/entities/hunter.json +++ b/src/generated/resources/data/vampirism/loot_tables/entities/hunter.json @@ -35,9 +35,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -47,9 +45,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -59,9 +55,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/entities/hunter_imob.json b/src/generated/resources/data/vampirism/loot_tables/entities/hunter_imob.json index a1859703e0..097ec81965 100644 --- a/src/generated/resources/data/vampirism/loot_tables/entities/hunter_imob.json +++ b/src/generated/resources/data/vampirism/loot_tables/entities/hunter_imob.json @@ -35,9 +35,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -47,9 +45,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -59,9 +55,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/entities/vampire.json b/src/generated/resources/data/vampirism/loot_tables/entities/vampire.json index 3c16aa92ba..158461c5eb 100644 --- a/src/generated/resources/data/vampirism/loot_tables/entities/vampire.json +++ b/src/generated/resources/data/vampirism/loot_tables/entities/vampire.json @@ -56,9 +56,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -68,9 +66,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -80,9 +76,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/entities/vampire_imob.json b/src/generated/resources/data/vampirism/loot_tables/entities/vampire_imob.json index c18230b945..edfe575a2a 100644 --- a/src/generated/resources/data/vampirism/loot_tables/entities/vampire_imob.json +++ b/src/generated/resources/data/vampirism/loot_tables/entities/vampire_imob.json @@ -56,9 +56,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -68,9 +66,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -80,9 +76,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/inject/abandoned_mineshaft.json b/src/generated/resources/data/vampirism/loot_tables/inject/abandoned_mineshaft.json index bbc64dec81..06148a159a 100644 --- a/src/generated/resources/data/vampirism/loot_tables/inject/abandoned_mineshaft.json +++ b/src/generated/resources/data/vampirism/loot_tables/inject/abandoned_mineshaft.json @@ -221,9 +221,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -233,9 +231,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -245,9 +241,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/inject/desert_pyramid.json b/src/generated/resources/data/vampirism/loot_tables/inject/desert_pyramid.json index ce1eb4bf89..73dd424542 100644 --- a/src/generated/resources/data/vampirism/loot_tables/inject/desert_pyramid.json +++ b/src/generated/resources/data/vampirism/loot_tables/inject/desert_pyramid.json @@ -49,9 +49,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -61,9 +59,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -73,9 +69,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/inject/jungle_temple.json b/src/generated/resources/data/vampirism/loot_tables/inject/jungle_temple.json index d0663d91a7..7431a5632a 100644 --- a/src/generated/resources/data/vampirism/loot_tables/inject/jungle_temple.json +++ b/src/generated/resources/data/vampirism/loot_tables/inject/jungle_temple.json @@ -202,9 +202,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -214,9 +212,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -226,9 +222,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/inject/stronghold_corridor.json b/src/generated/resources/data/vampirism/loot_tables/inject/stronghold_corridor.json index 72a0122794..a8caf66918 100644 --- a/src/generated/resources/data/vampirism/loot_tables/inject/stronghold_corridor.json +++ b/src/generated/resources/data/vampirism/loot_tables/inject/stronghold_corridor.json @@ -149,9 +149,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -161,9 +159,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -173,9 +169,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/loot_tables/inject/stronghold_library.json b/src/generated/resources/data/vampirism/loot_tables/inject/stronghold_library.json index 9683aa4899..a0a151ef9b 100644 --- a/src/generated/resources/data/vampirism/loot_tables/inject/stronghold_library.json +++ b/src/generated/resources/data/vampirism/loot_tables/inject/stronghold_library.json @@ -23,9 +23,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -35,9 +33,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], @@ -47,9 +43,7 @@ "type": "minecraft:item", "functions": [ { - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "function": "vampirism:add_refinement_set" } ], diff --git a/src/generated/resources/data/vampirism/tags/vampirism/faction/all.json b/src/generated/resources/data/vampirism/tags/vampirism/faction/all.json new file mode 100644 index 0000000000..d3a3b8d4ef --- /dev/null +++ b/src/generated/resources/data/vampirism/tags/vampirism/faction/all.json @@ -0,0 +1,6 @@ +{ + "values": [ + "#vampirism:is_hunter", + "#vampirism:is_vampire" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/vampirism/tags/vampirism/faction/has_lord_skills.json b/src/generated/resources/data/vampirism/tags/vampirism/faction/has_lord_skills.json new file mode 100644 index 0000000000..d4bd73fb3f --- /dev/null +++ b/src/generated/resources/data/vampirism/tags/vampirism/faction/has_lord_skills.json @@ -0,0 +1,6 @@ +{ + "values": [ + "vampirism:vampire", + "vampirism:hunter" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/vampirism/tags/vampirism/faction/hostile_towards_neutral.json b/src/generated/resources/data/vampirism/tags/vampirism/faction/hostile_towards_neutral.json new file mode 100644 index 0000000000..e05d7cbec8 --- /dev/null +++ b/src/generated/resources/data/vampirism/tags/vampirism/faction/hostile_towards_neutral.json @@ -0,0 +1,5 @@ +{ + "values": [ + "vampirism:vampire" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/vampirism/tags/vampirism/faction/is_hunter.json b/src/generated/resources/data/vampirism/tags/vampirism/faction/is_hunter.json new file mode 100644 index 0000000000..2678c4b208 --- /dev/null +++ b/src/generated/resources/data/vampirism/tags/vampirism/faction/is_hunter.json @@ -0,0 +1,5 @@ +{ + "values": [ + "vampirism:hunter" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/vampirism/tags/vampirism/faction/is_vampire.json b/src/generated/resources/data/vampirism/tags/vampirism/faction/is_vampire.json new file mode 100644 index 0000000000..e05d7cbec8 --- /dev/null +++ b/src/generated/resources/data/vampirism/tags/vampirism/faction/is_vampire.json @@ -0,0 +1,5 @@ +{ + "values": [ + "vampirism:vampire" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/vampirism/vampirism/skill_tree/hunter/level.json b/src/generated/resources/data/vampirism/vampirism/skill_tree/hunter/level.json index 709d7a29b5..144d75f789 100644 --- a/src/generated/resources/data/vampirism/vampirism/skill_tree/hunter/level.json +++ b/src/generated/resources/data/vampirism/vampirism/skill_tree/hunter/level.json @@ -3,18 +3,14 @@ "count": 1, "id": "vampirism:vampire_book" }, - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "name": { "translate": "text.vampirism.skills.level" }, "unlock_predicate": { "type_specific": { "type": "vampirism:faction", - "faction": { - "id": "vampirism:hunter" - } + "faction": "vampirism:hunter" } } } \ No newline at end of file diff --git a/src/generated/resources/data/vampirism/vampirism/skill_tree/hunter/lord.json b/src/generated/resources/data/vampirism/vampirism/skill_tree/hunter/lord.json index 7cae9a47c9..c296e9ca81 100644 --- a/src/generated/resources/data/vampirism/vampirism/skill_tree/hunter/lord.json +++ b/src/generated/resources/data/vampirism/vampirism/skill_tree/hunter/lord.json @@ -3,18 +3,14 @@ "count": 1, "id": "vampirism:hunter_minion_equipment" }, - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "name": { "translate": "text.vampirism.skills.lord" }, "unlock_predicate": { "type_specific": { "type": "vampirism:faction", - "faction": { - "id": "vampirism:hunter" - }, + "faction": "vampirism:hunter", "lord_level": 1 } } diff --git a/src/generated/resources/data/vampirism/vampirism/skill_tree/vampire/level.json b/src/generated/resources/data/vampirism/vampirism/skill_tree/vampire/level.json index 815c6acb89..a41bad49d8 100644 --- a/src/generated/resources/data/vampirism/vampirism/skill_tree/vampire/level.json +++ b/src/generated/resources/data/vampirism/vampirism/skill_tree/vampire/level.json @@ -3,18 +3,14 @@ "count": 1, "id": "vampirism:vampire_book" }, - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "name": { "translate": "text.vampirism.skills.level" }, "unlock_predicate": { "type_specific": { "type": "vampirism:faction", - "faction": { - "id": "vampirism:vampire" - } + "faction": "vampirism:vampire" } } } \ No newline at end of file diff --git a/src/generated/resources/data/vampirism/vampirism/skill_tree/vampire/lord.json b/src/generated/resources/data/vampirism/vampirism/skill_tree/vampire/lord.json index 3ad97f636f..2334683620 100644 --- a/src/generated/resources/data/vampirism/vampirism/skill_tree/vampire/lord.json +++ b/src/generated/resources/data/vampirism/vampirism/skill_tree/vampire/lord.json @@ -3,18 +3,14 @@ "count": 1, "id": "vampirism:vampire_minion_binding" }, - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "name": { "translate": "text.vampirism.skills.lord" }, "unlock_predicate": { "type_specific": { "type": "vampirism:faction", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "lord_level": 1 } } diff --git a/src/generated/resources/data/vampirism/vampirism/tasks/random_rare_refinement.json b/src/generated/resources/data/vampirism/vampirism/tasks/random_rare_refinement.json index 8cc39b4f9f..8b2a1ecc9e 100644 --- a/src/generated/resources/data/vampirism/vampirism/tasks/random_rare_refinement.json +++ b/src/generated/resources/data/vampirism/vampirism/tasks/random_rare_refinement.json @@ -14,9 +14,7 @@ }, "rewards": { "type": "vampirism:refinement", - "faction": { - "id": "vampirism:vampire" - }, + "faction": "vampirism:vampire", "rarity": "rare" }, "title": { diff --git a/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement1.json b/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement1.json index 0e74cb4679..54bb11931d 100644 --- a/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement1.json +++ b/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement1.json @@ -25,9 +25,7 @@ }, "rewards": { "type": "vampirism:refinement", - "faction": { - "id": "vampirism:vampire" - } + "faction": "vampirism:vampire" }, "title": { "translate": "task.vampirism.random_refinement1" diff --git a/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement2.json b/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement2.json index 7d4e4ddd12..ec53d6dfa1 100644 --- a/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement2.json +++ b/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement2.json @@ -25,9 +25,7 @@ }, "rewards": { "type": "vampirism:refinement", - "faction": { - "id": "vampirism:vampire" - } + "faction": "vampirism:vampire" }, "title": { "translate": "task.vampirism.random_refinement2" diff --git a/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement3.json b/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement3.json index 26963f41fd..adebaf3af4 100644 --- a/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement3.json +++ b/src/generated/resources/data/vampirism/vampirism/tasks/random_refinement3.json @@ -25,9 +25,7 @@ }, "rewards": { "type": "vampirism:refinement", - "faction": { - "id": "vampirism:vampire" - } + "faction": "vampirism:vampire" }, "title": { "translate": "task.vampirism.random_refinement3" diff --git a/src/main/java/de/teamlapen/vampirism/VampirismMod.java b/src/main/java/de/teamlapen/vampirism/VampirismMod.java index f839d80cc3..dd0da03a49 100755 --- a/src/main/java/de/teamlapen/vampirism/VampirismMod.java +++ b/src/main/java/de/teamlapen/vampirism/VampirismMod.java @@ -249,6 +249,7 @@ private void prepareAPI() { .addTag(Registries.VILLAGER_PROFESSION, ModProfessionTags.IS_VAMPIRE) .addTag(Registries.ENTITY_TYPE, ModEntityTags.VAMPIRE) .addTag(VampirismRegistries.Keys.TASK, ModTaskTags.IS_VAMPIRE) + .addTag(VampirismRegistries.Keys.FACTION, ModFactionTags.IS_VAMPIRE) .register(); VReference.HUNTER_FACTION = VampirismAPI.factionRegistry() .createPlayableFaction(VReference.HUNTER_FACTION_ID, IHunterPlayer.class, () -> (AttachmentType)(Object) ModAttachments.HUNTER_PLAYER.get()) @@ -273,6 +274,7 @@ private void prepareAPI() { .addTag(Registries.VILLAGER_PROFESSION, ModProfessionTags.IS_HUNTER) .addTag(Registries.ENTITY_TYPE, ModEntityTags.HUNTER) .addTag(VampirismRegistries.Keys.TASK, ModTaskTags.IS_HUNTER) + .addTag(VampirismRegistries.Keys.FACTION, ModFactionTags.IS_HUNTER) .register(); VReference.vision_nightVision = VampirismAPI.vampireVisionRegistry().registerVision(new ResourceLocation(REFERENCE.MODID, "night_vision"), new NightVision()); diff --git a/src/main/java/de/teamlapen/vampirism/advancements/critereon/FactionCriterionTrigger.java b/src/main/java/de/teamlapen/vampirism/advancements/critereon/FactionCriterionTrigger.java index 58ecea2fc9..3f2cb902b8 100644 --- a/src/main/java/de/teamlapen/vampirism/advancements/critereon/FactionCriterionTrigger.java +++ b/src/main/java/de/teamlapen/vampirism/advancements/critereon/FactionCriterionTrigger.java @@ -2,12 +2,16 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.core.ModAdvancements; +import de.teamlapen.vampirism.core.ModRegistries; +import de.teamlapen.vampirism.util.FactionCodec; import net.minecraft.advancements.Criterion; import net.minecraft.advancements.critereon.ContextAwarePredicate; import net.minecraft.advancements.critereon.EntityPredicate; import net.minecraft.advancements.critereon.SimpleCriterionTrigger; +import net.minecraft.core.Holder; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.ExtraCodecs; import net.minecraft.util.StringRepresentable; @@ -20,7 +24,7 @@ public class FactionCriterionTrigger extends SimpleCriterionTrigger { - public void trigger(@NotNull ServerPlayer player, IPlayableFaction faction, int level, int lordLevel) { + public void trigger(@NotNull ServerPlayer player, Holder> faction, int level, int lordLevel) { this.trigger(player, instance -> instance.matches(faction, level, lordLevel)); } @@ -28,7 +32,7 @@ public void revokeAll(ServerPlayer player) { this.revoke(player, instance -> true); } - public void revokeLevel(ServerPlayer player, IPlayableFaction faction, Type type, int newLevel) { + public void revokeLevel(ServerPlayer player, Holder> faction, Type type, int newLevel) { this.revoke(player, instance -> instance.faction == faction && instance.type == type && instance.level > newLevel); } @@ -69,31 +73,31 @@ public enum Type implements StringRepresentable { } } - public record TriggerInstance(@NotNull Optional player, @NotNull Type type, @Nullable IPlayableFaction faction, int level) implements SimpleCriterionTrigger.SimpleInstance { + public record TriggerInstance(@NotNull Optional player, @NotNull Type type, @Nullable Holder> faction, int level) implements SimpleCriterionTrigger.SimpleInstance { public static final Codec CODEC = RecordCodecBuilder.create(inst -> { return inst.group( EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("player").forGetter(TriggerInstance::player), StringRepresentable.fromEnum(Type::values).fieldOf("type").forGetter(TriggerInstance::type), - IPlayableFaction.CODEC.optionalFieldOf("faction").forGetter(p -> Optional.ofNullable(p.faction())), + FactionCodec.playable().optionalFieldOf("faction").forGetter(p -> Optional.ofNullable(p.faction())), ExtraCodecs.POSITIVE_INT.fieldOf("level").forGetter(TriggerInstance::level) ).apply(inst, TriggerInstance::new); }); - public static Criterion level(@Nullable IPlayableFaction faction, int level) { + public static Criterion level(@Nullable Holder> faction, int level) { return ModAdvancements.TRIGGER_FACTION.get().createCriterion(new TriggerInstance(Optional.empty(), Type.LEVEL, faction, level)); } - public static Criterion lord(@Nullable IPlayableFaction faction, int level) { + public static Criterion lord(@Nullable Holder> faction, int level) { return ModAdvancements.TRIGGER_FACTION.get().createCriterion(new TriggerInstance(Optional.empty(), Type.LORD, faction, level)); } @SuppressWarnings("OptionalUsedAsFieldOrParameterType") - public TriggerInstance(@NotNull Optional player, @NotNull Type type, @NotNull Optional> faction, int level) { + public TriggerInstance(@NotNull Optional player, @NotNull Type type, @NotNull Optional>> faction, int level) { this(player, type, faction.orElse(null), level); } - public boolean matches(IPlayableFaction faction, int level, int lordLevel) { + public boolean matches(Holder> faction, int level, int lordLevel) { if ((faction == null && this.faction == null) || Objects.equals(this.faction, faction)) { if (type == Type.LEVEL) { return level >= this.level; diff --git a/src/main/java/de/teamlapen/vampirism/advancements/critereon/FactionSubPredicate.java b/src/main/java/de/teamlapen/vampirism/advancements/critereon/FactionSubPredicate.java index 9925daf383..e51033df64 100644 --- a/src/main/java/de/teamlapen/vampirism/advancements/critereon/FactionSubPredicate.java +++ b/src/main/java/de/teamlapen/vampirism/advancements/critereon/FactionSubPredicate.java @@ -3,9 +3,13 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; +import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; +import de.teamlapen.vampirism.entity.factions.PlayableFaction; import net.minecraft.advancements.critereon.EntitySubPredicate; +import net.minecraft.core.Holder; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -18,37 +22,38 @@ @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public class FactionSubPredicate implements EntitySubPredicate { + @SuppressWarnings("unchecked") public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(inst -> inst.group( - IPlayableFaction.CODEC.optionalFieldOf("faction", null).forGetter(p -> p.faction), + ModRegistries.FACTIONS.holderByNameCodec().optionalFieldOf("faction", null).forGetter(p -> (Holder>) p.faction), Codec.INT.optionalFieldOf( "level").forGetter(p -> p.level), Codec.INT.optionalFieldOf("lord_level").forGetter(p -> p.lordLevel) ).apply(inst, FactionSubPredicate::new) ); @Nullable - private final IPlayableFaction faction; + private final Holder> faction; @NotNull private final Optional level; @NotNull private final Optional lordLevel; @SuppressWarnings("OptionalUsedAsFieldOrParameterType") - private FactionSubPredicate(@Nullable IPlayableFaction faction, @NotNull Optional level, @NotNull Optional lordLevel) { + private FactionSubPredicate(@Nullable Holder> faction, @NotNull Optional level, @NotNull Optional lordLevel) { this.faction = faction; this.level = level; this.lordLevel = lordLevel; } - public static FactionSubPredicate faction(@NotNull IPlayableFaction faction) { + public static FactionSubPredicate faction(@NotNull Holder> faction) { return new FactionSubPredicate(faction, Optional.empty(), Optional.empty()); } - public static FactionSubPredicate level(@NotNull IPlayableFaction faction, int level) { + public static FactionSubPredicate level(@NotNull Holder> faction, int level) { return new FactionSubPredicate(faction, Optional.of(level), Optional.empty()); } - public static FactionSubPredicate lord(@NotNull IPlayableFaction faction, int lordLevel) { + public static FactionSubPredicate lord(@NotNull Holder> faction, int lordLevel) { return new FactionSubPredicate(faction, Optional.empty(), Optional.of(lordLevel)); } @@ -56,7 +61,7 @@ public static FactionSubPredicate lord(int lordLevel) { return new FactionSubPredicate(null, Optional.empty(), Optional.of(lordLevel)); } - public static FactionSubPredicate lord(@NotNull IPlayableFaction faction) { + public static FactionSubPredicate lord(@NotNull Holder> faction) { return new FactionSubPredicate(faction, Optional.empty(), Optional.of(1)); } @@ -68,7 +73,7 @@ public static FactionSubPredicate level(int level) { public boolean matches(@NotNull Entity pEntity, @NotNull ServerLevel pLevel, @Nullable Vec3 p_218830_) { if (pEntity instanceof Player player) { FactionPlayerHandler fph = FactionPlayerHandler.get(player); - return (faction == null || fph.getCurrentFaction() == faction) + return (faction == null || IFaction.is(fph.getFaction(), faction)) && (level.isEmpty() || fph.getCurrentLevel() >= level.get()) && (lordLevel.isEmpty() || fph.getLordLevel() >= lordLevel.get()); } diff --git a/src/main/java/de/teamlapen/vampirism/blockentity/AltarInfusionBlockEntity.java b/src/main/java/de/teamlapen/vampirism/blockentity/AltarInfusionBlockEntity.java index 81e9d407df..2704a965dd 100644 --- a/src/main/java/de/teamlapen/vampirism/blockentity/AltarInfusionBlockEntity.java +++ b/src/main/java/de/teamlapen/vampirism/blockentity/AltarInfusionBlockEntity.java @@ -11,6 +11,7 @@ import de.teamlapen.vampirism.client.VampirismModClient; import de.teamlapen.vampirism.core.*; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; +import de.teamlapen.vampirism.entity.factions.FactionRegistry; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.entity.player.vampire.VampireLeveling; import de.teamlapen.vampirism.entity.player.vampire.VampirePlayer; @@ -264,11 +265,11 @@ private void tickRitual() { if (!level.isClientSide) { assert player.isAlive(); FactionPlayerHandler handler = FactionPlayerHandler.get(player); - if (handler.getCurrentLevel(VReference.VAMPIRE_FACTION) != targetLevel - 1) { + if (handler.getCurrentLevel(ModFactions.VAMPIRE) != targetLevel - 1) { LOGGER.warn("Player {} changed level while the ritual was running. Cannot levelup.", player); return; } - handler.setFactionLevel(VReference.VAMPIRE_FACTION, handler.getCurrentLevel(VReference.VAMPIRE_FACTION) + 1); + handler.setFactionLevel(ModFactions.VAMPIRE, handler.getCurrentLevel(ModFactions.VAMPIRE) + 1); VampirePlayer.get(player).drinkBlood(Integer.MAX_VALUE, 0, false, DrinkBloodContext.none()); if (player instanceof ServerPlayer serverPlayer) { ModAdvancements.TRIGGER_VAMPIRE_ACTION.get().trigger(serverPlayer, VampireActionCriterionTrigger.Action.PERFORM_RITUAL_INFUSION); diff --git a/src/main/java/de/teamlapen/vampirism/blockentity/AltarInspirationBlockEntity.java b/src/main/java/de/teamlapen/vampirism/blockentity/AltarInspirationBlockEntity.java index 4c6577d652..7b1c794294 100644 --- a/src/main/java/de/teamlapen/vampirism/blockentity/AltarInspirationBlockEntity.java +++ b/src/main/java/de/teamlapen/vampirism/blockentity/AltarInspirationBlockEntity.java @@ -2,6 +2,7 @@ import de.teamlapen.lib.lib.util.FluidTankWithListener; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModFluids; import de.teamlapen.vampirism.core.ModParticles; import de.teamlapen.vampirism.core.ModTiles; @@ -158,7 +159,7 @@ public static void serverTick(@NotNull Level level, @NotNull BlockPos pos, Block int blood = req.map(VampireLeveling.AltarInspirationRequirement::bloodAmount).orElse(0) * VReference.FOOD_TO_FLUID_BLOOD; ((InternalTank) blockEntity.tank).doDrain(blood, IFluidHandler.FluidAction.EXECUTE); blockEntity.ritualPlayer.addEffect(new MobEffectInstance(MobEffects.REGENERATION, blockEntity.targetLevel * 10 * 20)); - FactionPlayerHandler.get(blockEntity.ritualPlayer).setFactionLevel(VReference.VAMPIRE_FACTION, blockEntity.targetLevel); + FactionPlayerHandler.get(blockEntity.ritualPlayer).setFactionLevel(ModFactions.VAMPIRE, blockEntity.targetLevel); VampirePlayer.get(blockEntity.ritualPlayer).drinkBlood(Integer.MAX_VALUE, 0, false, DrinkBloodContext.none()); } } diff --git a/src/main/java/de/teamlapen/vampirism/blockentity/MotherBlockEntity.java b/src/main/java/de/teamlapen/vampirism/blockentity/MotherBlockEntity.java index 202e074d67..b30a1c6111 100644 --- a/src/main/java/de/teamlapen/vampirism/blockentity/MotherBlockEntity.java +++ b/src/main/java/de/teamlapen/vampirism/blockentity/MotherBlockEntity.java @@ -326,8 +326,8 @@ public void concludeFight() { ModAdvancements.TRIGGER_MOTHER_WIN.get().trigger(serverplayer); serverplayer.awardStat(ModStats.MOTHER_DEFEATED.get(), 1); FactionPlayerHandler handler = FactionPlayerHandler.get(serverplayer); - if (handler.getCurrentFaction() != null && handler.getCurrentLevel() < handler.getCurrentFaction().getHighestReachableLevel()) { - handler.setFactionLevel(handler.getCurrentFaction(), handler.getCurrentLevel() + 1); + if (handler.getFaction() != null && handler.getCurrentLevel() < handler.getFaction().value().getHighestReachableLevel()) { + handler.setFactionLevel(handler.getFaction(), handler.getCurrentLevel() + 1); } } } diff --git a/src/main/java/de/teamlapen/vampirism/blockentity/TotemBlockEntity.java b/src/main/java/de/teamlapen/vampirism/blockentity/TotemBlockEntity.java index f9cb2b4f28..4519cc725c 100644 --- a/src/main/java/de/teamlapen/vampirism/blockentity/TotemBlockEntity.java +++ b/src/main/java/de/teamlapen/vampirism/blockentity/TotemBlockEntity.java @@ -7,6 +7,7 @@ import de.teamlapen.lib.util.Color; import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; +import de.teamlapen.vampirism.api.VampirismRegistries; import de.teamlapen.vampirism.api.entity.*; import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; @@ -18,6 +19,7 @@ import de.teamlapen.vampirism.blocks.TotemTopBlock; import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.*; +import de.teamlapen.vampirism.core.tags.ModFactionTags; import de.teamlapen.vampirism.core.tags.ModProfessionTags; import de.teamlapen.vampirism.effects.SanguinareEffect; import de.teamlapen.vampirism.effects.SanguinareEffectInstance; @@ -91,6 +93,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; +import java.util.stream.Collectors; import static de.teamlapen.vampirism.util.TotemHelper.*; @@ -114,15 +117,15 @@ public static void makeAgressive(@NotNull Villager villager) { @NotNull private Set village = Sets.newHashSet(); /** - * use {@link #setControllingFaction(IFaction)} + * use {@link #setControllingFaction(net.minecraft.core.Holder)} */ @Nullable - private IFaction controllingFaction; + private Holder> controllingFaction; /** - * use {@link #setCapturingFaction(IFaction)} + * use {@link #setCapturingFaction(net.minecraft.core.Holder)} */ @Nullable - private IFaction capturingFaction; + private Holder> capturingFaction; /** * use {@link #getVillageArea()} */ @@ -135,7 +138,7 @@ public static void makeAgressive(@NotNull Villager villager) { private AABB villageAreaReduced; //forced attributes @Nullable - private IFaction forcedFaction; + private Holder> forcedFaction; private int forcedFactionTimer; private boolean forceVillageUpdate; //capturing attributes @@ -183,7 +186,7 @@ public void breakCapture() { public boolean canPlayerRemoveBlock(@NotNull Player player) { if (player.getAbilities().instabuild) return true; if (!player.isAlive()) return false; - @Nullable IFaction faction = VampirismPlayerAttributes.get(player).faction; + @Nullable Holder> faction = VampirismPlayerAttributes.get(player).faction; if (faction == this.controllingFaction) { if (this.capturingFaction == null) { return true; @@ -212,8 +215,8 @@ public float[] getBaseColors() { } @Override - public @NotNull Optional> getCaptureEntityForFaction(@NotNull IFaction faction) { - return WeightedRandom.getRandomItem(RNG, faction.getVillageData().getCaptureEntries()).map(CaptureEntityEntry::getEntity); + public @NotNull Optional> getCaptureEntityForFaction(@NotNull Holder> faction) { + return WeightedRandom.getRandomItem(RNG, faction.value().getVillageData().getCaptureEntries()).map(CaptureEntityEntry::getEntity); } /** @@ -229,7 +232,7 @@ public float[] getCapturingColors() { @Nullable @Override - public IFaction getCapturingFaction() { + public Holder> getCapturingFaction() { return capturingFaction; } @@ -241,7 +244,7 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() { @Nullable @Override - public IFaction getControllingFaction() { + public Holder> getControllingFaction() { return controllingFaction; } @@ -291,11 +294,11 @@ public AABB getVillageAreaReduced() { /** * @param faction attacking faction - * @param feedback interaction feedback supplier if capture cannot be started {@link #capturePreconditions(IFaction, BiConsumer)} + * @param feedback interaction feedback supplier if capture cannot be started {@link #capturePreconditions(net.minecraft.core.Holder, java.util.function.BiConsumer)} * @param badOmenLevel level of the badomen effect that triggered the raid (effect amplifier + 1). -1 if not triggered by bad omen. * @param strengthModifier modifier of the faction strength ration. See {@link #calculateAttackStrength(int, float)} */ - public void initiateCapture(@NotNull IFaction faction, @Nullable BiConsumer feedback, int badOmenLevel, float strengthModifier) { + public void initiateCapture(@NotNull Holder> faction, @Nullable BiConsumer feedback, int badOmenLevel, float strengthModifier) { this.updateTileStatus(); if (!this.capturePreconditions(faction, feedback == null ? (a, b) -> { } : feedback)) { @@ -312,17 +315,17 @@ public void initiateCapture(@NotNull IFaction faction, @Nullable BiConsumer { + this.setCapturingFaction(holder); + this.captureTimer = compound.getInt("captureTimer"); + this.captureDuration = compound.getInt("captureDuration"); + this.phase = CAPTURE_PHASE.valueOf(compound.getString("phase")); + this.strengthRatio = compound.getFloat("strengthRatio"); + this.captureAbortTimer = compound.getInt("captureAbortTimer"); + if (this.phase == CAPTURE_PHASE.PHASE_2) { + this.setupPhase2(); + } + }, () -> this.setCapturingFaction(null)); } else { this.setCapturingFaction(null); } @@ -354,8 +360,9 @@ public void loadAdditional(@NotNull CompoundTag compound, HolderLookup.Provider if (compound.contains("villageArea")) { FogLevel.getOpt(this.level).ifPresent(vw -> { AABB aabb = UtilLib.intToBB(compound.getIntArray("villageArea")); - vw.updateArtificialFogBoundingBox(this.worldPosition, this.controllingFaction == VReference.VAMPIRE_FACTION ? aabb : null); - if (this.isRaidTriggeredByBadOmen() && this.capturingFaction == VReference.VAMPIRE_FACTION) { + // noinspection UnclearExpression + vw.updateArtificialFogBoundingBox(this.worldPosition, IFaction.is(this.controllingFaction, ModFactions.VAMPIRE) ? aabb : null); + if (this.isRaidTriggeredByBadOmen() && IFaction.is(this.capturingFaction, ModFactions.VAMPIRE)) { vw.updateTemporaryArtificialFog(this.worldPosition, aabb); } }); @@ -385,12 +392,12 @@ public void notifyNearbyPlayers(@NotNull Component textComponent) { * initiates a new capture or increases the badomen level of a running capture * * @param faction attacking faction - * @param feedback interaction feedback supplier if capture cannot be started {@link #capturePreconditions(IFaction, BiConsumer)} + * @param feedback interaction feedback supplier if capture cannot be started {@link #capturePreconditions(net.minecraft.core.Holder, java.util.function.BiConsumer)} * @param badOmenLevel level of the badomen effect that triggered the raid (effect amplifier + 1). -1 if not triggered by bad omen. * @param strengthModifier modifier of the faction strength ration. See {@link #calculateAttackStrength(int, float)} * @return true if the badomen effect should be consumed */ - public boolean initiateCaptureOrIncreaseBadOmenLevel(@NotNull IFaction faction, @Nullable BiConsumer feedback, int badOmenLevel, float strengthModifier) { + public boolean initiateCaptureOrIncreaseBadOmenLevel(@NotNull Holder> faction, @Nullable BiConsumer feedback, int badOmenLevel, float strengthModifier) { if (this.capturingFaction == null) { this.initiateCapture(faction, feedback, badOmenLevel, strengthModifier); return true; @@ -423,18 +430,18 @@ public void onDataPacket(@NotNull Connection net, @NotNull ClientboundBlockEntit public void ringBell(@NotNull Player playerEntity) { if (this.capturingFaction != null) { - IPlayableFaction faction = VampirismPlayerAttributes.get(playerEntity).faction; + Holder> faction = VampirismPlayerAttributes.get(playerEntity).faction; boolean defender = faction == this.controllingFaction; boolean attacker = faction == this.capturingFaction; List entities = this.level.getEntitiesOfClass(LivingEntity.class, getVillageArea()); for (LivingEntity entity : entities) { - IFaction f = VampirismAPI.factionRegistry().getFaction(entity); + Holder> f = VampirismAPI.factionRegistry().getFactionHolder(entity); if (f == null) continue; if (entity instanceof ICaptureIgnore) { continue; - } else if (attacker && this.capturingFaction == f) { + } else if (attacker && IFaction.is(this.capturingFaction, f)) { continue; - } else if (defender && this.controllingFaction == f) continue; + } else if (defender && IFaction.is(this.controllingFaction, f)) continue; entity.addEffect(new MobEffectInstance(MobEffects.GLOWING, 120)); } } @@ -446,17 +453,17 @@ public void saveAdditional(@NotNull CompoundTag compound, HolderLookup.Provider compound.putBoolean("isDisabled", this.isDisabled); compound.putBoolean("isComplete", this.isComplete); compound.putBoolean("isInsideVillage", this.isInsideVillage); - if (this.controllingFaction != null) { - compound.putString("controllingFaction", this.controllingFaction.getID().toString()); - } - if (this.capturingFaction != null) { - compound.putString("capturingFaction", this.capturingFaction.getID().toString()); + Optional.ofNullable(this.controllingFaction).flatMap(Holder::unwrapKey).map(ResourceKey::location).map(ResourceLocation::toString).ifPresent(faction -> { + compound.putString("controllingFaction", faction); + }); + Optional.ofNullable(this.capturingFaction).flatMap(Holder::unwrapKey).map(ResourceKey::location).map(ResourceLocation::toString).ifPresent(faction -> { + compound.putString("capturingFaction", faction); compound.putInt("captureTimer", this.captureTimer); compound.putFloat("strengthRatio", this.strengthRatio); compound.putInt("captureDuration", this.captureDuration); compound.putInt("captureAbortTimer", this.captureAbortTimer); compound.putString("phase", this.phase.name()); - } + }); if (!village.isEmpty()) { compound.putIntArray("villageArea", UtilLib.bbToInt(this.getVillageArea())); } @@ -479,8 +486,8 @@ public void setChanged() { this.level.sendBlockUpdated(this.worldPosition, this.level.getBlockState(this.worldPosition), this.level.getBlockState(this.worldPosition), 3); if (!this.village.isEmpty()) { FogLevel.getOpt(this.level).ifPresent(vw -> { - vw.updateArtificialFogBoundingBox(this.worldPosition, this.controllingFaction == VReference.VAMPIRE_FACTION ? this.getVillageArea() : null); - if (this.isRaidTriggeredByBadOmen() && this.capturingFaction == VReference.VAMPIRE_FACTION) { + vw.updateArtificialFogBoundingBox(this.worldPosition, IFaction.is(this.controllingFaction, ModFactions.VAMPIRE) ? this.getVillageArea() : null); + if (this.isRaidTriggeredByBadOmen() && IFaction.is(this.capturingFaction, ModFactions.VAMPIRE)) { vw.updateTemporaryArtificialFog(this.worldPosition, this.getVillageArea()); } }); @@ -489,7 +496,7 @@ public void setChanged() { } } - public void setForcedFaction(@Nullable IFaction faction) { + public void setForcedFaction(@Nullable Holder> faction) { this.forcedFaction = faction; this.forcedFactionTimer = 5; this.setChanged(); @@ -552,7 +559,7 @@ public float shouldRenderBeam() { public static void clientTick(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull TotemBlockEntity blockEntity) { if (level.getGameTime() % 10 == 7 && blockEntity.controllingFaction != null) { - ModParticles.spawnParticlesClient(level, new GenericParticleOptions(new ResourceLocation("minecraft", "generic_4"), 20, blockEntity.controllingFaction.getColor(), 0.2F), pos.getX(), pos.getY(), pos.getZ(), 3, 30, level.random); + ModParticles.spawnParticlesClient(level, new GenericParticleOptions(new ResourceLocation("minecraft", "generic_4"), 20, blockEntity.controllingFaction.value().getColor(), 0.2F), pos.getX(), pos.getY(), pos.getZ(), 3, 30, level.random); } } @@ -568,8 +575,8 @@ private void serverTickSecondNonCapture(int timeInSeconds) { int villager = this.level.getEntitiesOfClass(Villager.class, this.getVillageArea().inflate(20)).size(); int max = Math.min(beds, VampirismConfig.BALANCE.viMaxVillagerRespawn.get()); if (villager < max) { - boolean isConverted = this.controllingFaction == VReference.VAMPIRE_FACTION && RNG.nextBoolean(); - this.spawnVillagerDefault(this.controllingFaction == VReference.HUNTER_FACTION, isConverted); + boolean isConverted = IFaction.is(this.controllingFaction, ModFactions.VAMPIRE) && RNG.nextBoolean(); + this.spawnVillagerDefault(IFaction.is(this.controllingFaction, ModFactions.VAMPIRE), isConverted); } else { spawnTaskMaster = true; @@ -578,7 +585,7 @@ private void serverTickSecondNonCapture(int timeInSeconds) { this.spawnTaskMaster(); } int defenderNumMax = Math.min(6, this.village.size() / 5); - List guards = this.level.getEntitiesOfClass(this.controllingFaction.getVillageData().getGuardSuperClass(), this.getVillageArea()); + List guards = this.level.getEntitiesOfClass(this.controllingFaction.value().getVillageData().getGuardSuperClass(), this.getVillageArea()); if (defenderNumMax > guards.size()) { getCaptureEntityForFaction(this.controllingFaction).ifPresent(entityType -> this.spawnEntity(entityType.create(this.level))); } @@ -586,7 +593,7 @@ private void serverTickSecondNonCapture(int timeInSeconds) { //Random raids if (timeSinceLastRaid > 12000 && this.level.getDifficulty() != Difficulty.PEACEFUL && this.level.random.nextFloat() < VampirismConfig.BALANCE.viRandomRaidChance.get()) { - List> factions = Lists.newArrayList(VampirismAPI.factionRegistry().getFactions()); + List>> factions = (List>>) (Object) ModRegistries.FACTIONS.holders().collect(Collectors.toList()); if (this.controllingFaction != null) { factions.remove(this.controllingFaction); } @@ -616,11 +623,11 @@ private void serverTickSecondCapture(int timeInSeconds) { //count entities CaptureInfo captureInfo = new CaptureInfo(this); for (LivingEntity entity : entities) { - IFaction faction = VampirismAPI.factionRegistry().getFaction(entity); + Holder> faction = VampirismAPI.factionRegistry().getFactionHolder(entity); if (faction == null) continue; if (entity instanceof ICaptureIgnore) continue; if (!entity.isAlive()) continue; - if (this.capturingFaction.equals(faction)) { + if (IFaction.is(this.capturingFaction, faction)) { currentAttacker++; attackerStrength += this.getStrength(entity); attackerMaxHealth += entity.getMaxHealth(); @@ -629,7 +636,7 @@ private void serverTickSecondCapture(int timeInSeconds) { if (entity instanceof IVillageCaptureEntity captureEntity) { captureEntity.attackVillage(captureInfo); } - } else if (faction.equals(this.controllingFaction)) { + } else if (IFaction.is(faction, this.controllingFaction)) { currentDefender++; defenderStrength += this.getStrength(entity); defenderMaxHealth += entity.getMaxHealth(); @@ -781,9 +788,13 @@ public void updateTileStatus() { if (!(this.isComplete = b instanceof TotemTopBlock && serverLevel.getBlockState(this.worldPosition.below()).getBlock().equals(ModBlocks.TOTEM_BASE.get()))) { return; } - ResourceLocation blockFaction = ((TotemTopBlock) b).faction; - if (!(blockFaction.equals(this.controllingFaction == null ? nonFactionTotem : this.controllingFaction.getID()))) { //If block faction does not match tile faction, force the tile to update to the block faction - this.forcedFaction = VampirismAPI.factionRegistry().getFactionByID(blockFaction); + Holder> blockFaction = ((TotemTopBlock) b).faction; + if (blockFaction == null) { + if (this.controllingFaction != null) { + this.setControllingFaction(null); + } + } else if (blockFaction != this.controllingFaction) { + this.setControllingFaction(blockFaction); } Set points = TotemHelper.getVillagePointsOfInterest(serverLevel, this.worldPosition); if (!(this.isInsideVillage = !points.isEmpty())) { @@ -832,7 +843,7 @@ public void updateTrainer(boolean toDummy) { private void applyVictoryBonus(boolean attackWin) { for (Player player : level.players()) { if (!player.isSpectator() && this.getVillageArea().contains(player.position())) { - if (!player.isSpectator() && VampirismAPI.factionRegistry().getFaction(player) == (attackWin ? this.capturingFaction : this.controllingFaction)) { + if (!player.isSpectator() && IFaction.is(VampirismAPI.factionRegistry().getFactionHolder(player), (attackWin ? this.capturingFaction : this.controllingFaction))) { if (!attackWin) { player.addEffect(new MobEffectInstance(MobEffects.HERO_OF_THE_VILLAGE, 48000, Math.max(this.badOmenLevel - 1, 0), false, false, true)); } @@ -847,7 +858,7 @@ private void applyVictoryBonus(boolean attackWin) { } } - private boolean capturePreconditions(@Nullable IFaction faction, @NotNull BiConsumer feedback) { + private boolean capturePreconditions(@Nullable Holder> faction, @NotNull BiConsumer feedback) { if (faction == null) { feedback.accept(Component.translatable("text.vampirism.village.no_faction"), true); return false; @@ -917,7 +928,7 @@ private void completeCapture(boolean notifyPlayer, boolean fullConvert) { if (notifyPlayer) { assert controllingFaction != null; - this.notifyNearbyPlayers(Component.translatable("text.vampirism.village.village_captured_by", controllingFaction.getNamePlural())); + this.notifyNearbyPlayers(Component.translatable("text.vampirism.village.village_captured_by", controllingFaction.value().getNamePlural())); } this.updateBossinfoPlayers(null); this.setChanged(); @@ -968,7 +979,7 @@ private void makeAgressive() { for (Villager villager : villagerEntities) { if (villager instanceof IFactionEntity) continue; if (VampirismEventFactory.fireMakeAggressive(this, villager)) { - if (VReference.VAMPIRE_FACTION.equals(this.capturingFaction)) { + if (IFaction.is(this.capturingFaction, ModFactions.VAMPIRE)) { if (villager.getAge() < 0) continue; if (RNG.nextInt(3) == 0) { makeAgressive(villager); @@ -1009,23 +1020,23 @@ private void handleBossBar(float defenderMaxHealth, float defenderHealth, float this.captureInfo.setPercentage(neutralPerc * attackerHealth / max, 1 - neutralPerc, neutralPerc * defenderHealth / max); } - private void setCapturingFaction(@Nullable IFaction faction) { + private void setCapturingFaction(@Nullable Holder> faction) { this.capturingFaction = faction; - this.progressColor = faction != null ? new Color(faction.getColor()).getRGBColorComponents() : DyeColor.WHITE.getTextureDiffuseColors(); + this.progressColor = faction != null ? new Color(faction.value().getColor()).getRGBColorComponents() : DyeColor.WHITE.getTextureDiffuseColors(); if (faction != null) { - this.captureInfo.setColors(new Color(faction.getColor()), Color.WHITE, this.controllingFaction == null ? Color.WHITE : new Color(this.controllingFaction.getColor())); - this.captureInfo.setName(Component.translatable("text.vampirism.village.bossinfo.raid", faction.getName().plainCopy().withStyle(style -> style.withColor((faction.getChatColor()))))); + this.captureInfo.setColors(new Color(faction.value().getColor()), Color.WHITE, this.controllingFaction == null ? Color.WHITE : new Color(this.controllingFaction.value().getColor())); + this.captureInfo.setName(Component.translatable("text.vampirism.village.bossinfo.raid", faction.value().getName().plainCopy().withStyle(style -> style.withColor((faction.value().getChatColor()))))); } } - private void setControllingFaction(@Nullable IFaction faction) { + private void setControllingFaction(@Nullable Holder> faction) { this.controllingFaction = faction; - this.baseColors = faction != null ? new Color(faction.getColor()).getRGBColorComponents() : DyeColor.WHITE.getTextureDiffuseColors(); + this.baseColors = faction != null ? new Color(faction.value().getColor()).getRGBColorComponents() : DyeColor.WHITE.getTextureDiffuseColors(); if (this.level != null) { BlockState oldBlockState = this.getBlockState(); Block b = oldBlockState.getBlock(); boolean crafted = b instanceof TotemTopBlock totem && totem.isCrafted(); - BlockState newBlockState = (faction == null ? crafted ? ModBlocks.TOTEM_TOP_CRAFTED.get() : ModBlocks.TOTEM_TOP.get() : faction.getVillageData().getTotemTopBlock(crafted)).defaultBlockState(); + BlockState newBlockState = (faction == null ? crafted ? ModBlocks.TOTEM_TOP_CRAFTED.get() : ModBlocks.TOTEM_TOP.get() : faction.value().getVillageData().getTotemTopBlock(crafted)).defaultBlockState(); try { //https://github.com/TeamLapen/Vampirism/issues/793 no idea what might cause this this.level.setBlock(this.worldPosition, newBlockState, 55); } catch (IllegalStateException e) { @@ -1042,7 +1053,7 @@ private void setupPhase2() { } } - private void spawnCaptureEntity(@Nullable IFaction faction) { + private void spawnCaptureEntity(@Nullable Holder> faction) { if (faction == null) return; assert this.level instanceof ServerLevel; EntityType entityType = this.getCaptureEntityForFaction(faction).orElse(null); @@ -1099,7 +1110,7 @@ private void spawnEntity(@NotNull Mob newEntity, @NotNull Mob oldEntity, boolean private void spawnTaskMaster() { assert level instanceof ServerLevel; assert this.controllingFaction != null; - EntityType entity = this.controllingFaction.getVillageData().getTaskMasterEntity(); + EntityType entity = this.controllingFaction.value().getVillageData().getTaskMasterEntity(); if (entity != null) { ITaskMasterEntity newEntity = entity.create(this.level); newEntity.setHome(this.getVillageAreaReduced()); @@ -1172,7 +1183,7 @@ private void updateCreaturesOnCapture(boolean fullConvert) { if (VampirismEventFactory.fireVillagerCaptureEventPre(this, villagerEntities, fullConvert)) { return; } - if (VReference.HUNTER_FACTION.equals(this.capturingFaction)) { + if (ModFactions.HUNTER.match(this.capturingFaction)) { List hunterEntities = this.level.getEntitiesOfClass(HunterBaseEntity.class, getVillageArea()); int i = Math.max(2, hunterEntities.size() / 2); for (HunterBaseEntity hunter : hunterEntities) { @@ -1191,7 +1202,7 @@ private void updateCreaturesOnCapture(boolean fullConvert) { } this.updateTrainer(false); - } else if (VReference.HUNTER_FACTION.equals(this.controllingFaction)) { + } else if (ModFactions.HUNTER.match(this.controllingFaction)) { updateTrainer(true); for (Villager villager : villagerEntities) { ExtendedCreature.getSafe(villager).ifPresent(e -> e.setPoisonousBlood(false)); @@ -1210,7 +1221,7 @@ private void updateCreaturesOnCapture(boolean fullConvert) { updateTrainer(true); } - if (VReference.VAMPIRE_FACTION.equals(this.capturingFaction)) { + if (IFaction.is(this.capturingFaction, ModFactions.VAMPIRE)) { for (Villager villager : villagerEntities) { if (!fullConvert) { if (RNG.nextInt(2) == 1) continue; @@ -1220,14 +1231,14 @@ private void updateCreaturesOnCapture(boolean fullConvert) { } } - } else if (VReference.VAMPIRE_FACTION.equals(this.controllingFaction)) { + } else if (IFaction.is(this.controllingFaction, ModFactions.VAMPIRE)) { for (Villager villager : villagerEntities) { if (villager.hasEffect(ModEffects.SANGUINARE)) { villager.removeEffect(ModEffects.SANGUINARE); } if (fullConvert) { if (villager instanceof ConvertedVillagerEntity) { - this.spawnVillagerReplaceForced(villager, this.capturingFaction == VReference.HUNTER_FACTION, false); + this.spawnVillagerReplaceForced(villager, ModFactions.HUNTER.match(this.capturingFaction), false); } } } @@ -1297,9 +1308,9 @@ private enum CAPTURE_PHASE { public static class CaptureInfo implements ICaptureAttributes { @Nullable - private final IFaction defendingFaction; + private final Holder> defendingFaction; @Nullable - private final IFaction attackingFaction; + private final Holder> attackingFaction; private final @NotNull AABB villageArea; private final @NotNull BlockPos pos; private final boolean shouldForceTargets; @@ -1314,13 +1325,13 @@ private CaptureInfo(@NotNull TotemBlockEntity totem) { @Nullable @Override - public IFaction getAttackingFaction() { + public Holder> getAttackingFaction() { return this.attackingFaction; } @Nullable @Override - public IFaction getDefendingFaction() { + public Holder> getDefendingFaction() { return this.defendingFaction; } diff --git a/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/DiffuserBlockEntity.java b/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/DiffuserBlockEntity.java index 4049b13b09..badec10736 100644 --- a/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/DiffuserBlockEntity.java +++ b/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/DiffuserBlockEntity.java @@ -6,6 +6,7 @@ import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.inventory.diffuser.DiffuserMenu; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; @@ -142,8 +143,9 @@ public void onTouched(Player pPlayer) { } - public static boolean tryAccess(Player player, IPlayableFaction faction, Component displayName) { - if (!player.isSpectator() && VampirismAPI.factionRegistry().getFaction(player) != faction) { + public static boolean tryAccess(Player player, Holder> faction, Component displayName) { + //noinspection rawtypes,deprecation,unchecked + if (!player.isSpectator() && VampirismAPI.factionRegistry().getFactionHolder(player).is((Holder)faction)) { player.displayClientMessage(Component.translatable("text.vampirism.cannot_access_menu", displayName), true); player.playNotifySound(SoundEvents.CHEST_LOCKED, SoundSource.BLOCKS, 1.0F, 1.0F); return false; diff --git a/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/FogDiffuserBlockEntity.java b/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/FogDiffuserBlockEntity.java index c7b4ab1a68..f9e76012ac 100644 --- a/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/FogDiffuserBlockEntity.java +++ b/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/FogDiffuserBlockEntity.java @@ -3,6 +3,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.datamaps.IFogDiffuserFuel; import de.teamlapen.vampirism.core.ModDataMaps; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModTiles; import de.teamlapen.vampirism.inventory.diffuser.DiffuserMenu; import de.teamlapen.vampirism.inventory.diffuser.FogDiffuserMenu; @@ -53,7 +54,7 @@ protected void activateEffect(Level level, BlockPos blockPos, BlockState blockSt @Override public boolean canOpen(@NotNull Player pPlayer) { - return tryAccess(pPlayer, VReference.VAMPIRE_FACTION, getName()) && super.canOpen(pPlayer); + return tryAccess(pPlayer, ModFactions.VAMPIRE, getName()) && super.canOpen(pPlayer); } protected int getRange() { diff --git a/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/GarlicDiffuserBlockEntity.java b/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/GarlicDiffuserBlockEntity.java index 14e6a5c219..34e1cfa9ea 100644 --- a/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/GarlicDiffuserBlockEntity.java +++ b/src/main/java/de/teamlapen/vampirism/blockentity/diffuser/GarlicDiffuserBlockEntity.java @@ -4,6 +4,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.datamaps.IGarlicDiffuserFuel; import de.teamlapen.vampirism.core.ModDataMaps; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModTiles; import de.teamlapen.vampirism.entity.player.vampire.VampirePlayer; import de.teamlapen.vampirism.inventory.diffuser.DiffuserMenu; @@ -80,7 +81,7 @@ public boolean isInRange(BlockPos blockPos) { @Override public boolean canOpen(@NotNull Player pPlayer) { - return tryAccess(pPlayer, VReference.HUNTER_FACTION, getName()) && super.canOpen(pPlayer); + return tryAccess(pPlayer, ModFactions.HUNTER, getName()) && super.canOpen(pPlayer); } @Override diff --git a/src/main/java/de/teamlapen/vampirism/blocks/AltarCleansingBlock.java b/src/main/java/de/teamlapen/vampirism/blocks/AltarCleansingBlock.java index 283b94204a..5e4ba1e512 100644 --- a/src/main/java/de/teamlapen/vampirism/blocks/AltarCleansingBlock.java +++ b/src/main/java/de/teamlapen/vampirism/blocks/AltarCleansingBlock.java @@ -3,6 +3,7 @@ import de.teamlapen.lib.lib.util.UtilLib; import de.teamlapen.vampirism.VampirismMod; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -68,7 +69,7 @@ public String getDescriptionId() { @Override public InteractionResult useWithoutItem(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @NotNull Player player, @NotNull BlockHitResult hit) { if (!world.isClientSide || !player.isAlive()) return InteractionResult.PASS; - if (FactionPlayerHandler.get(player).isInFaction(VReference.VAMPIRE_FACTION)) { + if (FactionPlayerHandler.get(player).isInFaction(ModFactions.VAMPIRE)) { VampirismMod.proxy.displayRevertBackScreen(); return InteractionResult.SUCCESS; } diff --git a/src/main/java/de/teamlapen/vampirism/blocks/GarlicBlock.java b/src/main/java/de/teamlapen/vampirism/blocks/GarlicBlock.java index fd364a97f9..cfb7bcec62 100644 --- a/src/main/java/de/teamlapen/vampirism/blocks/GarlicBlock.java +++ b/src/main/java/de/teamlapen/vampirism/blocks/GarlicBlock.java @@ -4,6 +4,7 @@ import de.teamlapen.vampirism.api.EnumStrength; import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.entity.vampire.IVampire; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.util.DamageHandler; import de.teamlapen.vampirism.util.Helper; @@ -54,7 +55,7 @@ public GarlicBlock() { public void entityInside(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @NotNull Entity entity) { if (state.getValue(AGE) > 5 && Helper.isVampire(entity)) { if (entity instanceof Player) { - VReference.VAMPIRE_FACTION.getPlayerCapability((Player) entity).ifPresent(vamp -> DamageHandler.affectVampireGarlicDirect(vamp, EnumStrength.WEAK)); + ModFactions.VAMPIRE.get().getPlayerCapability((Player) entity).ifPresent(vamp -> DamageHandler.affectVampireGarlicDirect(vamp, EnumStrength.WEAK)); } else if (entity instanceof IVampire) { DamageHandler.affectVampireGarlicDirect((IVampire) entity, EnumStrength.WEAK); } diff --git a/src/main/java/de/teamlapen/vampirism/blocks/MedChairBlock.java b/src/main/java/de/teamlapen/vampirism/blocks/MedChairBlock.java index 722a6fbf1e..68121e67e4 100644 --- a/src/main/java/de/teamlapen/vampirism/blocks/MedChairBlock.java +++ b/src/main/java/de/teamlapen/vampirism/blocks/MedChairBlock.java @@ -3,11 +3,13 @@ import de.teamlapen.lib.lib.util.UtilLib; import de.teamlapen.vampirism.VampirismMod; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IFactionPlayerHandler; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.client.VampirismModClient; import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModEffects; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.core.ModStats; import de.teamlapen.vampirism.effects.SanguinareEffect; @@ -15,6 +17,7 @@ import de.teamlapen.vampirism.inventory.RevertBackMenu; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.util.StringRepresentable; import net.minecraft.world.InteractionHand; @@ -92,18 +95,18 @@ public ItemInteractionResult useItemOn(ItemStack stack, @NotNull BlockState stat return ItemInteractionResult.sidedSuccess(world.isClientSide); } - private boolean handleGarlicInjection(@NotNull Player player, @NotNull Level world, @NotNull IFactionPlayerHandler handler, @Nullable IPlayableFaction currentFaction) { - if (handler.canJoin(VReference.HUNTER_FACTION)) { + private boolean handleGarlicInjection(@NotNull Player player, @NotNull Level world, @NotNull IFactionPlayerHandler handler, @Nullable Holder> currentFaction) { + if (handler.canJoin(ModFactions.HUNTER)) { if (world.isClientSide) { VampirismModClient.getINSTANCE().getOverlay().makeRenderFullColor(4, 30, 0xBBBBBBFF); } else { - handler.joinFaction(VReference.HUNTER_FACTION); + handler.joinFaction(ModFactions.HUNTER); player.addEffect(new MobEffectInstance(ModEffects.POISON, 200, 1)); } return true; } else if (currentFaction != null) { if (!world.isClientSide) { - player.sendSystemMessage(Component.translatable("text.vampirism.med_chair_other_faction", currentFaction.getName())); + player.sendSystemMessage(Component.translatable("text.vampirism.med_chair_other_faction", currentFaction.value().getName())); } } return false; @@ -111,7 +114,7 @@ private boolean handleGarlicInjection(@NotNull Player player, @NotNull Level wor private boolean handleInjections(@NotNull Player player, @NotNull Level world, @NotNull ItemStack stack, @NotNull BlockPos pos) { FactionPlayerHandler handler = FactionPlayerHandler.get(player); - IPlayableFaction faction = handler.getCurrentFaction(); + Holder> faction = handler.getFaction(); if (stack.getItem().equals(ModItems.INJECTION_GARLIC.get())) { return handleGarlicInjection(player, world, handler, faction); @@ -122,12 +125,12 @@ private boolean handleInjections(@NotNull Player player, @NotNull Level world, @ return false; } - private boolean handleSanguinareInjection(@NotNull Level level, @NotNull BlockPos pos, @NotNull Player player, @NotNull IFactionPlayerHandler handler, @Nullable IPlayableFaction currentFaction) { - if (VReference.VAMPIRE_FACTION.equals(currentFaction)) { + private boolean handleSanguinareInjection(@NotNull Level level, @NotNull BlockPos pos, @NotNull Player player, @NotNull IFactionPlayerHandler handler, @Nullable Holder> currentFaction) { + if (IFaction.is(ModFactions.VAMPIRE, currentFaction)) { player.displayClientMessage(Component.translatable("text.vampirism.already_vampire"), false); return false; } - if (VReference.HUNTER_FACTION.equals(currentFaction)) { + if (ModFactions.HUNTER.match(currentFaction)) { if (!level.isClientSide) { player.openMenu(new SimpleMenuProvider(new MenuConstructor() { @Override @@ -139,7 +142,7 @@ private boolean handleSanguinareInjection(@NotNull Level level, @NotNull BlockPo return false; } if (currentFaction == null) { - if (handler.canJoin(VReference.VAMPIRE_FACTION)) { + if (handler.canJoin(ModFactions.VAMPIRE)) { if (VampirismConfig.SERVER.disableFangInfection.get()) { player.displayClientMessage(Component.translatable("text.vampirism.deactivated_by_serveradmin"), true); } else { diff --git a/src/main/java/de/teamlapen/vampirism/blocks/TotemTopBlock.java b/src/main/java/de/teamlapen/vampirism/blocks/TotemTopBlock.java index 1f39670872..ba6999a5a6 100644 --- a/src/main/java/de/teamlapen/vampirism/blocks/TotemTopBlock.java +++ b/src/main/java/de/teamlapen/vampirism/blocks/TotemTopBlock.java @@ -3,11 +3,15 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.blockentity.TotemBlockEntity; import de.teamlapen.vampirism.core.ModBlocks; +import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.core.ModStats; import de.teamlapen.vampirism.core.ModTiles; +import de.teamlapen.vampirism.util.FactionCodec; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionResult; @@ -48,7 +52,7 @@ public class TotemTopBlock extends BaseEntityBlock { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(inst -> inst.group( Codec.BOOL.fieldOf("crafted").forGetter(TotemTopBlock::isCrafted), - ResourceLocation.CODEC.fieldOf("faction").forGetter(inst2 -> inst2.faction), + FactionCodec.faction().fieldOf("faction").forGetter(inst2 -> inst2.faction), propertiesCodec() ).apply(inst, TotemTopBlock::new) ); @@ -65,17 +69,18 @@ public class TotemTopBlock extends BaseEntityBlock { return Shapes.or(a, b); } - public final ResourceLocation faction; + @Nullable + public final Holder> faction; private final boolean crafted; - public TotemTopBlock(boolean crafted, ResourceLocation faction) { + public TotemTopBlock(boolean crafted, @Nullable Holder> faction) { this(crafted, faction, Properties.of().mapColor(MapColor.STONE).strength(12, 2000).sound(SoundType.STONE).pushReaction(PushReaction.BLOCK)); } /** * @param faction faction must be faction registryname; */ - public TotemTopBlock(boolean crafted, ResourceLocation faction, Block.Properties properties) { + public TotemTopBlock(boolean crafted, @Nullable Holder> faction, Block.Properties properties) { super(properties); this.faction = faction; this.crafted = crafted; diff --git a/src/main/java/de/teamlapen/vampirism/client/ClientConfigHelper.java b/src/main/java/de/teamlapen/vampirism/client/ClientConfigHelper.java index 6cfda537f3..c24b750b9e 100644 --- a/src/main/java/de/teamlapen/vampirism/client/ClientConfigHelper.java +++ b/src/main/java/de/teamlapen/vampirism/client/ClientConfigHelper.java @@ -128,15 +128,16 @@ public static List>> getActionOrder(@NotNull ResourceLocation * @return a valid order for the given faction */ @NotNull - public static List>> getActionOrder(@NotNull IPlayableFaction faction) { - return Objects.requireNonNullElseGet(ACTION_ORDER.get(faction.getID()), () -> { + public static List>> getActionOrder(@NotNull Holder> faction) { + ResourceLocation id = faction.unwrapKey().map(ResourceKey::location).orElseThrow(); + return Objects.requireNonNullElseGet(ACTION_ORDER.get(id), () -> { List>> order = getDefaultActionOrder(faction); - saveActionOrder(faction.getID(), order); + saveActionOrder(id, order); return order; }); } - public static List>> getDefaultActionOrder(IPlayableFaction faction) { + public static List>> getDefaultActionOrder(Holder> faction) { return ModRegistries.ACTIONS.holders().filter(s -> s.value().matchesFaction(faction)).collect(Collectors.toList()); } diff --git a/src/main/java/de/teamlapen/vampirism/client/core/ClientEventHandler.java b/src/main/java/de/teamlapen/vampirism/client/core/ClientEventHandler.java index 4c7cb1a036..f6e3e22bc5 100755 --- a/src/main/java/de/teamlapen/vampirism/client/core/ClientEventHandler.java +++ b/src/main/java/de/teamlapen/vampirism/client/core/ClientEventHandler.java @@ -10,6 +10,7 @@ import de.teamlapen.vampirism.client.model.blocks.BakedBloodContainerModel; import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModBlocks; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.data.ClientSkillTreeData; import de.teamlapen.vampirism.effects.VampirismPotion; import de.teamlapen.vampirism.entity.player.LevelAttributeModifier; @@ -181,7 +182,7 @@ public void onItemToolTip(@NotNull ItemTooltipEvent event) { List factionToolTips = new ArrayList<>(); factionToolTips.add(Component.empty()); factionToolTips.add(Component.translatable("text.vampirism.faction_specifics").withStyle(ChatFormatting.GRAY)); - factionToolTips.add(Component.literal(" ").append(VReference.HUNTER_FACTION.getName()).append(Component.translatable("text.vampirism.faction_only")).withStyle(Minecraft.getInstance().player != null ? Helper.isHunter(Minecraft.getInstance().player) ? ChatFormatting.DARK_GREEN : ChatFormatting.DARK_RED : ChatFormatting.GRAY)); + factionToolTips.add(Component.literal(" ").append(ModFactions.HUNTER.get().getName()).append(Component.translatable("text.vampirism.faction_only")).withStyle(Minecraft.getInstance().player != null ? Helper.isHunter(Minecraft.getInstance().player) ? ChatFormatting.DARK_GREEN : ChatFormatting.DARK_RED : ChatFormatting.GRAY)); toolTips.addAll(Math.min(event.getToolTip().size(), position), factionToolTips); }); } diff --git a/src/main/java/de/teamlapen/vampirism/client/core/ModBlocksRender.java b/src/main/java/de/teamlapen/vampirism/client/core/ModBlocksRender.java index 2c346cd58c..08a3b01ca1 100755 --- a/src/main/java/de/teamlapen/vampirism/client/core/ModBlocksRender.java +++ b/src/main/java/de/teamlapen/vampirism/client/core/ModBlocksRender.java @@ -12,6 +12,7 @@ import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.model.Material; +import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.block.entity.BlockEntity; @@ -57,8 +58,8 @@ static void registerBlockColors(RegisterColorHandlersEvent.@NotNull Block event) if (tintIndex == 255) { BlockEntity tile = (worldIn == null || pos == null) ? null : worldIn.getBlockEntity(pos); if (tile instanceof TotemBlockEntity) { - IFaction f = ((TotemBlockEntity) tile).getControllingFaction(); - if (f != null) return f.getColor(); + Holder> f = ((TotemBlockEntity) tile).getControllingFaction(); + if (f != null) return f.value().getColor(); } } return 0xFFFFFF; diff --git a/src/main/java/de/teamlapen/vampirism/client/gui/screens/EditSelectActionScreen.java b/src/main/java/de/teamlapen/vampirism/client/gui/screens/EditSelectActionScreen.java index c64065acaa..063236f72e 100644 --- a/src/main/java/de/teamlapen/vampirism/client/gui/screens/EditSelectActionScreen.java +++ b/src/main/java/de/teamlapen/vampirism/client/gui/screens/EditSelectActionScreen.java @@ -55,7 +55,7 @@ private static > ItemOrdering>> ge } private static > void saveOrdering(T player, ItemOrdering>> ordering) { - ClientConfigHelper.saveActionOrder(player.getFaction().getID(), ordering.getOrdering()); + ClientConfigHelper.saveActionOrder(player.getFaction().unwrapKey().map(ResourceKey::location).orElseThrow(), ordering.getOrdering()); } private KeyBindingList keyBindingList; diff --git a/src/main/java/de/teamlapen/vampirism/client/gui/screens/SelectActionRadialScreen.java b/src/main/java/de/teamlapen/vampirism/client/gui/screens/SelectActionRadialScreen.java index 73e0337ba5..c8a2ae4990 100644 --- a/src/main/java/de/teamlapen/vampirism/client/gui/screens/SelectActionRadialScreen.java +++ b/src/main/java/de/teamlapen/vampirism/client/gui/screens/SelectActionRadialScreen.java @@ -44,9 +44,10 @@ public static void show() { } public static > void show(KeyMapping keyMapping) { - IPlayableFaction faction = VampirismPlayerAttributes.get(Minecraft.getInstance().player).faction(); + Holder> faction = VampirismPlayerAttributes.get(Minecraft.getInstance().player).faction(); if (faction != null) { - faction.getPlayerCapability(Minecraft.getInstance().player).ifPresent(player -> { + faction.value().getPlayerCapability(Minecraft.getInstance().player).ifPresent(player -> { + //noinspection rawtypes List>> actions = ClientConfigHelper.getActionOrder(player.getFaction()).stream().filter(f -> ((IActionHandler)player.getActionHandler()).isActionUnlocked(f)).collect(Collectors.toList()); if (!actions.isEmpty()) { Minecraft.getInstance().setScreen(new SelectActionRadialScreen<>(player, actions, keyMapping)); diff --git a/src/main/java/de/teamlapen/vampirism/client/gui/screens/VampirePlayerAppearanceScreen.java b/src/main/java/de/teamlapen/vampirism/client/gui/screens/VampirePlayerAppearanceScreen.java index 8fb230f680..2255bf7075 100644 --- a/src/main/java/de/teamlapen/vampirism/client/gui/screens/VampirePlayerAppearanceScreen.java +++ b/src/main/java/de/teamlapen/vampirism/client/gui/screens/VampirePlayerAppearanceScreen.java @@ -14,6 +14,7 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Checkbox; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; import net.neoforged.neoforge.client.gui.widget.ExtendedButton; @@ -64,8 +65,8 @@ public void removed() { protected void init() { super.init(); VampirismPlayerAttributes attributes = VampirismPlayerAttributes.get(Minecraft.getInstance().player); - IFaction f = attributes.faction; - this.color = f == null ? Color.GRAY.getRGBColorComponents() : new Color(f.getColor()).getRGBColorComponents(); + Holder> f = attributes.faction; + this.color = f == null ? Color.GRAY.getRGBColorComponents() : new Color(f.value().getColor()).getRGBColorComponents(); VampirePlayerSpecialAttributes vampAtt = attributes.getVampSpecial(); this.fangType = vampAtt.fangType; this.eyeType = vampAtt.eyeType; diff --git a/src/main/java/de/teamlapen/vampirism/client/gui/screens/VampirismContainerScreen.java b/src/main/java/de/teamlapen/vampirism/client/gui/screens/VampirismContainerScreen.java index 822b0cb390..8237ed167d 100644 --- a/src/main/java/de/teamlapen/vampirism/client/gui/screens/VampirismContainerScreen.java +++ b/src/main/java/de/teamlapen/vampirism/client/gui/screens/VampirismContainerScreen.java @@ -136,7 +136,7 @@ protected void init() { if (factionPlayer.getLevel() > 0) { FactionPlayerHandler handler = FactionPlayerHandler.get(factionPlayer.asEntity()); MutableComponent component = Optional.of(handler).filter(x -> x.getLordLevel() > 0).map(FactionPlayerHandler::getLordTitle).map(x -> x.plainCopy().append(" (" + handler.getLordLevel() + ")")).orElseGet(() -> Component.translatable("text.vampirism.level").append(" " + factionPlayer.getLevel())); - this.level = component.withStyle(style -> style.withColor(factionPlayer.getFaction().getChatColor())); + this.level = component.withStyle(style -> style.withColor(factionPlayer.getFaction().value().getChatColor())); } else { this.level = Component.empty(); } diff --git a/src/main/java/de/teamlapen/vampirism/client/renderer/blockentity/TotemBESR.java b/src/main/java/de/teamlapen/vampirism/client/renderer/blockentity/TotemBESR.java index fe9e3b4818..89575edf84 100644 --- a/src/main/java/de/teamlapen/vampirism/client/renderer/blockentity/TotemBESR.java +++ b/src/main/java/de/teamlapen/vampirism/client/renderer/blockentity/TotemBESR.java @@ -9,6 +9,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.blockentity.BeaconRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.AABB; @@ -40,9 +41,9 @@ public void render(@NotNull TotemBlockEntity te, float partialTicks, @NotNull Po } BeaconRenderer.renderBeaconBeam(matrixStack, iRenderTypeBuffer, TEXTURE_BEACON_BEAM, partialTicks, textureScale, totalWorldTime, offset, HEIGHT - offset, baseColors, 0.2f, 0.25f); } else { - IFaction faction = te.getControllingFaction(); + Holder> faction = te.getControllingFaction(); if (faction != null) { - renderFactionName(faction, matrixStack, iRenderTypeBuffer, i); + renderFactionName(faction.value(), matrixStack, iRenderTypeBuffer, i); } } } diff --git a/src/main/java/de/teamlapen/vampirism/command/LevelCommand.java b/src/main/java/de/teamlapen/vampirism/command/LevelCommand.java index bdd10f5bbf..a59cfcaac8 100644 --- a/src/main/java/de/teamlapen/vampirism/command/LevelCommand.java +++ b/src/main/java/de/teamlapen/vampirism/command/LevelCommand.java @@ -11,6 +11,7 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.NotNull; @@ -57,7 +58,7 @@ private static int setLevel(@NotNull CommandContext context, @SuppressWarnings("SameReturnValue") private static int leaveFaction(@NotNull Collection players) { for (ServerPlayer player : players) { - FactionPlayerHandler.get(player).setFactionAndLevel(null, 0); + FactionPlayerHandler.get(player).setFactionAndLevel((Holder>) null, 0); } return 0; } diff --git a/src/main/java/de/teamlapen/vampirism/command/arguments/FactionArgument.java b/src/main/java/de/teamlapen/vampirism/command/arguments/FactionArgument.java index 2c4fc308dc..38de5a31c3 100644 --- a/src/main/java/de/teamlapen/vampirism/command/arguments/FactionArgument.java +++ b/src/main/java/de/teamlapen/vampirism/command/arguments/FactionArgument.java @@ -6,15 +6,21 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; +import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import de.teamlapen.vampirism.api.VampirismAPI; +import de.teamlapen.vampirism.api.VampirismRegistries; import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; +import de.teamlapen.vampirism.api.entity.player.actions.IAction; +import de.teamlapen.vampirism.core.ModRegistries; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.commands.arguments.ResourceArgument; import net.minecraft.commands.synchronization.ArgumentTypeInfo; +import net.minecraft.core.Holder; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -23,6 +29,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; @SuppressWarnings("ClassCanBeRecord") @@ -32,10 +39,6 @@ public class FactionArgument implements ArgumentType> { private static final DynamicCommandExceptionType FACTION_NOT_FOUND = new DynamicCommandExceptionType((id) -> Component.translatable("command.vampirism.argument.faction.notfound", id)); private static final DynamicCommandExceptionType FACTION_NOT_PLAYABLE = new DynamicCommandExceptionType((id) -> Component.translatable("command.vampirism.argument.faction.notplayable", id)); - public static IFaction getFaction(@NotNull CommandContext context, String id) { - return (IFaction) context.getArgument(id, IFaction.class); - } - public static IPlayableFaction getPlayableFaction(@NotNull CommandContext context, String id) { return (IPlayableFaction) context.getArgument(id, IFaction.class); } @@ -44,8 +47,12 @@ public static IPlayableFaction getPlayableFaction(@NotNull CommandContext> factions(CommandBuildContext context) { + return ResourceArgument.resource(context, VampirismRegistries.Keys.FACTION); + } + + public static Holder.Reference> getFaction(CommandContext pContext, String pArgument) throws CommandSyntaxException { + return ResourceArgument.getResource(pContext, pArgument, VampirismRegistries.Keys.FACTION); } public final boolean onlyPlayableFactions; @@ -61,7 +68,11 @@ public Collection getExamples() { @Override public @NotNull CompletableFuture listSuggestions(CommandContext context, @NotNull SuggestionsBuilder builder) { - return SharedSuggestionProvider.suggest(Arrays.stream(this.onlyPlayableFactions ? VampirismAPI.factionRegistry().getPlayableFactions() : VampirismAPI.factionRegistry().getFactions()).map(i -> i.getID().toString()), builder); + Stream>> factions = ModRegistries.FACTIONS.holders(); + if (this.onlyPlayableFactions) { + factions = factions.filter(f -> f.value() instanceof IPlayableFaction); + } + return SharedSuggestionProvider.suggest(factions.map(i -> i.key().location().toString()), builder); } @Override diff --git a/src/main/java/de/teamlapen/vampirism/command/test/GiveAccessoriesCommand.java b/src/main/java/de/teamlapen/vampirism/command/test/GiveAccessoriesCommand.java index 958d189a1b..7e36e149af 100644 --- a/src/main/java/de/teamlapen/vampirism/command/test/GiveAccessoriesCommand.java +++ b/src/main/java/de/teamlapen/vampirism/command/test/GiveAccessoriesCommand.java @@ -14,6 +14,7 @@ import de.teamlapen.vampirism.items.RefinementItem; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.item.Item; @@ -39,9 +40,9 @@ public class GiveAccessoriesCommand extends BasicCommand { @SuppressWarnings("SameReturnValue") private static int give(@NotNull CommandContext context, @NotNull ServerPlayer asPlayer, int number, @NotNull IRefinementSet set) { - IFaction faction = set.getFaction(); - if (faction instanceof PlayableFaction) { // should always be true - Z i = ((PlayableFaction) faction).getRefinementItem(IRefinementItem.AccessorySlotType.values()[number - 1]); + Holder> faction = set.getFaction(); + if (faction.value() instanceof PlayableFaction playable) { // should always be true + Z i = playable.getRefinementItem(IRefinementItem.AccessorySlotType.values()[number - 1]); ItemStack s = new ItemStack(i); if (i.applyRefinementSet(s, set)) { asPlayer.addItem(s); @@ -61,11 +62,10 @@ private static int help(@NotNull CommandContext context) { @SuppressWarnings("SameReturnValue") private static > int random(@NotNull CommandContext context, @NotNull ServerPlayer entity, int amount) { - IFaction faction = VampirismAPI.factionRegistry().getFaction(entity); - if (faction instanceof PlayableFaction) { + Holder> faction = VampirismAPI.factionRegistry().getFactionHolder(entity); + if (faction.value() instanceof PlayableFaction playable) { for (int i = 0; i < amount; ++i) { - //noinspection unchecked - ItemStack stack = RefinementItem.getRandomRefinementItem(((PlayableFaction) faction)); + ItemStack stack = RefinementItem.getRandomRefinementItem(playable); if (!stack.isEmpty()) { entity.addItem(stack); } else { diff --git a/src/main/java/de/teamlapen/vampirism/command/test/GiveBannerCommand.java b/src/main/java/de/teamlapen/vampirism/command/test/GiveBannerCommand.java index 4677487b67..ed19956ff0 100644 --- a/src/main/java/de/teamlapen/vampirism/command/test/GiveBannerCommand.java +++ b/src/main/java/de/teamlapen/vampirism/command/test/GiveBannerCommand.java @@ -4,24 +4,26 @@ import de.teamlapen.lib.lib.util.BasicCommand; import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.command.arguments.FactionArgument; +import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; +import net.minecraft.core.Holder; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.NotNull; public class GiveBannerCommand extends BasicCommand { - public static ArgumentBuilder register() { + public static ArgumentBuilder register(CommandBuildContext buildContext) { return Commands.literal("banner") .requires(context -> context.hasPermission(PERMISSION_LEVEL_CHEAT)) - .then(Commands.argument("faction", FactionArgument.factions()) + .then(Commands.argument("faction", FactionArgument.factions(buildContext)) .executes(context -> giveBannerItem(FactionArgument.getFaction(context, "faction"), context.getSource().getPlayerOrException())) ); } @SuppressWarnings("SameReturnValue") - private static int giveBannerItem(@NotNull IFaction faction, @NotNull ServerPlayer player) { - player.addItem(faction.getVillageData().getBanner(player.registryAccess())); + private static int giveBannerItem(@NotNull Holder> faction, @NotNull ServerPlayer player) { + player.addItem(faction.value().getVillageData().getBanner(player.registryAccess())); return 0; } } diff --git a/src/main/java/de/teamlapen/vampirism/command/test/SkillCommand.java b/src/main/java/de/teamlapen/vampirism/command/test/SkillCommand.java index 24888df9f1..90c22feab0 100644 --- a/src/main/java/de/teamlapen/vampirism/command/test/SkillCommand.java +++ b/src/main/java/de/teamlapen/vampirism/command/test/SkillCommand.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import de.teamlapen.lib.lib.util.BasicCommand; import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.skills.ISkill; import de.teamlapen.vampirism.api.entity.player.skills.ISkillHandler; @@ -59,7 +60,7 @@ private static > int enableAll(@NotNull CommandSourc T factionPlayer = FactionPlayerHandler.getCurrentFactionPlayer(asPlayer).orElseThrow(NO_FACTION::create); ISkillHandler skillHandler = factionPlayer.getSkillHandler(); ModRegistries.SKILLS.holders().forEach(holder -> { - if (!holder.value().getFaction().map(f -> f != factionPlayer.getFaction()).orElse(false)) { + if (IFaction.is(factionPlayer.getFaction(), holder.value().factions())) { //noinspection unchecked skillHandler.enableSkill((Holder>) (Object) holder); } diff --git a/src/main/java/de/teamlapen/vampirism/command/test/VillageCommand.java b/src/main/java/de/teamlapen/vampirism/command/test/VillageCommand.java index d9fd9bd4f1..805e781b9b 100644 --- a/src/main/java/de/teamlapen/vampirism/command/test/VillageCommand.java +++ b/src/main/java/de/teamlapen/vampirism/command/test/VillageCommand.java @@ -6,20 +6,22 @@ import de.teamlapen.vampirism.blockentity.TotemBlockEntity; import de.teamlapen.vampirism.command.arguments.FactionArgument; import de.teamlapen.vampirism.util.TotemHelper; +import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; public class VillageCommand extends BasicCommand { - public static ArgumentBuilder register() { + public static ArgumentBuilder register(CommandBuildContext buildContext) { return Commands.literal("village") .requires(context -> context.hasPermission(PERMISSION_LEVEL_CHEAT)) .then(Commands.literal("capture") - .then(Commands.argument("faction", FactionArgument.factions()) + .then(Commands.argument("faction", FactionArgument.factions(buildContext)) .executes(context -> capture(context.getSource(), context.getSource().getPlayerOrException(), FactionArgument.getFaction(context, "faction"))))) .then(Commands.literal("abort") .executes(context -> abort(context.getSource()))); @@ -27,7 +29,7 @@ public class VillageCommand extends BasicCommand { } @SuppressWarnings("SameReturnValue") - private static int capture(@NotNull CommandSourceStack source, @NotNull ServerPlayer player, IFaction faction) { + private static int capture(@NotNull CommandSourceStack source, @NotNull ServerPlayer player, Holder> faction) { source.sendSuccess(() -> TotemHelper.forceFactionCommand(faction, player), true); return 0; } diff --git a/src/main/java/de/teamlapen/vampirism/core/ModBlocks.java b/src/main/java/de/teamlapen/vampirism/core/ModBlocks.java index 2646048e45..afc79da9c1 100755 --- a/src/main/java/de/teamlapen/vampirism/core/ModBlocks.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModBlocks.java @@ -68,12 +68,12 @@ public class ModBlocks { public static final DeferredBlock TENT = BLOCKS.register("tent", TentBlock::new); public static final DeferredBlock TENT_MAIN = BLOCKS.register("tent_main", TentMainBlock::new); public static final DeferredBlock TOTEM_BASE = registerWithItem("totem_base", TotemBaseBlock::new); - public static final DeferredBlock TOTEM_TOP = registerWithItem("totem_top", () -> new TotemTopBlock(false, new ResourceLocation("none"))); - public static final DeferredBlock TOTEM_TOP_VAMPIRISM_VAMPIRE = BLOCKS.register("totem_top_vampirism_vampire", () -> new TotemTopBlock(false, VReference.VAMPIRE_FACTION_ID)); - public static final DeferredBlock TOTEM_TOP_VAMPIRISM_HUNTER = BLOCKS.register("totem_top_vampirism_hunter", () -> new TotemTopBlock(false, VReference.HUNTER_FACTION_ID)); - public static final DeferredBlock TOTEM_TOP_CRAFTED = registerWithItem("totem_top_crafted", () -> new TotemTopBlock(true, new ResourceLocation("none"))); - public static final DeferredBlock TOTEM_TOP_VAMPIRISM_VAMPIRE_CRAFTED = BLOCKS.register("totem_top_vampirism_vampire_crafted", () -> new TotemTopBlock(true, VReference.VAMPIRE_FACTION_ID)); - public static final DeferredBlock TOTEM_TOP_VAMPIRISM_HUNTER_CRAFTED = BLOCKS.register("totem_top_vampirism_hunter_crafted", () -> new TotemTopBlock(true, VReference.HUNTER_FACTION_ID)); + public static final DeferredBlock TOTEM_TOP = registerWithItem("totem_top", () -> new TotemTopBlock(false, null)); + public static final DeferredBlock TOTEM_TOP_VAMPIRISM_VAMPIRE = BLOCKS.register("totem_top_vampirism_vampire", () -> new TotemTopBlock(false, ModFactions.VAMPIRE)); + public static final DeferredBlock TOTEM_TOP_VAMPIRISM_HUNTER = BLOCKS.register("totem_top_vampirism_hunter", () -> new TotemTopBlock(false, ModFactions.HUNTER)); + public static final DeferredBlock TOTEM_TOP_CRAFTED = registerWithItem("totem_top_crafted", () -> new TotemTopBlock(true, null)); + public static final DeferredBlock TOTEM_TOP_VAMPIRISM_VAMPIRE_CRAFTED = BLOCKS.register("totem_top_vampirism_vampire_crafted", () -> new TotemTopBlock(true, ModFactions.VAMPIRE)); + public static final DeferredBlock TOTEM_TOP_VAMPIRISM_HUNTER_CRAFTED = BLOCKS.register("totem_top_vampirism_hunter_crafted", () -> new TotemTopBlock(true, ModFactions.HUNTER)); public static final DeferredBlock VAMPIRE_ORCHID = registerWithItem("vampire_orchid", () -> new VampirismFlowerBlock(VampirismFlowerBlock.TYPE.ORCHID)); public static final DeferredBlock POTTED_VAMPIRE_ORCHID = BLOCKS.register("potted_vampire_orchid", () -> potted(new FlowerPotBlock(() -> (FlowerPotBlock) Blocks.FLOWER_POT, VAMPIRE_ORCHID, Block.Properties.of().noCollission().isViewBlocking(UtilLib::never).pushReaction(PushReaction.DESTROY).instabreak()), VAMPIRE_ORCHID.getId())); public static final DeferredBlock WEAPON_TABLE = registerWithItem("weapon_table", WeaponTableBlock::new); diff --git a/src/main/java/de/teamlapen/vampirism/core/ModCommands.java b/src/main/java/de/teamlapen/vampirism/core/ModCommands.java index 2e597c10f9..762a8e5859 100644 --- a/src/main/java/de/teamlapen/vampirism/core/ModCommands.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModCommands.java @@ -84,13 +84,13 @@ static void registerCommands(@NotNull RegisterCommandsEvent event) { .then(VampireSwordCommand.register()) .then(SpawnTestAnimalCommand.register()) .then(HealCommand.register()) - .then(VillageCommand.register()) + .then(VillageCommand.register(buildContext)) .then(MinionCommand.register()) .then(TaskCommand.register()) .then(ForcePlayerSyncCommand.register()) .then(GiveAccessoriesCommand.register()) .then(SummonDummy.register()) - .then(GiveBannerCommand.register()) + .then(GiveBannerCommand.register(buildContext)) ); } } diff --git a/src/main/java/de/teamlapen/vampirism/core/ModEffects.java b/src/main/java/de/teamlapen/vampirism/core/ModEffects.java index 86a09e32b4..789f02633a 100644 --- a/src/main/java/de/teamlapen/vampirism/core/ModEffects.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModEffects.java @@ -30,18 +30,8 @@ public class ModEffects { public static final DeferredHolder NEONATAL = EFFECTS.register("neonatal", () -> new VampirismEffect(MobEffectCategory.NEUTRAL, 0xFFBBBB).addAttributeModifier(Attributes.ATTACK_DAMAGE, "377d132d-d091-43b2-8a8f-b940f9bc894c", -0.15, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL).addAttributeModifier(Attributes.MOVEMENT_SPEED, "ad6d7def-46e2-485f-afba-39252767f114", -0.15, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL)); public static final DeferredHolder OBLIVION = EFFECTS.register("oblivion", OblivionEffect::new); public static final DeferredHolder ARMOR_REGENERATION = EFFECTS.register("armor_regeneration", () -> new VampirismEffect(MobEffectCategory.NEUTRAL, 0xD17642)); - public static final DeferredHolder BAD_OMEN_HUNTER = EFFECTS.register("bad_omen_hunter", () -> new BadOmenEffect() { - @Override - public IFaction getFaction() { - return VReference.HUNTER_FACTION; - } - }); - public static final DeferredHolder BAD_OMEN_VAMPIRE = EFFECTS.register("bad_omen_vampire", () -> new BadOmenEffect() { - @Override - public IFaction getFaction() { - return VReference.VAMPIRE_FACTION; - } - }); + public static final DeferredHolder BAD_OMEN_HUNTER = EFFECTS.register("bad_omen_hunter", () -> new BadOmenEffect(ModFactions.HUNTER)); + public static final DeferredHolder BAD_OMEN_VAMPIRE = EFFECTS.register("bad_omen_vampire", () -> new BadOmenEffect(ModFactions.VAMPIRE)); public static final DeferredHolder LORD_SPEED = EFFECTS.register("lord_speed", () -> new VampirismEffect(MobEffectCategory.BENEFICIAL, 0xffffff).addAttributeModifier(Attributes.MOVEMENT_SPEED, "efe607d8-db8a-4156-b9d0-6a0640593057", 0.07F, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL)); public static final DeferredHolder LORD_ATTACK_SPEED = EFFECTS.register("lord_attack_speed", () -> new VampirismEffect(MobEffectCategory.BENEFICIAL, 0xffffff).addAttributeModifier(Attributes.ATTACK_SPEED, "a2ca9534-3baf-404f-b159-bc835bf963e6", 0.05F, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL)); public static final DeferredHolder NO_BLOOD = EFFECTS.register("no_blood", () -> new VampirismEffect(MobEffectCategory.HARMFUL, 0x191919) diff --git a/src/main/java/de/teamlapen/vampirism/core/ModEntitySelectors.java b/src/main/java/de/teamlapen/vampirism/core/ModEntitySelectors.java index 01d90781c0..69bd54e969 100644 --- a/src/main/java/de/teamlapen/vampirism/core/ModEntitySelectors.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModEntitySelectors.java @@ -9,10 +9,13 @@ import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.arguments.selector.options.EntitySelectorOptions; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; +import java.util.List; + /** * Creates and adds custom entity selectors based on Vampirism's properties @@ -31,9 +34,9 @@ public static void registerSelectors() { EntitySelectorOptions.register(FACTION, (parser) -> { boolean invert = parser.shouldInvertValue(); ResourceLocation factionID = new ResourceLocation(parser.getReader().readString()); - IFaction[] factions = VampirismAPI.factionRegistry().getFactions(); - for (final IFaction f : factions) { - if (f.getID().equals(factionID)) { + List>> factions = ModRegistries.FACTIONS.holders().toList(); + for (final Holder.Reference> f : factions) { + if (f.is(factionID)) { parser.addPredicate(input -> { if (input instanceof IFactionEntity) { boolean flag1 = f.equals(((IFactionEntity) input).getFaction()); diff --git a/src/main/java/de/teamlapen/vampirism/core/ModFactions.java b/src/main/java/de/teamlapen/vampirism/core/ModFactions.java new file mode 100644 index 0000000000..2eb2d689df --- /dev/null +++ b/src/main/java/de/teamlapen/vampirism/core/ModFactions.java @@ -0,0 +1,30 @@ +package de.teamlapen.vampirism.core; + +import de.teamlapen.vampirism.REFERENCE; +import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.VampirismFactions; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; +import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; +import de.teamlapen.vampirism.api.entity.player.hunter.IHunterPlayer; +import de.teamlapen.vampirism.api.entity.player.vampire.IVampirePlayer; +import de.teamlapen.vampirism.api.registries.DeferredFaction; +import de.teamlapen.vampirism.api.registries.DeferredFactionRegister; +import de.teamlapen.vampirism.entity.factions.PlayableFaction; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; + +@SuppressWarnings("deprecation") +public class ModFactions { + + public static final DeferredFactionRegister FACTIONS = DeferredFactionRegister.create(REFERENCE.MODID); + + public static final DeferredFaction> VAMPIRE = FACTIONS.registerFaction(VampirismFactions.Keys.VAMPIRE.getPath(), () -> VReference.VAMPIRE_FACTION); + public static final DeferredFaction> HUNTER = FACTIONS.registerFaction(VampirismFactions.Keys.HUNTER.getPath(), () -> VReference.HUNTER_FACTION); + + static void register(IEventBus bus) { + FACTIONS.register(bus); + } + +} diff --git a/src/main/java/de/teamlapen/vampirism/core/ModItems.java b/src/main/java/de/teamlapen/vampirism/core/ModItems.java index d640acf11b..8ef6c0cbcc 100755 --- a/src/main/java/de/teamlapen/vampirism/core/ModItems.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModItems.java @@ -207,14 +207,14 @@ public void appendHoverText(@NotNull ItemStack stack, @Nullable TooltipContext c public static final DeferredItem UMBRELLA = register("umbrella", UmbrellaItem::new); public static final DeferredItem HUNTER_MINION_EQUIPMENT = register("hunter_minion_equipment", () -> new Item(props())); - public static final DeferredItem HUNTER_MINION_UPGRADE_SIMPLE = register("hunter_minion_upgrade_simple", () -> new MinionUpgradeItem(1, 2, VReference.HUNTER_FACTION)); - public static final DeferredItem HUNTER_MINION_UPGRADE_ENHANCED = register("hunter_minion_upgrade_enhanced", () -> new MinionUpgradeItem(3, 4, VReference.HUNTER_FACTION)); - public static final DeferredItem HUNTER_MINION_UPGRADE_SPECIAL = register("hunter_minion_upgrade_special", () -> new MinionUpgradeItem(5, 6, VReference.HUNTER_FACTION)); + public static final DeferredItem HUNTER_MINION_UPGRADE_SIMPLE = register("hunter_minion_upgrade_simple", () -> new MinionUpgradeItem(1, 2, ModFactions.HUNTER)); + public static final DeferredItem HUNTER_MINION_UPGRADE_ENHANCED = register("hunter_minion_upgrade_enhanced", () -> new MinionUpgradeItem(3, 4, ModFactions.HUNTER)); + public static final DeferredItem HUNTER_MINION_UPGRADE_SPECIAL = register("hunter_minion_upgrade_special", () -> new MinionUpgradeItem(5, 6, ModFactions.HUNTER)); public static final DeferredItem FEEDING_ADAPTER = register("feeding_adapter", FeedingAdapterItem::new); public static final DeferredItem VAMPIRE_MINION_BINDING = register("vampire_minion_binding", () -> new Item(props())); - public static final DeferredItem VAMPIRE_MINION_UPGRADE_SIMPLE = register("vampire_minion_upgrade_simple", () -> new MinionUpgradeItem(1, 2, VReference.VAMPIRE_FACTION)); - public static final DeferredItem VAMPIRE_MINION_UPGRADE_ENHANCED = register("vampire_minion_upgrade_enhanced", () -> new MinionUpgradeItem(3, 4, VReference.VAMPIRE_FACTION)); - public static final DeferredItem VAMPIRE_MINION_UPGRADE_SPECIAL = register("vampire_minion_upgrade_special", () -> new MinionUpgradeItem(5, 6, VReference.VAMPIRE_FACTION)); + public static final DeferredItem VAMPIRE_MINION_UPGRADE_SIMPLE = register("vampire_minion_upgrade_simple", () -> new MinionUpgradeItem(1, 2, ModFactions.VAMPIRE)); + public static final DeferredItem VAMPIRE_MINION_UPGRADE_ENHANCED = register("vampire_minion_upgrade_enhanced", () -> new MinionUpgradeItem(3, 4, ModFactions.VAMPIRE)); + public static final DeferredItem VAMPIRE_MINION_UPGRADE_SPECIAL = register("vampire_minion_upgrade_special", () -> new MinionUpgradeItem(5, 6, ModFactions.VAMPIRE)); public static final DeferredItem OBLIVION_POTION = register("oblivion_potion", () -> new OblivionItem(props())); diff --git a/src/main/java/de/teamlapen/vampirism/core/ModRegistries.java b/src/main/java/de/teamlapen/vampirism/core/ModRegistries.java index aee88a5822..a147d03b75 100644 --- a/src/main/java/de/teamlapen/vampirism/core/ModRegistries.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModRegistries.java @@ -3,6 +3,7 @@ import com.mojang.serialization.MapCodec; import de.teamlapen.vampirism.api.VampirismRegistries; import de.teamlapen.vampirism.api.entity.convertible.Converter; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.minion.IMinionTask; import de.teamlapen.vampirism.api.entity.player.actions.IAction; import de.teamlapen.vampirism.api.entity.player.refinement.IRefinement; @@ -37,6 +38,7 @@ public class ModRegistries { public static final Registry>> TASK_REQUIREMENTS = new RegistryBuilder<>(VampirismRegistries.Keys.TASK_REQUIREMENT).create(); public static final Registry> TASK_REWARD_INSTANCES= new RegistryBuilder<>(VampirismRegistries.Keys.TASK_REWARD_INSTANCE).create(); public static final Registry> ENTITY_CONVERTER = new RegistryBuilder<>(VampirismRegistries.Keys.ENTITY_CONVERTER).create(); + public static final Registry> FACTIONS = new RegistryBuilder<>(VampirismRegistries.Keys.FACTION).sync(true).create(); public static final RegistrySetBuilder DATA_BUILDER = new RegistrySetBuilder() .add(Registries.BIOME, ModBiomes::createBiomes) @@ -65,6 +67,7 @@ static void registerRegistries(NewRegistryEvent event) { event.register(TASK_REQUIREMENTS); event.register(TASK_REWARD_INSTANCES); event.register(ENTITY_CONVERTER); + event.register(FACTIONS); } static void registerDatapackRegistries(DataPackRegistryEvent.NewRegistry event) { diff --git a/src/main/java/de/teamlapen/vampirism/core/ModTasks.java b/src/main/java/de/teamlapen/vampirism/core/ModTasks.java index 33d07dfb8d..d3aac09d17 100644 --- a/src/main/java/de/teamlapen/vampirism/core/ModTasks.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModTasks.java @@ -127,12 +127,12 @@ private static ResourceKey key(String path) { @SuppressWarnings("deprecation") static void createTasks(BootstrapContext context) { context.register(FEEDING_ADAPTER, TaskBuilder.builder(FEEDING_ADAPTER).defaultTitle().unlockedBy(new LvlUnlocker(4)).addRequirement(ModEntityTags.ADVANCED_HUNTER, 10).addRequirement(new ItemStack(Items.GOLD_INGOT, 5)).setReward(new ItemStack(ModItems.FEEDING_ADAPTER.get())).build()); - context.register(VAMPIRE_LORD_1, TaskBuilder.builder(VAMPIRE_LORD_1).defaultTitle().unlockedBy(new LvlUnlocker(VReference.VAMPIRE_FACTION.getHighestReachableLevel())).addRequirement(ModStats.INFECTED_CREATURES.get(), 25).addRequirement(new ItemStack(ModItems.PURE_BLOOD_4.get(), 5)).addRequirement(new ItemStack(Items.GOLD_INGOT, 32)).addRequirement(ModStats.WIN_VILLAGE_CAPTURE.get(), 3).setReward(new LordLevelReward(1, Component.translatable("task.vampirism.vampire_lord1.reward"))).build()); + context.register(VAMPIRE_LORD_1, TaskBuilder.builder(VAMPIRE_LORD_1).defaultTitle().unlockedBy(new LvlUnlocker(ModFactions.VAMPIRE.value().getHighestReachableLevel())).addRequirement(ModStats.INFECTED_CREATURES.get(), 25).addRequirement(new ItemStack(ModItems.PURE_BLOOD_4.get(), 5)).addRequirement(new ItemStack(Items.GOLD_INGOT, 32)).addRequirement(ModStats.WIN_VILLAGE_CAPTURE.get(), 3).setReward(new LordLevelReward(1, Component.translatable("task.vampirism.vampire_lord1.reward"))).build()); context.register(VAMPIRE_LORD_2, TaskBuilder.builder(VAMPIRE_LORD_2).defaultTitle().unlockedBy(new LordLvlUnlocker(1, true)).addRequirement(ModEntityTags.HUNTER, 30).addRequirement(new ItemStack(ModItems.PURE_BLOOD_4.get(), 5)).addRequirement(new ItemStack(Items.GOLD_INGOT, 48)).setReward(new LordLevelReward(2)).build()); context.register(VAMPIRE_LORD_3, TaskBuilder.builder(VAMPIRE_LORD_3).defaultTitle().unlockedBy(new LordLvlUnlocker(2, true)).addRequirement(ModEntityTags.HUNTER, 30).addRequirement(new ItemStack(ModItems.PURE_BLOOD_4.get(), 5)).addRequirement(new ItemStack(Items.GOLD_INGOT, 48)).setReward(new LordLevelReward(3)).build()); context.register(VAMPIRE_LORD_4, TaskBuilder.builder(VAMPIRE_LORD_4).defaultTitle().unlockedBy(new LordLvlUnlocker(3, true)).addRequirement(ModEntityTags.ADVANCED_HUNTER, 5).addRequirement(new ItemStack(ModItems.PURE_BLOOD_4.get(), 10)).addRequirement(new ItemStack(Items.GOLD_INGOT, 64)).setReward(new LordLevelReward(4)).build()); context.register(VAMPIRE_LORD_5, TaskBuilder.builder(VAMPIRE_LORD_5).defaultTitle().unlockedBy(new LordLvlUnlocker(4, true)).addRequirement(ModStats.INFECTED_CREATURES.get(), 50).addRequirement(new ItemStack(ModItems.PURE_BLOOD_4.get(), 20)).addRequirement(new ItemStack(Items.GOLD_INGOT, 64)).addRequirement(ModStats.CAPTURE_VILLAGE.get(), 6).setReward(new LordLevelReward(5)).build()); - context.register(HUNTER_LORD_1, TaskBuilder.builder(HUNTER_LORD_1).defaultTitle().unlockedBy(new LvlUnlocker(VReference.HUNTER_FACTION.getHighestReachableLevel())).addRequirement(ModEntityTags.VAMPIRE, 50).addRequirement(new ItemStack(Items.GOLD_INGOT, 32)).addRequirement(ModStats.WIN_VILLAGE_CAPTURE.get(), 3).setReward(new LordLevelReward(1, Component.translatable("task.vampirism.hunter_lord1.reward"))).build()); + context.register(HUNTER_LORD_1, TaskBuilder.builder(HUNTER_LORD_1).defaultTitle().unlockedBy(new LvlUnlocker(ModFactions.HUNTER.value().getHighestReachableLevel())).addRequirement(ModEntityTags.VAMPIRE, 50).addRequirement(new ItemStack(Items.GOLD_INGOT, 32)).addRequirement(ModStats.WIN_VILLAGE_CAPTURE.get(), 3).setReward(new LordLevelReward(1, Component.translatable("task.vampirism.hunter_lord1.reward"))).build()); context.register(HUNTER_LORD_2, TaskBuilder.builder(HUNTER_LORD_2).defaultTitle().unlockedBy(new LordLvlUnlocker(1, true)).addRequirement(ModEntityTags.VAMPIRE, 50).addRequirement(new ItemStack(Items.GOLD_INGOT, 32)).setReward(new LordLevelReward(2)).build()); context.register(HUNTER_LORD_3, TaskBuilder.builder(HUNTER_LORD_3).defaultTitle().unlockedBy(new LordLvlUnlocker(2, true)).addRequirement(ModEntityTags.VAMPIRE, 50).addRequirement(new ItemStack(Items.GOLD_INGOT, 32)).setReward(new LordLevelReward(3)).build()); context.register(HUNTER_LORD_4, TaskBuilder.builder(HUNTER_LORD_4).defaultTitle().unlockedBy(new LordLvlUnlocker(3, true)).addRequirement(ModEntityTags.VAMPIRE, 75).addRequirement(new ItemStack(Items.GOLD_INGOT, 64)).setReward(new LordLevelReward(4)).build()); @@ -168,9 +168,9 @@ static void createTasks(BootstrapContext context) { context.register(OBLIVION_POTION_PURE_BLOOD_3, TaskBuilder.builder(OBLIVION_POTION_PURE_BLOOD_3).defaultTitle().unlockedBy(new LvlUnlocker(7, 9)).addRequirement(ItemDataUtils.setPotion(new ItemStack(Items.POTION), Potions.POISON)).addRequirement(new ItemStack(ModItems.PURE_BLOOD_2.get())).setReward(new ItemStack(ModItems.OBLIVION_POTION.get())).build()); context.register(OBLIVION_POTION_PURE_BLOOD_4, TaskBuilder.builder(OBLIVION_POTION_PURE_BLOOD_4).defaultTitle().unlockedBy(new LvlUnlocker(10, 12)).addRequirement(ItemDataUtils.setPotion(new ItemStack(Items.POTION), Potions.POISON)).addRequirement(new ItemStack(ModItems.PURE_BLOOD_3.get())).setReward(new ItemStack(ModItems.OBLIVION_POTION.get())).build()); context.register(OBLIVION_POTION_PURE_BLOOD_5, TaskBuilder.builder(OBLIVION_POTION_PURE_BLOOD_5).defaultTitle().unlockedBy(new LvlUnlocker(13, 14)).addRequirement(ItemDataUtils.setPotion(new ItemStack(Items.POTION), Potions.POISON)).addRequirement(new ItemStack(ModItems.PURE_BLOOD_4.get())).setReward(new ItemStack(ModItems.OBLIVION_POTION.get())).build()); - context.register(RANDOM_REFINEMENT_1, TaskBuilder.builder(RANDOM_REFINEMENT_1).defaultTitle().addRequirement(ModEntityTags.ADVANCED_HUNTER, 10).addRequirement(new ItemStack(Items.GOLD_INGOT, 2)).setReward(new RefinementItemReward(VReference.VAMPIRE_FACTION)).build()); - context.register(RANDOM_REFINEMENT_2, TaskBuilder.builder(RANDOM_REFINEMENT_2).defaultTitle().addRequirement(ModEntities.VAMPIRE_BARON.get(), 3).addRequirement(new ItemStack(Items.GOLD_INGOT, 2)).setReward(new RefinementItemReward(VReference.VAMPIRE_FACTION)).build()); - context.register(RANDOM_REFINEMENT_3, TaskBuilder.builder(RANDOM_REFINEMENT_3).defaultTitle().addRequirement(Stats.TRADED_WITH_VILLAGER, 15).addRequirement(new ItemStack(Items.GOLD_INGOT, 2)).setReward(new RefinementItemReward(VReference.VAMPIRE_FACTION)).build()); - context.register(RANDOM_RARE_REFINEMENT, TaskBuilder.builder(RANDOM_RARE_REFINEMENT).defaultTitle().addRequirement(Stats.RAID_WIN, 1).setReward(new RefinementItemReward(VReference.VAMPIRE_FACTION, IRefinementSet.Rarity.RARE)).build()); + context.register(RANDOM_REFINEMENT_1, TaskBuilder.builder(RANDOM_REFINEMENT_1).defaultTitle().addRequirement(ModEntityTags.ADVANCED_HUNTER, 10).addRequirement(new ItemStack(Items.GOLD_INGOT, 2)).setReward(new RefinementItemReward(ModFactions.VAMPIRE)).build()); + context.register(RANDOM_REFINEMENT_2, TaskBuilder.builder(RANDOM_REFINEMENT_2).defaultTitle().addRequirement(ModEntities.VAMPIRE_BARON.get(), 3).addRequirement(new ItemStack(Items.GOLD_INGOT, 2)).setReward(new RefinementItemReward(ModFactions.VAMPIRE)).build()); + context.register(RANDOM_REFINEMENT_3, TaskBuilder.builder(RANDOM_REFINEMENT_3).defaultTitle().addRequirement(Stats.TRADED_WITH_VILLAGER, 15).addRequirement(new ItemStack(Items.GOLD_INGOT, 2)).setReward(new RefinementItemReward(ModFactions.VAMPIRE)).build()); + context.register(RANDOM_RARE_REFINEMENT, TaskBuilder.builder(RANDOM_RARE_REFINEMENT).defaultTitle().addRequirement(Stats.RAID_WIN, 1).setReward(new RefinementItemReward(ModFactions.VAMPIRE, IRefinementSet.Rarity.RARE)).build()); } } diff --git a/src/main/java/de/teamlapen/vampirism/core/RegistryManager.java b/src/main/java/de/teamlapen/vampirism/core/RegistryManager.java index 88597456fd..7d480437fa 100644 --- a/src/main/java/de/teamlapen/vampirism/core/RegistryManager.java +++ b/src/main/java/de/teamlapen/vampirism/core/RegistryManager.java @@ -68,6 +68,7 @@ public void setupRegistries() { ModSkills.init(); ModDataComponents.register(eventBus); ModArmorMaterials.register(eventBus); + ModFactions.register(eventBus); } @SubscribeEvent diff --git a/src/main/java/de/teamlapen/vampirism/core/tags/ModFactionTags.java b/src/main/java/de/teamlapen/vampirism/core/tags/ModFactionTags.java new file mode 100644 index 0000000000..1fc9f4c264 --- /dev/null +++ b/src/main/java/de/teamlapen/vampirism/core/tags/ModFactionTags.java @@ -0,0 +1,22 @@ +package de.teamlapen.vampirism.core.tags; + +import de.teamlapen.vampirism.REFERENCE; +import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.VampirismTags; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import org.jetbrains.annotations.NotNull; + +public class ModFactionTags { + + public static final TagKey> HOSTILE_TOWARDS_NEUTRAL = tag("hostile_towards_neutral"); + public static final TagKey> ALL_FACTIONS = VampirismTags.Factions.ALL_FACTIONS; + public static final TagKey> IS_HUNTER = VampirismTags.Factions.IS_HUNTER; + public static final TagKey> IS_VAMPIRE = VampirismTags.Factions.IS_VAMPIRE; + public static final TagKey> HAS_LORD_SKILLS = tag("has_lord_skills"); + + private static @NotNull TagKey> tag(@NotNull String name) { + return TagKey.create(VampirismRegistries.Keys.FACTION, new ResourceLocation(REFERENCE.MODID, name)); + } +} diff --git a/src/main/java/de/teamlapen/vampirism/data/provider/AdvancementProvider.java b/src/main/java/de/teamlapen/vampirism/data/provider/AdvancementProvider.java index 2de1c4c085..a5271fe2f1 100644 --- a/src/main/java/de/teamlapen/vampirism/data/provider/AdvancementProvider.java +++ b/src/main/java/de/teamlapen/vampirism/data/provider/AdvancementProvider.java @@ -62,25 +62,25 @@ public void generate(@NotNull AdvancementHolder root, HolderLookup.@NotNull Prov AdvancementHolder become_hunter = Advancement.Builder.advancement() .display(ModItems.ITEM_GARLIC.get(), Component.translatable("advancement.vampirism.become_hunter"), Component.translatable("advancement.vampirism.become_hunter.desc"), null, AdvancementType.TASK, true, false, false) .parent(root) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.HUNTER_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.HUNTER, 1)) .save(consumer, REFERENCE.MODID + ":hunter/become_hunter"); AdvancementHolder stake = Advancement.Builder.advancement() .display(ModItems.STAKE.get(), Component.translatable("advancement.vampirism.stake"), Component.translatable("advancement.vampirism.stake.desc"), null, AdvancementType.CHALLENGE, true, true, true) .parent(become_hunter) .addCriterion("flower", HunterActionCriterionTrigger.TriggerInstance.of(HunterActionCriterionTrigger.Action.STAKE)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.HUNTER_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.HUNTER, 1)) .rewards(AdvancementRewards.Builder.experience(100)) .save(consumer, REFERENCE.MODID + ":hunter/stake"); AdvancementHolder betrayal = Advancement.Builder.advancement() .display(ModItems.HUMAN_HEART.get(), Component.translatable("advancement.vampirism.betrayal"), Component.translatable("advancement.vampirism.betrayal.desc"), null, AdvancementType.TASK, true, true, true) .parent(become_hunter) .addCriterion("kill", KilledTrigger.TriggerInstance.playerKilledEntity(EntityPredicate.Builder.entity().of(ModEntityTags.HUNTER))) - .addCriterion("faction", FactionCriterionTrigger.TriggerInstance.level(VReference.HUNTER_FACTION, 1)) + .addCriterion("faction", FactionCriterionTrigger.TriggerInstance.level(ModFactions.HUNTER, 1)) .save(consumer, REFERENCE.MODID + ":hunter/betrayal"); AdvancementHolder max_level = Advancement.Builder.advancement() .display(ModItems.ITEM_GARLIC.get(), Component.translatable("advancement.vampirism.max_level_hunter"), Component.translatable("advancement.vampirism.max_level_hunter.desc"), null, AdvancementType.GOAL, true, true, true) .parent(stake) - .addCriterion("level", FactionCriterionTrigger.TriggerInstance.level(VReference.HUNTER_FACTION, 14)) + .addCriterion("level", FactionCriterionTrigger.TriggerInstance.level(ModFactions.HUNTER, 14)) .rewards(AdvancementRewards.Builder.experience(100)) .save(consumer, REFERENCE.MODID + ":hunter/max_level"); AdvancementHolder technology = Advancement.Builder.advancement() @@ -88,32 +88,32 @@ public void generate(@NotNull AdvancementHolder root, HolderLookup.@NotNull Prov .parent(become_hunter) .addCriterion("basic", InventoryChangeTrigger.TriggerInstance.hasItems(ModItems.BASIC_TECH_CROSSBOW)) .addCriterion("advanced", InventoryChangeTrigger.TriggerInstance.hasItems(ModItems.ENHANCED_TECH_CROSSBOW)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.HUNTER_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.HUNTER, 1)) .requirements(AdvancementRequirements.Strategy.AND) .save(consumer, REFERENCE.MODID + ":hunter/technology"); AdvancementHolder max_lord = Advancement.Builder.advancement() .display(ModItems.HUNTER_MINION_UPGRADE_SPECIAL.get(), Component.translatable("advancement.vampirism.max_lord_hunter"), Component.translatable("advancement.vampirism.max_lord_hunter.desc"), null, AdvancementType.CHALLENGE, true, true, true) .parent(max_level) - .addCriterion("level", FactionCriterionTrigger.TriggerInstance.lord(VReference.HUNTER_FACTION, 5)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.HUNTER_FACTION, 1)) + .addCriterion("level", FactionCriterionTrigger.TriggerInstance.lord(ModFactions.HUNTER, 5)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.HUNTER, 1)) .save(consumer, REFERENCE.MODID + ":hunter/max_lord"); AdvancementHolder cure_vampire = Advancement.Builder.advancement() .display(Items.GOLDEN_APPLE, Component.translatable("advancement.vampirism.cure_vampire_villager"), Component.translatable("advancement.vampirism.cure_vampire_villager.desc"), null, AdvancementType.TASK, true, true, true) .parent(become_hunter) .addCriterion("cure", CuredVampireVillagerCriterionTrigger.TriggerInstance.any()) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.HUNTER_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.HUNTER, 1)) .save(consumer, REFERENCE.MODID + ":hunter/cure_vampire_villager"); AdvancementHolder kill_mother = Advancement.Builder.advancement() .display(ModItems.MOTHER_CORE.get(), Component.translatable("advancement.vampirism.hunter_kill_mother"), Component.translatable("advancement.vampirism.hunter_kill_mother.desc"), null, AdvancementType.CHALLENGE, true, true, true) .parent(become_hunter) .addCriterion("killed", ModAdvancements.TRIGGER_MOTHER_WIN.get().createCriterion(new PlayerTrigger.TriggerInstance(Optional.empty()))) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.HUNTER_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.HUNTER, 1)) .save(consumer, REFERENCE.MODID + ":hunter/kill_mother"); AdvancementHolder kill_resurrected_vampire = Advancement.Builder.advancement() .display(ModItems.SOUL_ORB_VAMPIRE.get(), Component.translatable("advancement.vampirism.kill_resurrected_vampire"), Component.translatable("advancement.vampirism.kill_resurrected_vampire").append("\n").append(Component.translatable("advancement.vampirism.kill_resurrected_vampire.desc")), null, AdvancementType.TASK, true, true, true) .parent(become_hunter) - .addCriterion("killed", KilledTrigger.TriggerInstance.playerKilledEntity(EntityPredicate.Builder.entity().effects(MobEffectsPredicate.Builder.effects().and(ModEffects.NEONATAL)).subPredicate(FactionSubPredicate.faction(VReference.VAMPIRE_FACTION)))) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.HUNTER_FACTION, 1)) + .addCriterion("killed", KilledTrigger.TriggerInstance.playerKilledEntity(EntityPredicate.Builder.entity().effects(MobEffectsPredicate.Builder.effects().and(ModEffects.NEONATAL)).subPredicate(FactionSubPredicate.faction(ModFactions.VAMPIRE)))) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.HUNTER, 1)) .save(consumer, REFERENCE.MODID + ":hunter/kill_resurrected_vampire"); } } @@ -156,72 +156,72 @@ public void generate(@NotNull AdvancementHolder root, HolderLookup.@NotNull Prov AdvancementHolder become_vampire = Advancement.Builder.advancement() .display(ModItems.VAMPIRE_FANG.get(), Component.translatable("advancement.vampirism.become_vampire"), Component.translatable("advancement.vampirism.become_vampire.desc"), null, AdvancementType.TASK, true, false, false) .parent(root) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/become_vampire"); AdvancementHolder bat = Advancement.Builder.advancement() .display(Items.FEATHER, Component.translatable("advancement.vampirism.bat"), Component.translatable("advancement.vampirism.bat.desc"), null, AdvancementType.TASK, true, true, true) .parent(become_vampire) .addCriterion("action", VampireActionCriterionTrigger.TriggerInstance.of(VampireActionCriterionTrigger.Action.BAT)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/bat"); AdvancementHolder first_blood = Advancement.Builder.advancement() .display(ModItems.BLOOD_BOTTLE.get(), Component.translatable("advancement.vampirism.sucking_blood"), Component.translatable("advancement.vampirism.sucking_blood.desc"), null, AdvancementType.TASK, true, true, true) .parent(become_vampire) .addCriterion("flower", VampireActionCriterionTrigger.TriggerInstance.of(VampireActionCriterionTrigger.Action.SUCK_BLOOD)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/first_blood"); AdvancementHolder blood_cult = Advancement.Builder.advancement() .display(ModBlocks.ALTAR_INFUSION.get(), Component.translatable("advancement.vampirism.blood_cult"), Component.translatable("advancement.vampirism.blood_cult.desc"), null, AdvancementType.TASK, true, true, true) .parent(become_vampire) .addCriterion("flower", VampireActionCriterionTrigger.TriggerInstance.of(VampireActionCriterionTrigger.Action.PERFORM_RITUAL_INFUSION)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/blood_cult"); AdvancementHolder resurrect = Advancement.Builder.advancement() .display(ModItems.SOUL_ORB_VAMPIRE.get(), Component.translatable("advancement.vampirism.resurrect"), Component.translatable("advancement.vampirism.resurrect.desc"), null, AdvancementType.TASK, true, true, true) .parent(become_vampire) .addCriterion("resurrected", VampireActionCriterionTrigger.TriggerInstance.of(VampireActionCriterionTrigger.Action.RESURRECT)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/resurrect"); AdvancementHolder extra_storage = Advancement.Builder.advancement() .display(ModBlocks.BLOOD_CONTAINER.get(), Component.translatable("advancement.vampirism.extra_storage"), Component.translatable("advancement.vampirism.extra_storage.desc"), null, AdvancementType.TASK, true, true, true) .parent(first_blood) .addCriterion("blood_container", InventoryChangeTrigger.TriggerInstance.hasItems(ModBlocks.BLOOD_CONTAINER.get())) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/extra_storage"); AdvancementHolder max_level = Advancement.Builder.advancement() .display(ModItems.VAMPIRE_FANG.get(), Component.translatable("advancement.vampirism.max_level_vampire"), Component.translatable("advancement.vampirism.max_level_vampire.desc"), null, AdvancementType.GOAL, true, true, true) .parent(bat) - .addCriterion("level", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 14)) + .addCriterion("level", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 14)) .rewards(AdvancementRewards.Builder.experience(100)) .save(consumer, REFERENCE.MODID + ":vampire/max_level"); AdvancementHolder sniped = Advancement.Builder.advancement() .display(Items.ARROW, Component.translatable("advancement.vampirism.sniped"), Component.translatable("advancement.vampirism.sniped.desc"), null, AdvancementType.TASK, true, true, true) .parent(bat) .addCriterion("flower", VampireActionCriterionTrigger.TriggerInstance.of(VampireActionCriterionTrigger.Action.SNIPED_IN_BAT)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/sniped"); AdvancementHolder yuck = Advancement.Builder.advancement() .display(new DisplayInfo(ItemDataUtils.createPotion(Potions.POISON), Component.translatable("advancement.vampirism.yuck"), Component.translatable("advancement.vampirism.yuck.desc"), Optional.empty(), AdvancementType.TASK, true, true, true)) .parent(first_blood) .addCriterion("flower", VampireActionCriterionTrigger.TriggerInstance.of(VampireActionCriterionTrigger.Action.POISONOUS_BITE)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/yuck"); AdvancementHolder freeze_kill = Advancement.Builder.advancement() .display(new DisplayInfo(new ItemStack(Items.CLOCK), Component.translatable("advancement.vampirism.freeze_kill"), Component.translatable("advancement.vampirism.freeze_kill.desc"), Optional.empty(), AdvancementType.TASK, true, true, true)) .parent(blood_cult) .addCriterion("kill", VampireActionCriterionTrigger.TriggerInstance.of(VampireActionCriterionTrigger.Action.KILL_FROZEN_HUNTER)) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/freeze_kill"); AdvancementHolder max_lord = Advancement.Builder.advancement() .display(ModItems.VAMPIRE_MINION_UPGRADE_SPECIAL.get(), Component.translatable("advancement.vampirism.max_lord_vampire"), Component.translatable("advancement.vampirism.max_lord_vampire.desc"), null, AdvancementType.CHALLENGE, true, true, true) .parent(max_level) - .addCriterion("level", FactionCriterionTrigger.TriggerInstance.lord(VReference.VAMPIRE_FACTION, 5)) + .addCriterion("level", FactionCriterionTrigger.TriggerInstance.lord(ModFactions.VAMPIRE, 5)) .save(consumer, REFERENCE.MODID + ":vampire/max_lord"); AdvancementHolder kill_mother = Advancement.Builder.advancement() .display(ModItems.MOTHER_CORE.get(), Component.translatable("advancement.vampirism.vampire_kill_mother"), Component.translatable("advancement.vampirism.vampire_kill_mother.desc"), null, AdvancementType.CHALLENGE, true, true, true) .parent(become_vampire) .addCriterion("killed", ModAdvancements.TRIGGER_MOTHER_WIN.get().createCriterion(new PlayerTrigger.TriggerInstance(Optional.empty()))) - .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(VReference.VAMPIRE_FACTION, 1)) + .addCriterion("main", FactionCriterionTrigger.TriggerInstance.level(ModFactions.VAMPIRE, 1)) .save(consumer, REFERENCE.MODID + ":vampire/kill_mother"); } } diff --git a/src/main/java/de/teamlapen/vampirism/data/provider/LootTablesProvider.java b/src/main/java/de/teamlapen/vampirism/data/provider/LootTablesProvider.java index 34f65cb071..382048cdff 100644 --- a/src/main/java/de/teamlapen/vampirism/data/provider/LootTablesProvider.java +++ b/src/main/java/de/teamlapen/vampirism/data/provider/LootTablesProvider.java @@ -104,9 +104,9 @@ public void generate() { .withPool(LootPool.lootPool().when(LootItemRandomChanceWithLootingCondition.randomChanceAndLootingBoost(0.1f, 0.015f)).setRolls(ConstantValue.exactly(1)) .add(LootItem.lootTableItem(ModItems.VAMPIRE_BOOK.get()).setWeight(1).apply(AddBookNbtFunction.builder()))) .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1)).when(LootItemRandomChanceWithLootingCondition.randomChanceAndLootingBoost(0.05f, 0.01f)) - .add(LootItem.lootTableItem(ModItems.AMULET.get()).setWeight(1).apply(RefinementSetFunction.builder(VReference.VAMPIRE_FACTION))) - .add(LootItem.lootTableItem(ModItems.RING.get()).setWeight(1).apply(RefinementSetFunction.builder(VReference.VAMPIRE_FACTION))) - .add(LootItem.lootTableItem(ModItems.OBI_BELT.get()).setWeight(1).apply(RefinementSetFunction.builder(VReference.VAMPIRE_FACTION)))); + .add(LootItem.lootTableItem(ModItems.AMULET.get()).setWeight(1).apply(RefinementSetFunction.builder(ModFactions.VAMPIRE))) + .add(LootItem.lootTableItem(ModItems.RING.get()).setWeight(1).apply(RefinementSetFunction.builder(ModFactions.VAMPIRE))) + .add(LootItem.lootTableItem(ModItems.OBI_BELT.get()).setWeight(1).apply(RefinementSetFunction.builder(ModFactions.VAMPIRE)))); this.add(ModEntities.ADVANCED_VAMPIRE.get(), advanced_vampire); this.add(ModEntities.ADVANCED_VAMPIRE_IMOB.get(), advanced_vampire); this.add(ModEntities.BLINDING_BAT.get(), LootTable.lootTable()); @@ -129,9 +129,9 @@ public void generate() { .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1)).when(StakeCondition.builder(LootContext.EntityTarget.KILLER_PLAYER)).when(LootItemRandomChanceWithLootingCondition.randomChanceAndLootingBoost(0.5f, 0.05f)) .add(LootItem.lootTableItem(ModItems.VAMPIRE_BLOOD_BOTTLE.get()).setWeight(1))) .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1)).when(LootItemRandomChanceWithLootingCondition.randomChanceAndLootingBoost(0.02f, 0.01f)) - .add(LootItem.lootTableItem(ModItems.AMULET.get()).setWeight(1).apply(RefinementSetFunction.builder(VReference.VAMPIRE_FACTION))) - .add(LootItem.lootTableItem(ModItems.RING.get()).setWeight(1).apply(RefinementSetFunction.builder(VReference.VAMPIRE_FACTION))) - .add(LootItem.lootTableItem(ModItems.OBI_BELT.get()).setWeight(1).apply(RefinementSetFunction.builder(VReference.VAMPIRE_FACTION)))); + .add(LootItem.lootTableItem(ModItems.AMULET.get()).setWeight(1).apply(RefinementSetFunction.builder(ModFactions.VAMPIRE))) + .add(LootItem.lootTableItem(ModItems.RING.get()).setWeight(1).apply(RefinementSetFunction.builder(ModFactions.VAMPIRE))) + .add(LootItem.lootTableItem(ModItems.OBI_BELT.get()).setWeight(1).apply(RefinementSetFunction.builder(ModFactions.VAMPIRE)))); this.add(ModEntities.VAMPIRE.get(), vampire); this.add(ModEntities.VAMPIRE_IMOB.get(), vampire); this.add(ModEntities.VAMPIRE_BARON.get(), LootTable.lootTable() @@ -149,9 +149,9 @@ public void generate() { .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1)).when(LootItemKilledByPlayerCondition.killedByPlayer()).when(LootItemRandomChanceWithLootingCondition.randomChanceAndLootingBoost(0.33f, 0.005f)) .add(LootItem.lootTableItem(ModItems.HUMAN_HEART.get()).setWeight(1))) .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1)).when(LootItemRandomChanceWithLootingCondition.randomChanceAndLootingBoost(0.05f, 0.02f)) - .add(LootItem.lootTableItem(ModItems.AMULET.get()).setWeight(1).apply(RefinementSetFunction.builder(VReference.VAMPIRE_FACTION))) - .add(LootItem.lootTableItem(ModItems.RING.get()).setWeight(1).apply(RefinementSetFunction.builder(VReference.VAMPIRE_FACTION))) - .add(LootItem.lootTableItem(ModItems.OBI_BELT.get()).setWeight(1).apply(RefinementSetFunction.builder(VReference.VAMPIRE_FACTION)))); + .add(LootItem.lootTableItem(ModItems.AMULET.get()).setWeight(1).apply(RefinementSetFunction.builder(ModFactions.VAMPIRE))) + .add(LootItem.lootTableItem(ModItems.RING.get()).setWeight(1).apply(RefinementSetFunction.builder(ModFactions.VAMPIRE))) + .add(LootItem.lootTableItem(ModItems.OBI_BELT.get()).setWeight(1).apply(RefinementSetFunction.builder(ModFactions.VAMPIRE)))); this.add(ModEntities.HUNTER.get(), hunter); this.add(ModEntities.HUNTER_IMOB.get(), hunter); this.add(ModEntities.VILLAGER_ANGRY.get(), LootTable.lootTable()); @@ -383,9 +383,9 @@ public void generate(HolderLookup.@NotNull Provider holderProvider, BiConsumer run(@NotNull CachedOutput pOutput) { - return this.lookupProvider.thenApply(provider -> { + return this.lookupProvider.thenCompose(provider -> { Set set = new HashSet<>(); List> list = new ArrayList<>(); RegistryOps ops = RegistryOps.create(JsonOps.INSTANCE, provider); diff --git a/src/main/java/de/teamlapen/vampirism/data/provider/tags/ModFactionProvider.java b/src/main/java/de/teamlapen/vampirism/data/provider/tags/ModFactionProvider.java new file mode 100644 index 0000000000..05270e8122 --- /dev/null +++ b/src/main/java/de/teamlapen/vampirism/data/provider/tags/ModFactionProvider.java @@ -0,0 +1,35 @@ +package de.teamlapen.vampirism.data.provider.tags; + +import de.teamlapen.vampirism.REFERENCE; +import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.core.ModFactions; +import de.teamlapen.vampirism.core.ModVillage; +import de.teamlapen.vampirism.core.tags.ModFactionTags; +import de.teamlapen.vampirism.core.tags.ModPoiTypeTags; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.PackOutput; +import net.minecraft.data.tags.PoiTypeTagsProvider; +import net.minecraft.data.tags.TagsProvider; +import net.minecraft.tags.PoiTypeTags; +import net.neoforged.neoforge.common.data.ExistingFileHelper; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.concurrent.CompletableFuture; + +public class ModFactionProvider extends TagsProvider> { + + public ModFactionProvider(PackOutput output, CompletableFuture lookupProvider, @Nullable ExistingFileHelper existingFileHelper) { + super(output, VampirismRegistries.Keys.FACTION, lookupProvider, REFERENCE.MODID, existingFileHelper); + } + + @Override + protected void addTags(HolderLookup.@NotNull Provider holderProvider) { + this.tag(ModFactionTags.HOSTILE_TOWARDS_NEUTRAL).add(ModFactions.VAMPIRE.getRawKey()); + this.tag(ModFactionTags.IS_HUNTER).add(ModFactions.HUNTER.getRawKey()); + this.tag(ModFactionTags.IS_VAMPIRE).add(ModFactions.VAMPIRE.getRawKey()); + this.tag(ModFactionTags.HAS_LORD_SKILLS).add(ModFactions.VAMPIRE.getRawKey(), ModFactions.HUNTER.getRawKey()); + this.tag(ModFactionTags.ALL_FACTIONS).addTag(ModFactionTags.IS_HUNTER).addTag(ModFactionTags.IS_VAMPIRE); + } +} diff --git a/src/main/java/de/teamlapen/vampirism/data/provider/tags/TagProvider.java b/src/main/java/de/teamlapen/vampirism/data/provider/tags/TagProvider.java index e50cb43a8d..1838c1d51a 100644 --- a/src/main/java/de/teamlapen/vampirism/data/provider/tags/TagProvider.java +++ b/src/main/java/de/teamlapen/vampirism/data/provider/tags/TagProvider.java @@ -27,6 +27,7 @@ public static void register(DataGenerator gen, @NotNull GatherDataEvent event, P gen.addProvider(event.includeServer(), new ModSkillTreeProvider(output, future, existingFileHelper)); gen.addProvider(event.includeServer(), new ModEffectTypeProvider(output, future, existingFileHelper)); gen.addProvider(event.includeServer(), new ModEnchantmentProvider(output, future, existingFileHelper)); + gen.addProvider(event.includeServer(), new ModFactionProvider(output, future, existingFileHelper)); } } diff --git a/src/main/java/de/teamlapen/vampirism/data/recipebuilder/SkillNodeBuilder.java b/src/main/java/de/teamlapen/vampirism/data/recipebuilder/SkillNodeBuilder.java deleted file mode 100644 index b896e0e4e5..0000000000 --- a/src/main/java/de/teamlapen/vampirism/data/recipebuilder/SkillNodeBuilder.java +++ /dev/null @@ -1,108 +0,0 @@ -package de.teamlapen.vampirism.data.recipebuilder; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import de.teamlapen.vampirism.api.VReference; -import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; -import de.teamlapen.vampirism.api.entity.player.skills.ISkill; -import de.teamlapen.vampirism.util.RegUtil; -import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; - -public class SkillNodeBuilder { - - public static @NotNull SkillNodeBuilder skill(@NotNull ResourceLocation parent, @NotNull ISkill... skills) { - return new SkillNodeBuilder(parent, skills); - } - - public static SkillNodeBuilder hunter(@NotNull ResourceLocation parent, @NotNull ISkill... skills) { - assertFactionSkills(VReference.HUNTER_FACTION, skills); - return skill(parent, skills).faction(VReference.HUNTER_FACTION); - } - - public static SkillNodeBuilder vampire(@NotNull ResourceLocation parent, @NotNull ISkill... skills) { - assertFactionSkills(VReference.VAMPIRE_FACTION, skills); - return skill(parent, skills).faction(VReference.VAMPIRE_FACTION); - } - - public static void assertFactionSkills(IPlayableFaction faction, ISkill... skills) { - if(Arrays.stream(skills).anyMatch(skill -> skill.getFaction().filter(f -> f != faction).isPresent())){ - throw new IllegalArgumentException("Illegal skill for faction. Skills must be for the same or any faction"); - } - } - - private final @NotNull ResourceLocation parent; - private final ISkill[] skills; - private ResourceLocation faction; - private ResourceLocation[] lockingSkillNodes; - - public SkillNodeBuilder(@NotNull ResourceLocation parent, @NotNull ISkill... skills) { - this.parent = parent; - this.skills = skills; - this.lockingSkillNodes = new ResourceLocation[0]; - } - - public @NotNull ResourceLocation build(@NotNull SkillNodeOutput output, @NotNull ResourceLocation id) { - if (faction != null) { - id = new ResourceLocation(id.getNamespace(), faction.getPath() + "/" + id.getPath()); - } - this.validate(id); - output.accept(id, new Result(id, this.parent, this.skills, this.lockingSkillNodes)); - return id; - } - - public @NotNull SkillNodeBuilder faction(@NotNull IPlayableFaction faction) { - this.faction = faction.getID(); - return this; - } - - public @NotNull SkillNodeBuilder lockingNodes(@NotNull ResourceLocation... skillNodes) { - this.lockingSkillNodes = skillNodes; - return this; - } - - private void validate(@NotNull ResourceLocation id) { - if (this.skills.length == 0) { - throw new IllegalStateException("No skills defined for skill node " + id + "!"); - } - } - - @SuppressWarnings("ClassCanBeRecord") - private static class Result implements FinishedSkillNode { - private final @NotNull ResourceLocation parent; - private final ISkill[] skills; - private final @NotNull ResourceLocation id; - private final ResourceLocation[] lockingSkillNodes; - - public Result(@NotNull ResourceLocation id, @NotNull ResourceLocation parent, @NotNull ISkill[] skills, @NotNull ResourceLocation[] lockingSkillNodes) { - this.id = id; - this.parent = parent; - this.skills = skills; - this.lockingSkillNodes = lockingSkillNodes; - } - - @Override - public @NotNull ResourceLocation getID() { - return id; - } - - @Override - public void serialize(@NotNull JsonObject json) { - json.addProperty("parent", parent.toString()); - JsonArray array = new JsonArray(); - for (ISkill skill : this.skills) { - array.add(RegUtil.id(skill).toString()); - } - json.add("skills", array); - if (lockingSkillNodes.length > 0) { - JsonArray nodes = new JsonArray(); - for (ResourceLocation lockingSkillNode : this.lockingSkillNodes) { - nodes.add(lockingSkillNode.toString()); - } - json.add("locking", nodes); - } - } - } -} diff --git a/src/main/java/de/teamlapen/vampirism/effects/BadOmenEffect.java b/src/main/java/de/teamlapen/vampirism/effects/BadOmenEffect.java index 39553fef13..9ffe4285d2 100644 --- a/src/main/java/de/teamlapen/vampirism/effects/BadOmenEffect.java +++ b/src/main/java/de/teamlapen/vampirism/effects/BadOmenEffect.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; +import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.util.TotemHelper; import net.minecraft.core.Holder; @@ -21,7 +22,9 @@ /** * does not extend {@link VampirismEffect} so other mods can use this too */ -public abstract class BadOmenEffect extends MobEffect { +public class BadOmenEffect extends MobEffect { + + private final Holder> faction; /** * Call this if onDeath of an entity that might carry a faction banner. @@ -32,11 +35,11 @@ public abstract class BadOmenEffect extends MobEffect { */ public static void handlePotentialBannerKill(@Nullable Entity offender, @NotNull IFactionEntity victim) { if (offender instanceof Player player) { - IFaction faction = victim.getFaction(); - if (faction.getVillageData().isBanner(victim.asEntity().getItemBySlot(EquipmentSlot.HEAD), offender.registryAccess())) { - IFaction playerFaction = VampirismPlayerAttributes.get(player).faction; + Holder> faction = victim.getFaction(); + if (faction.value().getVillageData().isBanner(victim.asEntity().getItemBySlot(EquipmentSlot.HEAD), offender.registryAccess())) { + Holder> playerFaction = VampirismPlayerAttributes.get(player).faction; if (playerFaction != null && playerFaction != faction) { - Holder badOmen = faction.getVillageData().badOmenEffect(); + Holder badOmen = faction.value().getVillageData().badOmenEffect(); if (badOmen != null) { MobEffectInstance inst = player.getEffect(badOmen); int i = inst != null ? Math.min(inst.getAmplifier() + 1, 4) : 0; @@ -49,12 +52,11 @@ public static void handlePotentialBannerKill(@Nullable Entity offender, @NotNull } } - public BadOmenEffect() { + public BadOmenEffect(Holder> faction) { super(MobEffectCategory.NEUTRAL, 745784); + this.faction = faction; } - public abstract IFaction getFaction(); - @Override public boolean applyEffectTick(@NotNull LivingEntity entityLivingBaseIn, int amplifier) { if (entityLivingBaseIn instanceof ServerPlayer playerEntity && !entityLivingBaseIn.isSpectator()) { @@ -62,8 +64,8 @@ public boolean applyEffectTick(@NotNull LivingEntity entityLivingBaseIn, int amp if (serverWorld.getDifficulty() == Difficulty.PEACEFUL) { return true; } - return !TotemHelper.getTotemNearPos(serverWorld, entityLivingBaseIn.blockPosition(), true).filter(s -> s.getControllingFaction() != getFaction()).map(totem -> { - return totem.initiateCaptureOrIncreaseBadOmenLevel(getFaction(), null, Math.min(amplifier, 4) + 1, 0); + return !TotemHelper.getTotemNearPos(serverWorld, entityLivingBaseIn.blockPosition(), true).filter(s -> !IFaction.is(s.getControllingFaction(), this.faction)).map(totem -> { + return totem.initiateCaptureOrIncreaseBadOmenLevel(this.faction, null, Math.min(amplifier, 4) + 1, 0); }).orElse(false); } return true; diff --git a/src/main/java/de/teamlapen/vampirism/entity/BlindingBatEntity.java b/src/main/java/de/teamlapen/vampirism/entity/BlindingBatEntity.java index 8b9e02ccfb..7c98ca8de5 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/BlindingBatEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/BlindingBatEntity.java @@ -3,6 +3,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; import de.teamlapen.vampirism.config.BalanceMobProps; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.tags.ModBiomeTags; import de.teamlapen.vampirism.util.DamageHandler; import de.teamlapen.vampirism.util.Helper; @@ -50,7 +51,7 @@ public static boolean spawnPredicate(@NotNull EntityType !Helper.appearsAsVampire(e, this)); private boolean restrictLiveSpan; private boolean targeting; diff --git a/src/main/java/de/teamlapen/vampirism/entity/GhostEntity.java b/src/main/java/de/teamlapen/vampirism/entity/GhostEntity.java index 4f7e6d6e37..e83830d954 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/GhostEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/GhostEntity.java @@ -3,6 +3,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; import de.teamlapen.vampirism.api.entity.IEntityLeader; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModSounds; import de.teamlapen.vampirism.core.tags.ModDamageTypeTags; import de.teamlapen.vampirism.entity.ai.goals.DefendLeaderGoal; @@ -74,10 +75,10 @@ protected void registerGoals() { this.goalSelector.addGoal(9, new LookAtPlayerGoal(this, Player.class, 16)); this.targetSelector.addGoal(1, new HurtByTargetGoal(this)); - NearestAttackableTargetGoal goal = new NearestAttackableTargetGoal<>(this, Player.class, 0, false, false, VampirismAPI.factionRegistry().getPredicate(VReference.VAMPIRE_FACTION, true, false, true, true, null)); + NearestAttackableTargetGoal goal = new NearestAttackableTargetGoal<>(this, Player.class, 0, false, false, VampirismAPI.factionRegistry().getPredicate(ModFactions.VAMPIRE, true, false, true, true, null)); ((NearestTargetGoalModifier) goal).ignoreLineOfSight(); this.targetSelector.addGoal(3, goal); - NearestAttackableTargetGoal goal2 = new NearestAttackableTargetGoal<>(this, PathfinderMob.class, 5, false, false, VampirismAPI.factionRegistry().getPredicate(VReference.VAMPIRE_FACTION, false, true, false, true, null)) { + NearestAttackableTargetGoal goal2 = new NearestAttackableTargetGoal<>(this, PathfinderMob.class, 5, false, false, VampirismAPI.factionRegistry().getPredicate(ModFactions.VAMPIRE, false, true, false, true, null)) { @Override protected double getFollowDistance() { return super.getFollowDistance() / 2; diff --git a/src/main/java/de/teamlapen/vampirism/entity/ModEntityEventHandler.java b/src/main/java/de/teamlapen/vampirism/entity/ModEntityEventHandler.java index 5083ae3a7a..4184ab063e 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/ModEntityEventHandler.java +++ b/src/main/java/de/teamlapen/vampirism/entity/ModEntityEventHandler.java @@ -9,6 +9,7 @@ import de.teamlapen.vampirism.blockentity.TotemBlockEntity; import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModEffects; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.core.tags.ModBlockTags; import de.teamlapen.vampirism.core.tags.ModDamageTypeTags; @@ -206,7 +207,7 @@ public void onEntityJoinWorld(@NotNull EntityJoinLevelEvent event) { if (event.getEntity() instanceof Villager) { Optional tile = TotemHelper.getTotemNearPos(((ServerLevel) event.getLevel()), event.getEntity().blockPosition(), true); - if (tile.filter(t -> VReference.HUNTER_FACTION.equals(t.getControllingFaction())).isPresent()) { + if (tile.filter(t -> ModFactions.HUNTER.match(t.getControllingFaction())).isPresent()) { ExtendedCreature.getSafe(event.getEntity()).ifPresent(e -> e.setPoisonousBlood(true)); } //noinspection UnnecessaryReturnStatement diff --git a/src/main/java/de/teamlapen/vampirism/entity/VampirismEntity.java b/src/main/java/de/teamlapen/vampirism/entity/VampirismEntity.java index 91810e168f..72d818de7c 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/VampirismEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/VampirismEntity.java @@ -11,11 +11,13 @@ import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModParticles; import de.teamlapen.vampirism.core.tags.ModBiomeTags; +import de.teamlapen.vampirism.core.tags.ModFactionTags; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.particle.GenericParticleOptions; import de.teamlapen.vampirism.util.Helper; import de.teamlapen.vampirism.world.fog.FogLevel; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; @@ -325,10 +327,10 @@ private void checkImobConversion() { if (opt == ServerConfig.IMobOptions.SMART) { Player player = VampirismMod.proxy.getClientPlayer(); if (player != null && player.isAlive()) { - IPlayableFaction f = VampirismPlayerAttributes.get(player).faction; - IFaction thisFaction = ((IFactionEntity) this).getFaction(); + Holder> f = VampirismPlayerAttributes.get(player).faction; + Holder> thisFaction = (Holder>) ((IFactionEntity) this).getFaction(); - boolean hostile = f == null ? thisFaction.isHostileTowardsNeutral() : !thisFaction.equals(f); + boolean hostile = f == null ? thisFaction.is(ModFactionTags.HOSTILE_TOWARDS_NEUTRAL) : !thisFaction.equals(f); convert = hostile != current; } diff --git a/src/main/java/de/teamlapen/vampirism/entity/ai/goals/GolemTargetNonVillageFactionGoal.java b/src/main/java/de/teamlapen/vampirism/entity/ai/goals/GolemTargetNonVillageFactionGoal.java index a016888fc7..8b5aa9a562 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/ai/goals/GolemTargetNonVillageFactionGoal.java +++ b/src/main/java/de/teamlapen/vampirism/entity/ai/goals/GolemTargetNonVillageFactionGoal.java @@ -3,9 +3,14 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; +import de.teamlapen.vampirism.api.entity.player.hunter.IHunterPlayer; +import de.teamlapen.vampirism.api.registries.DeferredFaction; import de.teamlapen.vampirism.blockentity.TotemBlockEntity; import de.teamlapen.vampirism.config.VampirismConfig; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.util.TotemHelper; +import net.minecraft.core.Holder; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal; @@ -21,9 +26,9 @@ * Targets vampires if the golem as a non vampire village assigned */ public class GolemTargetNonVillageFactionGoal extends NearestAttackableTargetGoal { - private static final Map, Predicate> predicates = new HashMap<>(); + private static final Map>, Predicate> predicates = new HashMap<>(); private final @NotNull IronGolem golem; - private IFaction faction; + private Holder> faction; public GolemTargetNonVillageFactionGoal(@NotNull IronGolem creature) { super(creature, LivingEntity.class, 4, false, false, null); @@ -58,15 +63,16 @@ protected void findTarget() { * * @return Whether the faction has changed */ - @SuppressWarnings({"unchecked", "rawtypes"}) private boolean determineGolemFaction() { - IFaction faction = VReference.HUNTER_FACTION; + Holder> faction = ModFactions.HUNTER; if (VampirismConfig.BALANCE.golemAttackNonVillageFaction.get()) { - Optional tile = TotemHelper.getTotemNearPos(((ServerLevel) this.golem.level()), this.golem.blockPosition(), true); - faction = tile.map(TotemBlockEntity::getControllingFaction).orElse(((IFaction) VReference.HUNTER_FACTION)); // Raw type because otherwise it does not work + Optional>> tile = TotemHelper.getTotemNearPos(((ServerLevel) this.golem.level()), this.golem.blockPosition(), true).map(TotemBlockEntity::getControllingFaction); + if (tile.isPresent()) { + faction = tile.get(); + } } - if (faction != this.faction) { + if (IFaction.is(faction, this.faction)) { this.targetConditions.selector(predicates.computeIfAbsent(this.faction = faction, faction1 -> VampirismAPI.factionRegistry().getPredicate(faction1, true, true, false, false, null))); return true; } diff --git a/src/main/java/de/teamlapen/vampirism/entity/converted/CurableConvertedCreature.java b/src/main/java/de/teamlapen/vampirism/entity/converted/CurableConvertedCreature.java index dbaba29729..05ddb88472 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/converted/CurableConvertedCreature.java +++ b/src/main/java/de/teamlapen/vampirism/entity/converted/CurableConvertedCreature.java @@ -10,6 +10,7 @@ import de.teamlapen.vampirism.api.items.IVampireFinisher; import de.teamlapen.vampirism.core.ModAttributes; import de.teamlapen.vampirism.core.ModEffects; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.entity.ConvertedCreature; import de.teamlapen.vampirism.entity.CrossbowArrowEntity; import de.teamlapen.vampirism.entity.SoulOrbEntity; @@ -267,7 +268,7 @@ default void tickDeathC() { @SuppressWarnings("JavadocReference") default void registerGoalsC() { PathfinderMob entity = ((PathfinderMob) this); - entity.goalSelector.addGoal(1, new AvoidEntityGoal<>(entity, PathfinderMob.class, 10, 1, 1.1, VampirismAPI.factionRegistry().getPredicate(getFaction(), false, true, false, false, VReference.HUNTER_FACTION))); + entity.goalSelector.addGoal(1, new AvoidEntityGoal<>(entity, PathfinderMob.class, 10, 1, 1.1, VampirismAPI.factionRegistry().getPredicate(getFaction(), false, true, false, false, ModFactions.HUNTER))); entity.goalSelector.addGoal(4, new RestrictSunGoal(entity)); entity.goalSelector.addGoal(5, new AttackMeleeNoSunGoal(entity, 0.9D, false)); diff --git a/src/main/java/de/teamlapen/vampirism/entity/factions/FactionPlayerHandler.java b/src/main/java/de/teamlapen/vampirism/entity/factions/FactionPlayerHandler.java index fe115234de..7a38398b88 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/factions/FactionPlayerHandler.java +++ b/src/main/java/de/teamlapen/vampirism/entity/factions/FactionPlayerHandler.java @@ -15,6 +15,7 @@ import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModAdvancements; import de.teamlapen.vampirism.core.ModAttachments; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.core.tags.ModTaskTags; import de.teamlapen.vampirism.entity.minion.management.PlayerMinionController; @@ -22,6 +23,7 @@ import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.misc.VampirismLogger; import de.teamlapen.vampirism.util.DamageHandler; +import de.teamlapen.vampirism.util.RegUtil; import de.teamlapen.vampirism.util.ScoreboardUtil; import de.teamlapen.vampirism.util.VampirismEventFactory; import de.teamlapen.vampirism.world.MinionWorldData; @@ -81,7 +83,7 @@ public class FactionPlayerHandler implements IAttachment, IFactionPlayerHandler private final Player player; @NotNull private final Int2ObjectMap>> boundActions = new Int2ObjectArrayMap<>(); - private @Nullable IPlayableFaction currentFaction = null; + private @Nullable Holder> currentFaction = null; private int currentLevel = 0; private int currentLordLevel = 0; @NotNull @@ -97,7 +99,7 @@ public FactionPlayerHandler(Player player) { } @Override - public boolean canJoin(IPlayableFaction faction) { + public boolean canJoin(Holder> faction) { PlayerFactionEvent.CanJoinFaction.Behavior behavior = VampirismEventFactory.fireCanJoinFactionEvent(this, currentFaction, faction); if (behavior == PlayerFactionEvent.CanJoinFaction.Behavior.ONLY_WHEN_NO_FACTION) { return currentFaction == null; @@ -106,10 +108,14 @@ public boolean canJoin(IPlayableFaction faction) { } @Override - public boolean canLeaveFaction() { - return currentFaction == null || currentFaction.getPlayerCapability(player).map(IFactionPlayer::canLeaveFaction).orElse(false); + public boolean canJoin(IPlayableFaction faction) { + return canJoin(RegUtil.holder(faction)); } + @Override + public boolean canLeaveFaction() { + return currentFaction == null || currentFaction.value().getPlayerCapability(player).map(IFactionPlayer::canLeaveFaction).orElse(false); + } /** * @param id ATM 1-3 @@ -125,16 +131,23 @@ public Holder> getBoundAction(int id) { return SERIALIZER_ID; } + @SuppressWarnings("unchecked") @Nullable @Override public > IPlayableFaction getCurrentFaction() { - return (IPlayableFaction) currentFaction; + return currentFaction == null ? null : (IPlayableFaction) currentFaction.value(); + } + + @Nullable + @Override + public Holder> getFaction() { + return currentFaction; } @NotNull @Override public > Optional getCurrentFactionPlayer() { - return currentFaction == null ? Optional.empty() : (Optional) currentFaction.getPlayerCapability(player); + return currentFaction == null ? Optional.empty() : (Optional) currentFaction.value().getPlayerCapability(player); } @Override @@ -147,15 +160,19 @@ public int getCurrentLevel(IPlayableFaction f) { return isInFaction(f) ? currentLevel : 0; } + @Override + public int getCurrentLevel(Holder> f) { + return isInFaction(f) ? currentLevel : 0; + } + @Override public float getCurrentLevelRelative() { - return currentFaction == null ? 0 : currentLevel / (float) currentFaction.getHighestReachableLevel(); + return currentFaction == null ? 0 : currentLevel / (float) currentFaction.value().getHighestReachableLevel(); } - @Nullable @Override - public IPlayableFaction getLordFaction() { - return currentLordLevel > 0 ? currentFaction : null; + public @NotNull Optional>> getLordFaction() { + return currentLordLevel > 0 ? Optional.ofNullable(currentFaction) : Optional.empty(); } @Override @@ -175,7 +192,7 @@ public Component getLordTitle() { } public @NotNull Optional lordTitles() { - return Optional.ofNullable(currentFaction).map(IPlayableFaction::lordTiles); + return Optional.ofNullable(currentFaction).map(Holder::value).map(IPlayableFaction::lordTiles); } public int getMaxMinions() { @@ -195,19 +212,32 @@ public IPlayableFaction.TitleGender titleGender() { @Override public boolean isInFaction(@Nullable IFaction f) { - return Objects.equals(currentFaction, f); + if (this.currentFaction != null) { + return Objects.equals(currentFaction.value(), f); + } + return Objects.equals(null, f); } @Override - public void joinFaction(@NotNull IPlayableFaction faction) { + public > boolean isInFaction(@Nullable Holder f) { + return IFaction.is(currentFaction, f); + } + + @Override + public void joinFaction(@NotNull Holder> faction) { if (canJoin(faction)) { setFactionAndLevel(faction, 1); } } + @Override + public void joinFaction(@NotNull IPlayableFaction faction) { + joinFaction(RegUtil.holder(faction)); + } + @Override public void deserializeUpdateNBT(HolderLookup.Provider provider, @NotNull CompoundTag nbt) { - IPlayableFaction old = currentFaction; + Holder> old = currentFaction; int oldLevel = currentLevel; if (nbt.contains("faction", Tag.TAG_STRING)) { String f = nbt.getString("faction"); @@ -277,19 +307,19 @@ public void setBoundAction(int id, @Nullable Holder> boundAction, boo } @Override - public boolean setFactionAndLevel(@Nullable IPlayableFaction faction, int level) { - IPlayableFaction old = currentFaction; + public boolean setFactionAndLevel(@Nullable Holder> faction, int level) { + Holder> old = currentFaction; int oldLevel = currentLevel; int newLordLevel = this.currentLordLevel; if (currentFaction != null && (!currentFaction.equals(faction) || level == 0)) { - if (!currentFaction.getPlayerCapability(player).map(IFactionPlayer::canLeaveFaction).orElse(false)) { - LOGGER.info("You cannot leave faction {}, it is prevented by respective mod", currentFaction.getID()); + if (!currentFaction.value().getPlayerCapability(player).map(IFactionPlayer::canLeaveFaction).orElse(false)) { + LOGGER.info("You cannot leave faction {}, it is prevented by respective mod", currentFaction.getRegisteredName()); return false; } } - if (faction != null && (level < 0 || level > faction.getHighestReachableLevel())) { - LOGGER.warn("Level {} in faction {} cannot be reached", level, faction.getID()); + if (faction != null && (level < 0 || level > faction.value().getHighestReachableLevel())) { + LOGGER.warn("Level {} in faction {} cannot be reached", level, faction.getRegisteredName()); return false; } if (VampirismEventFactory.fireChangeLevelOrFactionEvent(this, old, oldLevel, faction, faction == null ? 0 : level)) { @@ -297,7 +327,7 @@ public boolean setFactionAndLevel(@Nullable IPlayableFaction faction, int lev return false; } if (this.currentFaction != null && faction != this.currentFaction) { - this.currentFaction.getPlayerCapability(player).ifPresent(factionPlayer -> factionPlayer.getTaskManager().reset()); + this.currentFaction.value().getPlayerCapability(player).ifPresent(factionPlayer -> factionPlayer.getTaskManager().reset()); } if (faction == null) { currentFaction = null; @@ -306,7 +336,7 @@ public boolean setFactionAndLevel(@Nullable IPlayableFaction faction, int lev } else { currentFaction = faction; currentLevel = level; - if (currentLevel != currentFaction.getHighestReachableLevel() || currentFaction != old) { + if (currentLevel != currentFaction.value().getHighestReachableLevel() || currentFaction != old) { newLordLevel = 0; } } @@ -322,9 +352,9 @@ public boolean setFactionAndLevel(@Nullable IPlayableFaction faction, int lev notifyFaction(old, oldLevel); if (this.player instanceof ServerPlayer && !(currentFaction == old && oldLevel == currentLevel)) { if (old == currentFaction) { - VampirismLogger.info(VampirismLogger.LEVEL, "{} has new faction level {} {}, was {}", this.player.getName().getString(), currentFaction.getID(), currentLevel, oldLevel); + VampirismLogger.info(VampirismLogger.LEVEL, "{} has new faction level {} {}, was {}", this.player.getName().getString(), currentFaction.getRegisteredName(), currentLevel, oldLevel); } else if (currentFaction != null) { - VampirismLogger.info(VampirismLogger.LEVEL, "{} is now in faction {} {}", this.player.getName().getString(), currentFaction.getID(), currentLevel); + VampirismLogger.info(VampirismLogger.LEVEL, "{} is now in faction {} {}", this.player.getName().getString(), currentFaction.getRegisteredName(), currentLevel); } else { VampirismLogger.info(VampirismLogger.LEVEL, "{} has now no level", this.player.getName().getString()); } @@ -346,9 +376,19 @@ public boolean setFactionAndLevel(@Nullable IPlayableFaction faction, int lev } + @Override + public boolean setFactionAndLevel(@Nullable IPlayableFaction faction, int level) { + return setFactionAndLevel(faction == null ? null : RegUtil.holder(faction), level); + } + + @Override + public boolean setFactionLevel(@NotNull Holder> faction, int level) { + return faction == currentFaction && setFactionAndLevel(faction, level); + } + @Override public boolean setFactionLevel(@NotNull IPlayableFaction faction, int level) { - return faction.equals(currentFaction) && setFactionAndLevel(faction, level); + return setFactionLevel(RegUtil.holder(faction), level); } @Override @@ -368,7 +408,7 @@ public boolean setTitleGender(boolean female) { @Override public @NotNull CompoundTag serializeUpdateNBT(HolderLookup.@NotNull Provider provider) { CompoundTag nbt = new CompoundTag(); - nbt.putString("faction", currentFaction == null ? "null" : currentFaction.getID().toString()); + nbt.putString("faction", Optional.ofNullable(this.currentFaction).flatMap(Holder::unwrapKey).map(ResourceKey::location).map(ResourceLocation::toString).orElse("null")); nbt.putInt("level", currentLevel); nbt.putInt("lord_level", currentLordLevel); nbt.putString("title_gender", titleGender.name()); @@ -378,22 +418,17 @@ public boolean setTitleGender(boolean female) { @Override public void leaveFaction(boolean die) { - IFaction oldFaction = currentFaction; + Holder> oldFaction = currentFaction; if (oldFaction == null) return; - setFactionAndLevel(null, 0); - player.displayClientMessage(Component.translatable("command.vampirism.base.level.successful", player.getName(), oldFaction.getName(), 0), true); + setFactionAndLevel((Holder>) null, 0); + player.displayClientMessage(Component.translatable("command.vampirism.base.level.successful", player.getName(), oldFaction.value().getName(), 0), true); if (die) { DamageHandler.kill(player, 10000); } } - private @Nullable IPlayableFaction getFactionFromKey(ResourceLocation key) { - for (IPlayableFaction p : VampirismAPI.factionRegistry().getPlayableFactions()) { - if (p.getID().equals(key)) { - return p; - } - } - return null; + private @Nullable Holder> getFactionFromKey(ResourceLocation key) { + return (Holder>) (Object) ModRegistries.FACTIONS.getHolder(key).orElse(null); } private void loadBoundActions(@NotNull CompoundTag nbt) { @@ -418,22 +453,22 @@ public void checkSkillTreeLocks() { * Notify faction about changes. * {@link FactionPlayerHandler#currentFaction} and {@link FactionPlayerHandler#currentLevel} will be used as the new ones */ - private void notifyFaction(@Nullable IPlayableFaction oldFaction, int oldLevel) { + private void notifyFaction(@Nullable Holder> oldFaction, int oldLevel) { if (oldFaction != null && !oldFaction.equals(currentFaction)) { - LOGGER.debug(LogUtil.FACTION, "{} is leaving faction {}", this.player.getName().getString(), oldFaction.getID()); - VampirismLogger.info(VampirismLogger.LEVEL, "{} is leaving faction {}", this.player.getName().getString(), oldFaction.getID()); - oldFaction.getPlayerCapability(player).ifPresent(c -> c.onLevelChanged(0, oldLevel)); + LOGGER.debug(LogUtil.FACTION, "{} is leaving faction {}", this.player.getName().getString(), oldFaction.getRegisteredName()); + VampirismLogger.info(VampirismLogger.LEVEL, "{} is leaving faction {}", this.player.getName().getString(), oldFaction.getRegisteredName()); + oldFaction.value().getPlayerCapability(player).ifPresent(c -> c.onLevelChanged(0, oldLevel)); } if (currentFaction != null) { - LOGGER.debug(LogUtil.FACTION, "{} has new faction level {} {}", this.player.getName().getString(), currentFaction.getID(), currentLevel); - currentFaction.getPlayerCapability(player).ifPresent(c -> c.onLevelChanged(currentLevel, Objects.equals(oldFaction, currentFaction) ? oldLevel : 0)); + LOGGER.debug(LogUtil.FACTION, "{} has new faction level {} {}", this.player.getName().getString(), currentFaction.getRegisteredName(), currentLevel); + currentFaction.value().getPlayerCapability(player).ifPresent(c -> c.onLevelChanged(currentLevel, Objects.equals(oldFaction, currentFaction) ? oldLevel : 0)); } - ScoreboardUtil.updateScoreboard(player, ScoreboardUtil.FACTION_CRITERIA, currentFaction == null ? 0 : currentFaction.getID().hashCode()); + ScoreboardUtil.updateScoreboard(player, ScoreboardUtil.FACTION_CRITERIA, currentFaction == null ? 0 : currentFaction.value().hashCode()); } private boolean setLordLevel(int level, boolean sync) { int oldLevel = this.currentLordLevel; - if (level > 0 && (currentFaction == null || currentLevel != currentFaction.getHighestReachableLevel() || level > currentFaction.getHighestLordLevel())) { + if (level > 0 && (currentFaction == null || currentLevel != currentFaction.value().getHighestReachableLevel() || level > currentFaction.value().getHighestLordLevel())) { return false; } if (level < this.currentLordLevel) { @@ -474,8 +509,8 @@ private void sync(boolean all) { private void updateCache() { player.refreshDisplayName(); VampirismPlayerAttributes atts = ((IVampirismPlayer) player).getVampAtts(); - atts.hunterLevel = this.currentFaction == VReference.HUNTER_FACTION ? this.currentLevel : 0; - atts.vampireLevel = this.currentFaction == VReference.VAMPIRE_FACTION ? this.currentLevel : 0; + atts.hunterLevel = getCurrentLevel(ModFactions.HUNTER); + atts.vampireLevel = getCurrentLevel(ModFactions.VAMPIRE); atts.lordLevel = this.currentLordLevel; atts.faction = this.currentFaction; } @@ -495,11 +530,11 @@ private void writeBoundActions(@NotNull CompoundTag nbt) { @Override public @NotNull CompoundTag serializeNBT(HolderLookup.@NotNull Provider provider) { CompoundTag nbt = new CompoundTag(); - if (currentFaction != null) { - nbt.putString("faction", currentFaction.getID().toString()); + Optional.ofNullable(this.currentFaction).flatMap(Holder::unwrapKey).map(ResourceKey::location).map(ResourceLocation::toString).ifPresent(faction -> { + nbt.putString("faction", faction); nbt.putInt("level", currentLevel); nbt.putInt("lord_level", currentLordLevel); - } + }); nbt.putString("title_gender", titleGender.name()); writeBoundActions(nbt); @@ -513,8 +548,8 @@ public void deserializeNBT(HolderLookup.@NotNull Provider provider, @NotNull Com if (currentFaction == null) { LOGGER.warn("Could not find faction {}. Did mods change?", nbt.getString("faction")); } else { - currentLevel = Math.min(nbt.getInt("level"), this.currentFaction.getHighestReachableLevel()); - currentLordLevel = Math.min(nbt.getInt("lord_level"), this.currentFaction.getHighestLordLevel()); + currentLevel = Math.min(nbt.getInt("level"), this.currentFaction.value().getHighestReachableLevel()); + currentLordLevel = Math.min(nbt.getInt("lord_level"), this.currentFaction.value().getHighestLordLevel()); notifyFaction(null, 0); } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/factions/FactionPredicate.java b/src/main/java/de/teamlapen/vampirism/entity/factions/FactionPredicate.java index ee4a3ed95c..f96167aea2 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/factions/FactionPredicate.java +++ b/src/main/java/de/teamlapen/vampirism/entity/factions/FactionPredicate.java @@ -1,79 +1,105 @@ package de.teamlapen.vampirism.entity.factions; import com.google.common.base.Predicate; -import de.teamlapen.vampirism.api.entity.factions.IDisguise; import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; -import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; +import de.teamlapen.vampirism.core.tags.ModFactionTags; +import net.minecraft.core.Holder; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** - * Predicate for faction related selection - */ -public class FactionPredicate implements Predicate { - private final @NotNull IFaction thisFaction; - private final boolean player; - private final boolean nonPlayer; - private final boolean neutralPlayer; - private final boolean ignoreDisguise; - /** - * If null, all other faction are seen as hostile - */ - @Nullable - private final IFaction otherFaction; - - /** - * Selects entities - * - * @param thisFaction The friendly faction - * @param player If players should be selected - * @param nonPlayer If non players should be selected - * @param neutralPlayer If neutral playsers should be selected - * @param ignoreDisguise If the disguise ability of players should be ignored. - * @param otherFaction If this is not null, only entities of this faction are selected. - */ - protected FactionPredicate(@NotNull IFaction thisFaction, boolean player, boolean nonPlayer, boolean neutralPlayer, boolean ignoreDisguise, @Nullable IFaction otherFaction) { - this.thisFaction = thisFaction; - this.player = player; - this.nonPlayer = nonPlayer; - this.neutralPlayer = neutralPlayer; - this.otherFaction = otherFaction; - this.ignoreDisguise = ignoreDisguise; - } +import java.util.Optional; - protected FactionPredicate(@NotNull Faction thisFaction, boolean player, boolean nonPlayer, boolean neutralPlayer, boolean ignoreDisguise) { - this(thisFaction, player, nonPlayer, neutralPlayer, ignoreDisguise, null); - } +public record FactionPredicate(Holder> sourceFaction, boolean player, boolean nonPlayer, boolean neutral, boolean ignoreDisguise, Optional>> targetFaction) implements Predicate { @Override public boolean apply(@Nullable LivingEntity input) { - if (input == null) return false; - if (nonPlayer && input instanceof IFactionEntity) { - IFaction other = ((IFactionEntity) input).getFaction(); - return !thisFaction.equals(other) && (otherFaction == null || otherFaction.equals(other)); - - } - if (player && input instanceof Player && input.isAlive()) { - return FactionPlayerHandler.getCurrentFactionPlayer((Player) input).map(fp -> { - IFaction f = fp.getDisguise().getViewedFaction(thisFaction, ignoreDisguise); - return (f != null || (thisFaction.isHostileTowardsNeutral() && neutralPlayer)) && !thisFaction.equals(f) && (otherFaction == null || otherFaction.equals(f)); - } - ).orElse(neutralPlayer); + switch (input) { + case null -> { + return false; + } + case IFactionEntity iFactionEntity when nonPlayer -> { + Holder> other = iFactionEntity.getFaction(); + return !sourceFaction.equals(other) && (targetFaction.isEmpty() || targetFaction.get().equals(other)); + } + case Player player1 when player && input.isAlive() -> { + return FactionPlayerHandler.getCurrentFactionPlayer(player1).map(fp -> { + @SuppressWarnings("rawtypes") + Holder f = fp.getDisguise().getViewedFaction(sourceFaction, ignoreDisguise); + //noinspection unchecked,deprecation,rawtypes + return (f != null || (((Holder) sourceFaction).is(ModFactionTags.HOSTILE_TOWARDS_NEUTRAL) && neutral)) && !sourceFaction.equals(f) && (targetFaction.isEmpty() || (f != null && targetFaction.get().is(f))); + } + ).orElse(neutral); + } + default -> { + } } return false; } - @Override - public @NotNull String toString() { - return "PredicateFaction{" + - "thisFaction=" + thisFaction + - ", player=" + player + - ", nonPlayer=" + nonPlayer + - ", neutralPlayer=" + neutralPlayer + - ", otherFaction=" + otherFaction + - '}'; + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + public static class Builder { + + private final Holder> sourceFaction; + private boolean player; + private boolean nonPlayer; + private boolean neutral; + private boolean ignoreDisguise; + private Optional>> targetFaction = Optional.empty(); + + public Builder(Holder> sourceFaction) { + this.sourceFaction = sourceFaction; + } + + public Builder player() { + this.player = true; + return this; + } + + public Builder player(boolean player) { + this.player = player; + return this; + } + + public Builder nonPlayer() { + this.nonPlayer = false; + return this; + } + + public Builder nonPlayer(boolean nonPlayer) { + this.nonPlayer = nonPlayer; + return this; + } + + public Builder neutral() { + this.neutral = true; + return this; + } + + public Builder neutral(boolean neutral) { + this.neutral = neutral; + return this; + } + + public Builder ignoreDisguise() { + this.ignoreDisguise = true; + return this; + } + + public Builder ignoreDisguise(boolean ignoreDisguise) { + this.ignoreDisguise = ignoreDisguise; + return this; + } + + public Builder targetFaction(Holder> targetFaction) { + this.targetFaction = Optional.ofNullable(targetFaction); + return this; + } + + public FactionPredicate build() { + return new FactionPredicate(sourceFaction, player, nonPlayer, neutral, ignoreDisguise, targetFaction); + } } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/factions/FactionRegistry.java b/src/main/java/de/teamlapen/vampirism/entity/factions/FactionRegistry.java index a8beee1d6a..56c9c39745 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/factions/FactionRegistry.java +++ b/src/main/java/de/teamlapen/vampirism/entity/factions/FactionRegistry.java @@ -10,9 +10,12 @@ import de.teamlapen.vampirism.api.entity.minion.IMinionEntity; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.items.IRefinementItem; +import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; +import de.teamlapen.vampirism.util.RegUtil; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextColor; @@ -33,6 +36,7 @@ import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.*; +import java.util.stream.Collectors; public class FactionRegistry implements IFactionRegistry { @@ -70,6 +74,12 @@ public void finish() { @Override @Nullable public IFaction getFaction(Entity entity) { + Holder> factionHolder = getFactionHolder(entity); + return factionHolder == null ? null : factionHolder.value(); + } + + @Override + public Holder> getFactionHolder(Entity entity) { if (entity instanceof IFactionEntity) { return ((IFactionEntity) entity).getFaction(); } else if (entity instanceof Player) { @@ -102,47 +112,31 @@ public PlayableFaction[] getPlayableFactions() { return playableFactions; } + @SuppressWarnings({"unchecked", "RedundantCast"}) + @Override + public List>> playableFactions() { + return ModRegistries.FACTIONS.holders().filter(s -> s.value() instanceof IPlayableFaction).map(s -> ((Holder>) (Object) s)).collect(Collectors.toList()); + } + @Override public Predicate getPredicate(@NotNull IFaction thisFaction, boolean ignoreDisguise) { return getPredicate(thisFaction, true, true, true, ignoreDisguise, null); } + public Predicate getPredicate(@NotNull Holder> thisFaction, boolean ignoreDisguise) { + return getPredicate(thisFaction, true, true, true, ignoreDisguise, null); + } + + @Override + public Predicate getPredicate(@NotNull Holder> thisFaction, boolean player, boolean mob, boolean neutralPlayer, boolean ignoreDisguise, @Nullable Holder> otherFaction) { + var hash = Objects.hash(thisFaction.unwrapKey().orElseThrow(), player, mob, neutralPlayer, ignoreDisguise, otherFaction == null ? null : otherFaction.unwrapKey().orElseThrow()); + return predicateMap.computeIfAbsent(hash, (k) -> new FactionPredicate.Builder(thisFaction).player().nonPlayer(mob).neutral(neutralPlayer).ignoreDisguise(ignoreDisguise).targetFaction(otherFaction).build()); + } + @Override public Predicate getPredicate(@NotNull IFaction thisFaction, boolean player, boolean mob, boolean neutralPlayer, boolean ignoreDisguise, @Nullable IFaction otherFaction) { - int key = 0; - if (otherFaction != null) { - int id = otherFaction.hashCode(); - if (id > 63) { - LOGGER.warn("Faction id over 64, predicates won't work"); - } - key |= ((id & 63) << 10); - } - if (player) { - key |= (1 << 9); - } - if (mob) { - key |= (1 << 8); - } - if (neutralPlayer) { - key |= (1 << 7); - } - if (ignoreDisguise) { - key |= (1 << 6); - } - int id = thisFaction.hashCode(); - if (id > 64) { - LOGGER.warn("Faction id over 64, predicates won't work"); - } - key |= id & 63; - Predicate predicate; - if (predicateMap.containsKey(key)) { - predicate = predicateMap.get(key); - } else { - predicate = new FactionPredicate(thisFaction, player, mob, neutralPlayer, ignoreDisguise, otherFaction); - predicateMap.put(key, predicate); - } - return predicate; + return getPredicate(RegUtil.holder(thisFaction), player, mob, neutralPlayer, ignoreDisguise, otherFaction == null ? null : RegUtil.holder(otherFaction)); } @ThreadSafeAPI @@ -285,6 +279,7 @@ public IPlayableFactionBuilder color(int color) { return (IPlayableFactionBuilder) super.color(color); } + @Deprecated @Override public IPlayableFactionBuilder hostileTowardsNeutral() { return (IPlayableFactionBuilder) super.hostileTowardsNeutral(); diff --git a/src/main/java/de/teamlapen/vampirism/entity/factions/PlayableFaction.java b/src/main/java/de/teamlapen/vampirism/entity/factions/PlayableFaction.java index c882c35019..50b2dbbff6 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/factions/PlayableFaction.java +++ b/src/main/java/de/teamlapen/vampirism/entity/factions/PlayableFaction.java @@ -52,6 +52,9 @@ public int getHighestReachableLevel() { return highestLevel; } + /** + * @deprecated use HasLordSkills tag instead + */ @Override public boolean hasLordSkills() { return this.hasLordSkills; diff --git a/src/main/java/de/teamlapen/vampirism/entity/minion/HunterMinionEntity.java b/src/main/java/de/teamlapen/vampirism/entity/minion/HunterMinionEntity.java index 3b2df68ec7..12745d9291 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/minion/HunterMinionEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/minion/HunterMinionEntity.java @@ -6,12 +6,14 @@ import de.teamlapen.vampirism.VampirismMod; import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; import de.teamlapen.vampirism.api.entity.hunter.IHunter; import de.teamlapen.vampirism.api.entity.hunter.IVampirismCrossbowUser; import de.teamlapen.vampirism.api.entity.minion.IMinionTask; import de.teamlapen.vampirism.api.items.IHunterCrossbow; import de.teamlapen.vampirism.config.BalanceMobProps; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.entity.VampirismEntity; import de.teamlapen.vampirism.entity.ai.goals.RangedHunterCrossbowAttackGoal; @@ -65,7 +67,7 @@ public class HunterMinionEntity extends MinionEntity type, Level world) { - super(type, world, VampirismAPI.factionRegistry().getPredicate(VReference.HUNTER_FACTION, true, true, false, false, null).or(e -> !(e instanceof IFactionEntity) && (e instanceof Enemy) && !(e instanceof Creeper))); + super(type, world, VampirismAPI.factionRegistry().getPredicate(ModFactions.HUNTER, true, true, false, false, null).or(e -> !(e instanceof IFactionEntity) && (e instanceof Enemy) && !(e instanceof Creeper))); } @Override @@ -151,7 +153,7 @@ protected void onMinionDataReceived(HolderLookup.Provider provider, @NotNull Hun protected InteractionResult mobInteract(@NotNull Player player, @NotNull InteractionHand hand) { if (!this.level().isClientSide() && isLord(player) && minionData != null) { ItemStack heldItem = player.getItemInHand(hand); - if (heldItem.getItem() instanceof MinionUpgradeItem && ((MinionUpgradeItem) heldItem.getItem()).getFaction() == this.getFaction()) { + if (heldItem.getItem() instanceof MinionUpgradeItem && IFaction.is(((MinionUpgradeItem) heldItem.getItem()).getFaction(), this.getFaction())) { if (this.minionData.level + 1 >= ((MinionUpgradeItem) heldItem.getItem()).getMinLevel() && this.minionData.level + 1 <= ((MinionUpgradeItem) heldItem.getItem()).getMaxLevel()) { this.minionData.level++; if (!player.getAbilities().instabuild) heldItem.shrink(1); @@ -295,7 +297,7 @@ public void deserializeNBT(HolderLookup.@NotNull Provider provider, @NotNull Com @Override public @NotNull MutableComponent getFormattedName() { - return super.getFormattedName().withStyle(style -> style.withColor((VReference.HUNTER_FACTION.getChatColor()))); + return super.getFormattedName().withStyle(style -> style.withColor((ModFactions.HUNTER.get().getChatColor()))); } public int getHealthLevel() { diff --git a/src/main/java/de/teamlapen/vampirism/entity/minion/VampireMinionEntity.java b/src/main/java/de/teamlapen/vampirism/entity/minion/VampireMinionEntity.java index 59f9023cb8..29230a463f 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/minion/VampireMinionEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/minion/VampireMinionEntity.java @@ -7,6 +7,7 @@ import de.teamlapen.vampirism.api.EnumStrength; import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IFactionEntity; import de.teamlapen.vampirism.api.entity.minion.IMinionTask; import de.teamlapen.vampirism.api.entity.player.vampire.IDrinkBloodContext; @@ -15,6 +16,7 @@ import de.teamlapen.vampirism.config.BalanceMobProps; import de.teamlapen.vampirism.core.ModAttributes; import de.teamlapen.vampirism.core.ModEffects; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.entity.VampirismEntity; import de.teamlapen.vampirism.entity.ai.goals.FleeSunVampireGoal; import de.teamlapen.vampirism.entity.ai.goals.RestrictSunVampireGoal; @@ -65,7 +67,7 @@ public class VampireMinionEntity extends MinionEntity type, Level world) { - super(type, world, VampirismAPI.factionRegistry().getPredicate(VReference.VAMPIRE_FACTION, true, true, true, false, null).or(e -> !(e instanceof IFactionEntity) && e instanceof Enemy && !(e instanceof Zombie) && !(e instanceof Skeleton) && !(e instanceof Creeper))); + super(type, world, VampirismAPI.factionRegistry().getPredicate(ModFactions.VAMPIRE, true, true, true, false, null).or(e -> !(e instanceof IFactionEntity) && e instanceof Enemy && !(e instanceof Zombie) && !(e instanceof Skeleton) && !(e instanceof Creeper))); } @Override @@ -206,7 +208,7 @@ protected boolean canConsume(@NotNull ItemStack stack) { protected InteractionResult mobInteract(@NotNull Player player, @NotNull InteractionHand hand) { if (!this.level().isClientSide() && isLord(player) && minionData != null) { ItemStack heldItem = player.getItemInHand(hand); - if (heldItem.getItem() instanceof MinionUpgradeItem && ((MinionUpgradeItem) heldItem.getItem()).getFaction() == this.getFaction()) { + if (heldItem.getItem() instanceof MinionUpgradeItem && IFaction.is(((MinionUpgradeItem) heldItem.getItem()).getFaction(), this.getFaction())) { if (this.minionData.level + 1 >= ((MinionUpgradeItem) heldItem.getItem()).getMinLevel() && this.minionData.level + 1 <= ((MinionUpgradeItem) heldItem.getItem()).getMaxLevel()) { this.minionData.level++; if (!player.getAbilities().instabuild) heldItem.shrink(1); @@ -294,7 +296,7 @@ public void deserializeNBT(HolderLookup.@NotNull Provider provider, @NotNull Com @Override public @NotNull MutableComponent getFormattedName() { - return super.getFormattedName().withStyle(style -> style.withColor(VReference.VAMPIRE_FACTION.getChatColor())); + return super.getFormattedName().withStyle(style -> style.withColor(ModFactions.VAMPIRE.value().getChatColor())); } public int getHealthLevel() { diff --git a/src/main/java/de/teamlapen/vampirism/entity/minion/management/CollectResourcesTask.java b/src/main/java/de/teamlapen/vampirism/entity/minion/management/CollectResourcesTask.java index abea0636a8..879145dee6 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/minion/management/CollectResourcesTask.java +++ b/src/main/java/de/teamlapen/vampirism/entity/minion/management/CollectResourcesTask.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.UUID; import java.util.function.Function; -import java.util.function.Supplier; import java.util.stream.Stream; import static de.teamlapen.vampirism.entity.minion.management.CollectResourcesTask.Desc; @@ -41,13 +40,13 @@ public class CollectResourcesTask extends DefaultMinionTas private final List> resources; private final RandomSource rng = RandomSource.create(); @Nullable - private final IFaction faction; + private final Holder> faction; /** * @param faction If given, only available to this faction */ - public CollectResourcesTask(@Nullable IFaction faction, @NotNull Function coolDownSupplier, @NotNull List> resources, @NotNull Holder> requiredSkill) { + public CollectResourcesTask(@Nullable Holder> faction, @NotNull Function coolDownSupplier, @NotNull List> resources, @NotNull Holder> requiredSkill) { super(requiredSkill); this.coolDownSupplier = coolDownSupplier; this.resources = resources; @@ -72,8 +71,8 @@ public void deactivateTask(Desc desc) { } @Override - public boolean isAvailable(@NotNull IPlayableFaction faction, @Nullable ILordPlayer player) { - return (this.faction == null || this.faction == faction) && isRequiredSkillUnlocked(faction, player); + public boolean isAvailable(@NotNull Holder> faction, @Nullable ILordPlayer player) { + return (this.faction == null || IFaction.is(this.faction, faction)) && isRequiredSkillUnlocked(faction, player); } @@ -99,7 +98,7 @@ public void tickBackground(@NotNull Desc desc, @NotNull Q data) { } @Override - public @Nullable IFaction getFaction() { + public @Nullable Holder> getFaction() { return this.faction; } diff --git a/src/main/java/de/teamlapen/vampirism/entity/minion/management/DefaultMinionTask.java b/src/main/java/de/teamlapen/vampirism/entity/minion/management/DefaultMinionTask.java index 921c1ed4b4..23585f5b2a 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/minion/management/DefaultMinionTask.java +++ b/src/main/java/de/teamlapen/vampirism/entity/minion/management/DefaultMinionTask.java @@ -53,7 +53,7 @@ protected void triggerAdvancements(Player player) { } } - public boolean isRequiredSkillUnlocked(@NotNull IPlayableFaction faction, @Nullable ILordPlayer player) { - return this.requiredSkill == null || player == null || faction.getPlayerCapability(player.getPlayer()).map(a -> a.getSkillHandler().isSkillEnabled(this.requiredSkill)).orElse(false); + public boolean isRequiredSkillUnlocked(@NotNull Holder> faction, @Nullable ILordPlayer player) { + return this.requiredSkill == null || player == null || faction.value().getPlayerCapability(player.getPlayer()).map(a -> a.getSkillHandler().isSkillEnabled(this.requiredSkill)).orElse(false); } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/minion/management/MinionTasks.java b/src/main/java/de/teamlapen/vampirism/entity/minion/management/MinionTasks.java index e1302645f1..29efb332b3 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/minion/management/MinionTasks.java +++ b/src/main/java/de/teamlapen/vampirism/entity/minion/management/MinionTasks.java @@ -6,6 +6,7 @@ import de.teamlapen.vampirism.api.VampirismRegistries; import de.teamlapen.vampirism.api.entity.minion.IMinionTask; import de.teamlapen.vampirism.config.VampirismConfig; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.entity.minion.HunterMinionEntity; import de.teamlapen.vampirism.entity.minion.VampireMinionEntity; @@ -28,8 +29,8 @@ public class MinionTasks { public static final DeferredHolder,StayTask> STAY = MINION_TASKS.register("stay", StayTask::new); public static final DeferredHolder,DefendAreaTask> DEFEND_AREA = MINION_TASKS.register("defend_area", DefendAreaTask::new); public static final DeferredHolder,SimpleMinionTask> FOLLOW_LORD = MINION_TASKS.register("follow_lord", SimpleMinionTask::new); - public static final DeferredHolder,CollectResourcesTask> COLLECT_HUNTER_ITEMS = MINION_TASKS.register("collect_hunter_items", () -> new CollectResourcesTask<>(VReference.HUNTER_FACTION, data -> (int) (VampirismConfig.BALANCE.miResourceCooldown.get() * (1f - data.getResourceEfficiencyLevel() / HunterMinionEntity.HunterMinionData.MAX_LEVEL_RESOURCES * 0.4f)), Arrays.asList(WeightedEntry.wrap(new ItemStack(ModItems.GARLIC_BREAD.get()), 10), WeightedEntry.wrap(new ItemStack(Items.IRON_NUGGET, 19), 25), WeightedEntry.wrap(new ItemStack(Items.GOLD_NUGGET, 7), 10), WeightedEntry.wrap(new ItemStack(ModItems.ITEM_GARLIC.get(), 2), 15), WeightedEntry.wrap(new ItemStack(Items.COAL, 5), 20)), HunterSkills.MINION_COLLECT)); - public static final DeferredHolder,CollectResourcesTask> COLLECT_BLOOD = MINION_TASKS.register("collect_blood", () -> new CollectResourcesTask<>(VReference.VAMPIRE_FACTION, data -> VampirismConfig.BALANCE.miResourceCooldown.get(), Arrays.asList(WeightedEntry.wrap(BloodBottleItem.getStackWithDamage(BloodBottleItem.AMOUNT), 20), WeightedEntry.wrap(new ItemStack(ModItems.HUMAN_HEART.get()), 5), WeightedEntry.wrap(new ItemStack(Items.IRON_NUGGET, 12), 12), WeightedEntry.wrap(new ItemStack(Items.GOLD_NUGGET, 6), 10)), VampireSkills.MINION_COLLECT)); + public static final DeferredHolder,CollectResourcesTask> COLLECT_HUNTER_ITEMS = MINION_TASKS.register("collect_hunter_items", () -> new CollectResourcesTask<>(ModFactions.HUNTER, data -> (int) (VampirismConfig.BALANCE.miResourceCooldown.get() * (1f - data.getResourceEfficiencyLevel() / HunterMinionEntity.HunterMinionData.MAX_LEVEL_RESOURCES * 0.4f)), Arrays.asList(WeightedEntry.wrap(new ItemStack(ModItems.GARLIC_BREAD.get()), 10), WeightedEntry.wrap(new ItemStack(Items.IRON_NUGGET, 19), 25), WeightedEntry.wrap(new ItemStack(Items.GOLD_NUGGET, 7), 10), WeightedEntry.wrap(new ItemStack(ModItems.ITEM_GARLIC.get(), 2), 15), WeightedEntry.wrap(new ItemStack(Items.COAL, 5), 20)), HunterSkills.MINION_COLLECT)); + public static final DeferredHolder,CollectResourcesTask> COLLECT_BLOOD = MINION_TASKS.register("collect_blood", () -> new CollectResourcesTask<>(ModFactions.VAMPIRE, data -> VampirismConfig.BALANCE.miResourceCooldown.get(), Arrays.asList(WeightedEntry.wrap(BloodBottleItem.getStackWithDamage(BloodBottleItem.AMOUNT), 20), WeightedEntry.wrap(new ItemStack(ModItems.HUMAN_HEART.get()), 5), WeightedEntry.wrap(new ItemStack(Items.IRON_NUGGET, 12), 12), WeightedEntry.wrap(new ItemStack(Items.GOLD_NUGGET, 6), 10)), VampireSkills.MINION_COLLECT)); public static final DeferredHolder,SimpleMinionTask> NOTHING = MINION_TASKS.register("nothing", NothingTask::new); public static final DeferredHolder,SimpleMinionTask> PROTECT_LORD = MINION_TASKS.register("protect_lord", SimpleMinionTask::new); diff --git a/src/main/java/de/teamlapen/vampirism/entity/minion/management/NothingTask.java b/src/main/java/de/teamlapen/vampirism/entity/minion/management/NothingTask.java index 2448b18aa1..c8cc43a1b5 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/minion/management/NothingTask.java +++ b/src/main/java/de/teamlapen/vampirism/entity/minion/management/NothingTask.java @@ -4,13 +4,14 @@ import de.teamlapen.vampirism.api.entity.minion.IMinionTask; import de.teamlapen.vampirism.api.entity.minion.INoGlobalCommandTask; import de.teamlapen.vampirism.api.entity.player.ILordPlayer; +import net.minecraft.core.Holder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class NothingTask extends SimpleMinionTask implements INoGlobalCommandTask, MinionData> { @Override - public boolean isAvailable(@NotNull IPlayableFaction faction, @Nullable ILordPlayer player) { + public boolean isAvailable(@NotNull Holder> faction, @Nullable ILordPlayer player) { return false; } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/minion/management/PlayerMinionController.java b/src/main/java/de/teamlapen/vampirism/entity/minion/management/PlayerMinionController.java index 1938b9b803..f462343263 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/minion/management/PlayerMinionController.java +++ b/src/main/java/de/teamlapen/vampirism/entity/minion/management/PlayerMinionController.java @@ -14,6 +14,7 @@ import de.teamlapen.vampirism.entity.player.lord.skills.LordSkills; import de.teamlapen.vampirism.util.Helper; import de.teamlapen.vampirism.util.RegUtil; +import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; @@ -68,10 +69,7 @@ public class PlayerMinionController implements INBTSerializable { private final static Logger LOGGER = LogManager.getLogger(); public static @NotNull List> getAvailableTasks(@NotNull ILordPlayer player) { - if (player.getLordFaction() == null) { - return new ArrayList<>(); - } - return RegUtil.values(ModRegistries.MINION_TASKS).stream().filter(t -> t.isAvailable(player.getLordFaction(), player)).collect(Collectors.toList()); + return player.getLordFaction().stream().flatMap(s -> RegUtil.values(ModRegistries.MINION_TASKS).stream().filter(t -> t.isAvailable(s.value(), player))).collect(Collectors.toList()); } private final Random rng = new Random(); @@ -81,7 +79,7 @@ public class PlayerMinionController implements INBTSerializable { private final UUID lordID; private int maxMinions; @Nullable - private IPlayableFaction faction; + private Holder> faction; @NotNull private MinionInfo @NotNull [] minions = new MinionInfo[0]; @SuppressWarnings("unchecked") @@ -204,7 +202,7 @@ public MinionEntity createMinionEntityAtPlayer(int id, @NotNull Player p) { LOGGER.warn("Cannot create minion because type does not exist"); } else { return Helper.createEntity(type, p.getCommandSenderWorld()).map(m -> { - if (faction == null || faction.isEntityOfFaction(m)) { + if (faction == null || faction.value().isEntityOfFaction(m)) { LOGGER.warn("Specified minion entity is of wrong faction. This: {} Minion: {}", faction, m.getFaction()); m.discard(); return null; @@ -243,12 +241,13 @@ public int createNewMinionSlot(@NotNull MinionData data, EntityType f = VampirismAPI.factionRegistry().getFactionByID(new ResourceLocation(nbt.getString("faction"))); - if (!(f instanceof IPlayableFaction)) { + //noinspection unchecked + Optional>> faction = ModRegistries.FACTIONS.getHolder(new ResourceLocation(nbt.getString("faction"))).filter(s -> s.value() instanceof IPlayableFaction).map(s -> (Holder>) (Object) s); + if (faction.isEmpty()) { this.maxMinions = 0; return; } - this.faction = (IPlayableFaction) f; + this.faction = faction.get(); this.maxMinions = nbt.getInt("max_minions"); ListTag data = nbt.getList("data", 10); MinionInfo[] infos = new MinionInfo[data.size()]; @@ -369,9 +368,9 @@ public void markDeadAndReleaseMinionSlot(int id, int token) { if (i != null) { i.checkin(); i.deathCooldown = 20 * VampirismConfig.BALANCE.miDeathRecoveryTime.get(); - getLord().flatMap(player -> player.getLordFaction().getPlayerCapability(player.getPlayer()).map(IFactionPlayer::getSkillHandler)).ifPresent(s -> { + getLord().flatMap(player -> player.getLordFaction().map(Holder::value).flatMap(s -> s.getPlayerCapability(player.getPlayer())).map(IFactionPlayer::getSkillHandler)).ifPresent(s -> { if (s.isSkillEnabled(LordSkills.MINION_RECOVERY)) { - i.deathCooldown *= (int) 0.8; + i.deathCooldown = (int) (i.deathCooldown * 0.8); } }); if (id < minionTokens.length) { @@ -414,7 +413,7 @@ public boolean recallMinion(int id) { CompoundTag nbt = new CompoundTag(); nbt.putInt("max_minions", maxMinions); if (faction != null) { - nbt.putString("faction", faction.getID().toString()); + nbt.putString("faction", faction.unwrapKey().map(ResourceKey::location).map(ResourceLocation::toString).orElseThrow()); } ListTag data = new ListTag(); for (MinionInfo i : minions) { @@ -429,7 +428,7 @@ public boolean recallMinion(int id) { return nbt; } - public void setMaxMinions(@Nullable IPlayableFaction faction, int newCount) { + public void setMaxMinions(@Nullable Holder> faction, int newCount) { assert newCount >= 0; if (this.faction != null && faction != this.faction) { LOGGER.warn("Changing player minion controller faction"); diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/FactionBasePlayer.java b/src/main/java/de/teamlapen/vampirism/entity/player/FactionBasePlayer.java index e03d901d81..662491bdf2 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/FactionBasePlayer.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/FactionBasePlayer.java @@ -9,6 +9,9 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; +import de.teamlapen.vampirism.entity.factions.Faction; +import de.teamlapen.vampirism.entity.factions.PlayableFaction; +import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; @@ -179,24 +182,24 @@ public void deserializeUpdateNBT(HolderLookup.@NotNull Provider provider, @NotNu private static class Disguise implements IDisguise { - private final IPlayableFaction faction; + private final Holder> faction; - public Disguise(IPlayableFaction faction) { + public Disguise(Holder> faction) { this.faction = faction; } @Override - public @NotNull IPlayableFaction getOriginalFaction() { + public @NotNull Holder> getOriginalFaction() { return this.faction; } @Override - public @Nullable IPlayableFaction getViewedFaction(@Nullable IFaction viewerFaction) { + public @Nullable Holder> getViewedFaction(@Nullable Holder> viewerFaction) { return this.faction; } @Override - public void disguiseAs(@Nullable IPlayableFaction faction) { + public void disguiseAs(@Nullable Holder> faction) { } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/ModPlayerEventHandler.java b/src/main/java/de/teamlapen/vampirism/entity/player/ModPlayerEventHandler.java index e96dd3b448..3aee276fd8 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/ModPlayerEventHandler.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/ModPlayerEventHandler.java @@ -420,13 +420,13 @@ public void onPlayerName(PlayerEvent.@NotNull NameFormat event) { if (VampirismConfig.SERVER.factionColorInChat.get()) { FactionPlayerHandler handler = FactionPlayerHandler.get(event.getEntity()); handler.getCurrentFactionPlayer().ifPresent(fp -> { - IFaction f = fp.getDisguise().getViewedFaction(Optional.ofNullable(VampirismMod.proxy.getClientPlayer()).map(FactionPlayerHandler::get).map(FactionPlayerHandler::getCurrentFaction).orElse(null)); + Holder> f = fp.getDisguise().getViewedFaction(Optional.ofNullable(VampirismMod.proxy.getClientPlayer()).map(FactionPlayerHandler::get).map(FactionPlayerHandler::getFaction).orElse(null)); if (f != null) { MutableComponent displayName; displayName = Optional.of(handler).filter(h -> h.getLordLevel() > 0).filter(x -> VampirismConfig.SERVER.lordPrefixInChat.get()).map(FactionPlayerHandler::getLordTitle) .map(x -> Component.literal("[").append(x).append("] ").append(event.getDisplayname())) .orElseGet(() -> event.getDisplayname().copy()); - event.setDisplayname(displayName.withStyle(style -> style.withColor((f.getChatColor())))); + event.setDisplayname(displayName.withStyle(style -> style.withColor((f.value().getChatColor())))); } }); } @@ -468,7 +468,7 @@ private boolean checkItemUsePerm(@NotNull ItemStack stack, @NotNull Player playe if (!stack.isEmpty() && stack.getItem() instanceof IFactionExclusiveItem factionItem) { if (!player.isAlive()) return false; FactionPlayerHandler handler = FactionPlayerHandler.get(player); - IFaction usingFaction = factionItem.getExclusiveFaction(stack); + Holder> usingFaction = factionItem.getExclusiveFaction(stack); if (usingFaction != null && !handler.isInFaction(usingFaction) && checkExceptions(player, handler.getCurrentFaction(), stack)) { if (message) { player.displayClientMessage(Component.translatable("text.vampirism.can_not_be_used_faction"), true); @@ -506,8 +506,8 @@ private boolean checkExceptions(@NotNull Player player, IPlayableFaction curr public void onPlayerAttackCritical(@NotNull CriticalHitEvent event) { ItemStack stack = event.getEntity().getMainHandItem(); if (!stack.isEmpty() && stack.getItem() instanceof IFactionSlayerItem item) { - IFaction faction = VampirismAPI.factionRegistry().getFaction(event.getTarget()); - if (faction != null && faction.equals(item.getSlayedFaction())) { + Holder> faction = VampirismAPI.factionRegistry().getFactionHolder(event.getTarget()); + if (faction != null && IFaction.is(faction, item.getSlayedFaction())) { event.setResult(Event.Result.ALLOW); event.setDamageModifier(event.getDamageModifier() + (event.getOldDamageModifier() * (item.getDamageMultiplierForFaction(stack) - 1))); } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/TaskManager.java b/src/main/java/de/teamlapen/vampirism/entity/player/TaskManager.java index 79ea931c6b..729546bada 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/TaskManager.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/TaskManager.java @@ -7,6 +7,7 @@ import de.teamlapen.lib.lib.storage.ISavable; import de.teamlapen.lib.lib.util.UtilLib; import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.task.*; @@ -51,7 +52,7 @@ public class TaskManager implements ITaskManager, ISavable { private static final UUID UNIQUE_TASKS = UUID.fromString("e2c6068a-8f0e-4d5b-822a-38ad6ecf98c9"); @NotNull - private final IPlayableFaction faction; + private final Holder> faction; @NotNull private final ServerPlayer player; @NotNull @@ -63,7 +64,7 @@ public class TaskManager implements ITaskManager, ISavable { private final Registry registry; - public TaskManager(@NotNull ServerPlayer player, @NotNull IFactionPlayer factionPlayer, @NotNull IPlayableFaction faction) { + public TaskManager(@NotNull ServerPlayer player, @NotNull IFactionPlayer factionPlayer, @NotNull Holder> faction) { this.faction = faction; this.player = player; this.factionPlayer = factionPlayer; @@ -446,7 +447,7 @@ private boolean matchesFaction(@NotNull ResourceKey task) { } private boolean matchesFaction(@NotNull Holder task) { - return !task.is(ModTaskTags.HAS_FACTION) || this.faction.getTag(VampirismRegistries.Keys.TASK).map(task::is).orElse(false); + return !task.is(ModTaskTags.HAS_FACTION) || this.faction.value().getTag(VampirismRegistries.Keys.TASK).map(task::is).orElse(false); } /** diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/VampirismPlayerAttributes.java b/src/main/java/de/teamlapen/vampirism/entity/player/VampirismPlayerAttributes.java index 98a689cdb2..efc597c343 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/VampirismPlayerAttributes.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/VampirismPlayerAttributes.java @@ -5,6 +5,7 @@ import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.entity.player.hunter.HunterPlayerSpecialAttribute; import de.teamlapen.vampirism.entity.player.vampire.VampirePlayerSpecialAttributes; +import net.minecraft.core.Holder; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -25,7 +26,7 @@ public static VampirismPlayerAttributes get(@NotNull Player player) { public int hunterLevel = 0; @Nullable @Deprecated - public IPlayableFaction faction = null; + public Holder> faction = null; public int lordLevel = 0; public @NotNull HunterPlayerSpecialAttribute getHuntSpecial() { @@ -36,8 +37,8 @@ public static VampirismPlayerAttributes get(@NotNull Player player) { return vampSpecial; } - @SuppressWarnings("unchecked") - public > IPlayableFaction faction() { - return (IPlayableFaction) faction; + @SuppressWarnings({"RedundantCast", "unchecked"}) + public > Holder> faction() { + return ((Holder>) (Object) faction); } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/actions/ActionHandler.java b/src/main/java/de/teamlapen/vampirism/entity/player/actions/ActionHandler.java index 04b8b8aec4..9c0fa87ce0 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/actions/ActionHandler.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/actions/ActionHandler.java @@ -8,6 +8,7 @@ import de.teamlapen.vampirism.api.entity.player.actions.IActionHandler; import de.teamlapen.vampirism.api.entity.player.actions.ILastingAction; import de.teamlapen.vampirism.api.event.ActionEvent; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.core.ModStats; import de.teamlapen.vampirism.util.Permissions; @@ -83,7 +84,7 @@ public class ActionHandler> implements IActionHandle public ActionHandler(@NotNull T player) { this.player = player; - List> actions = VampirismAPI.actionManager().getActionsForFaction(player.getFaction()); + List>> actions = VampirismAPI.actionManager().getActionsForFaction(player.getFaction()); cooldownTimers = new Object2IntOpenHashMap<>(actions.size(), 0.9f); activeTimers = new Object2IntOpenHashMap<>(actions.size(), 0.9f); diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/actions/ActionManager.java b/src/main/java/de/teamlapen/vampirism/entity/player/actions/ActionManager.java index 1b49fe9c4e..5027eb3eb0 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/actions/ActionManager.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/actions/ActionManager.java @@ -1,11 +1,13 @@ package de.teamlapen.vampirism.entity.player.actions; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.actions.IAction; import de.teamlapen.vampirism.api.entity.player.actions.IActionManager; import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.util.RegUtil; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import org.jetbrains.annotations.NotNull; @@ -17,10 +19,18 @@ public class ActionManager implements IActionManager { @SuppressWarnings("unchecked") @Override - public > @NotNull List> getActionsForFaction(IPlayableFaction faction) { + @Deprecated + public > @NotNull List> getActionsForFaction(@NotNull IPlayableFaction faction) { return RegUtil.values(ModRegistries.ACTIONS).stream().filter(action -> action.getFaction().map(f -> f == faction).orElse(true)).map(action -> (IAction) action).collect(Collectors.toList()); } + @Override + public @NotNull List>> getActionsForFaction(@NotNull Holder> faction) { + //noinspection RedundantCast,unchecked + return ModRegistries.ACTIONS.holders().filter(action -> IFaction.is(faction, action.value().factions())).map(action -> (Holder>) (Object) action).collect(Collectors.toList()); + } + + @Deprecated @Override public Registry> getRegistry() { return ModRegistries.ACTIONS; diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/hunter/HunterPlayer.java b/src/main/java/de/teamlapen/vampirism/entity/player/hunter/HunterPlayer.java index 5c51912382..3dbf530563 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/hunter/HunterPlayer.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/hunter/HunterPlayer.java @@ -18,6 +18,7 @@ import de.teamlapen.vampirism.core.ModAdvancements; import de.teamlapen.vampirism.core.ModAttachments; import de.teamlapen.vampirism.core.ModEffects; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.tags.ModItemTags; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; import de.teamlapen.vampirism.entity.minion.HunterMinionEntity; @@ -34,6 +35,7 @@ import de.teamlapen.vampirism.util.OilUtils; import de.teamlapen.vampirism.util.ScoreboardUtil; import de.teamlapen.vampirism.world.MinionWorldData; +import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceKey; @@ -82,7 +84,7 @@ public class HunterPlayer extends FactionBasePlayer implements IH public HunterPlayer(Player player) { super(player); actionHandler = new ActionHandler<>(this); - skillHandler = new SkillHandler<>(this, VReference.HUNTER_FACTION); + skillHandler = new SkillHandler<>(this, ModFactions.HUNTER); this.disguise = new Disguise(); } @@ -312,17 +314,17 @@ public String nbtKey() { public class Disguise implements IDisguise { @Override - public @NotNull IPlayableFaction getOriginalFaction() { + public @NotNull Holder> getOriginalFaction() { return getFaction(); } @Override - public @Nullable IPlayableFaction getViewedFaction(@Nullable IFaction viewerFaction) { - return player.hasEffect(ModEffects.DISGUISE_AS_VAMPIRE) ? VReference.VAMPIRE_FACTION : getOriginalFaction(); + public @Nullable Holder> getViewedFaction(@Nullable Holder> viewerFaction) { + return player.hasEffect(ModEffects.DISGUISE_AS_VAMPIRE) ? ModFactions.VAMPIRE : getOriginalFaction(); } @Override - public void disguiseAs(@Nullable IPlayableFaction faction) { + public void disguiseAs(@Nullable Holder> faction) { } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/hunter/actions/AwarenessHunterAction.java b/src/main/java/de/teamlapen/vampirism/entity/player/hunter/actions/AwarenessHunterAction.java index b7d1739d54..a3e07e213b 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/hunter/actions/AwarenessHunterAction.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/hunter/actions/AwarenessHunterAction.java @@ -6,6 +6,7 @@ import de.teamlapen.vampirism.api.entity.player.hunter.DefaultHunterAction; import de.teamlapen.vampirism.api.entity.player.hunter.IHunterPlayer; import de.teamlapen.vampirism.config.VampirismConfig; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.entity.player.hunter.HunterPlayer; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.targeting.TargetingConditions; @@ -15,7 +16,7 @@ public class AwarenessHunterAction extends DefaultHunterAction implements ILastingAction { - private final TargetingConditions vampirePredicate = TargetingConditions.forNonCombat().selector(VampirismAPI.factionRegistry().getPredicate(VReference.HUNTER_FACTION, true, true, false, false, VReference.VAMPIRE_FACTION)); + private final TargetingConditions vampirePredicate = TargetingConditions.forNonCombat().selector(VampirismAPI.factionRegistry().getPredicate(ModFactions.HUNTER, true, true, false, false, ModFactions.VAMPIRE)); public AwarenessHunterAction() { super(); diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/hunter/actions/HunterActions.java b/src/main/java/de/teamlapen/vampirism/entity/player/hunter/actions/HunterActions.java index 6eb2ee17d9..4ee507cb66 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/hunter/actions/HunterActions.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/hunter/actions/HunterActions.java @@ -1,15 +1,11 @@ package de.teamlapen.vampirism.entity.player.hunter.actions; import de.teamlapen.vampirism.REFERENCE; -import de.teamlapen.vampirism.api.DeferredAction; -import de.teamlapen.vampirism.api.DeferredActionRegister; -import de.teamlapen.vampirism.api.VampirismRegistries; -import de.teamlapen.vampirism.api.entity.player.actions.IAction; +import de.teamlapen.vampirism.api.registries.DeferredAction; +import de.teamlapen.vampirism.api.registries.DeferredActionRegister; import de.teamlapen.vampirism.api.entity.player.actions.ILastingAction; import de.teamlapen.vampirism.api.entity.player.hunter.IHunterPlayer; import net.neoforged.bus.api.IEventBus; -import net.neoforged.neoforge.registries.DeferredHolder; -import net.neoforged.neoforge.registries.DeferredRegister; import org.jetbrains.annotations.ApiStatus; /** diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/hunter/skills/HunterSkills.java b/src/main/java/de/teamlapen/vampirism/entity/player/hunter/skills/HunterSkills.java index cd673dd6ad..6d9ea11ab1 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/hunter/skills/HunterSkills.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/hunter/skills/HunterSkills.java @@ -9,6 +9,7 @@ import de.teamlapen.vampirism.api.entity.player.hunter.IHunterPlayer; import de.teamlapen.vampirism.api.entity.player.skills.ISkill; import de.teamlapen.vampirism.config.VampirismConfig; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.entity.player.hunter.actions.HunterActions; import de.teamlapen.vampirism.entity.player.lord.skills.LordSkills; @@ -38,8 +39,8 @@ public class HunterSkills { public static final DeferredRegister> SKILLS = DeferredRegister.create(VampirismRegistries.Keys.SKILL, REFERENCE.MODID); - public static final DeferredHolder, ISkill> LEVEL_ROOT = SKILLS.register(VReference.HUNTER_FACTION.getID().getPath(), () -> new VampirismSkill.SimpleHunterSkill(0, false)); - public static final DeferredHolder, ISkill> LORD_ROOT = SKILLS.register(VReference.HUNTER_FACTION.getID().withSuffix("_lord").getPath(), () -> new VampirismSkill.SimpleHunterSkill(0, false)); + public static final DeferredHolder, ISkill> LEVEL_ROOT = SKILLS.register(ModFactions.HUNTER.getKey().location().getPath(), () -> new VampirismSkill.SimpleHunterSkill(0, false)); + public static final DeferredHolder, ISkill> LORD_ROOT = SKILLS.register(ModFactions.HUNTER.getKey().location().withSuffix("_lord").getPath(), () -> new VampirismSkill.SimpleHunterSkill(0, false)); public static final DeferredHolder, ISkill> BASIC_ALCHEMY = SKILLS.register("basic_alchemy", () -> new VampirismSkill.SimpleHunterSkill(2, true)); public static final DeferredHolder, ISkill> GARLIC_DIFFUSER = SKILLS.register("garlic_diffuser", () -> new VampirismSkill.SimpleHunterSkill(2, true)); public static final DeferredHolder, ISkill> GARLIC_DIFFUSER_IMPROVED = SKILLS.register("garlic_diffuser_improved", () -> new VampirismSkill.SimpleHunterSkill(2, true)); @@ -169,8 +170,8 @@ private static ResourceKey tree(String path) { public static void createSkillTrees(BootstrapContext context) { HolderGetter lookup = context.lookup(VampirismRegistries.Keys.SKILL_NODE); - context.register(LEVEL, new SkillTree(VReference.HUNTER_FACTION, EntityPredicate.Builder.entity().subPredicate(FactionSubPredicate.faction(VReference.HUNTER_FACTION)).build(), new ItemStack(ModItems.VAMPIRE_BOOK.get()), Component.translatable("text.vampirism.skills.level"))); - context.register(LORD, new SkillTree(VReference.HUNTER_FACTION, EntityPredicate.Builder.entity().subPredicate(FactionSubPredicate.lord(VReference.HUNTER_FACTION)).build(), new ItemStack(ModItems.HUNTER_MINION_EQUIPMENT.get()), Component.translatable("text.vampirism.skills.lord"))); + context.register(LEVEL, new SkillTree(ModFactions.HUNTER, EntityPredicate.Builder.entity().subPredicate(FactionSubPredicate.faction(ModFactions.HUNTER)).build(), new ItemStack(ModItems.VAMPIRE_BOOK.get()), Component.translatable("text.vampirism.skills.level"))); + context.register(LORD, new SkillTree(ModFactions.HUNTER, EntityPredicate.Builder.entity().subPredicate(FactionSubPredicate.lord(ModFactions.HUNTER)).build(), new ItemStack(ModItems.HUNTER_MINION_EQUIPMENT.get()), Component.translatable("text.vampirism.skills.lord"))); } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/lord/actions/LordActions.java b/src/main/java/de/teamlapen/vampirism/entity/player/lord/actions/LordActions.java index 79811cf848..650b9c42cd 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/lord/actions/LordActions.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/lord/actions/LordActions.java @@ -1,15 +1,11 @@ package de.teamlapen.vampirism.entity.player.lord.actions; import de.teamlapen.vampirism.REFERENCE; -import de.teamlapen.vampirism.api.DeferredAction; -import de.teamlapen.vampirism.api.DeferredActionRegister; -import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.registries.DeferredAction; +import de.teamlapen.vampirism.api.registries.DeferredActionRegister; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.actions.IAction; -import de.teamlapen.vampirism.entity.player.FactionBasePlayer; import net.neoforged.bus.api.IEventBus; -import net.neoforged.neoforge.registries.DeferredHolder; -import net.neoforged.neoforge.registries.DeferredRegister; import org.jetbrains.annotations.ApiStatus; public class LordActions { diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/lord/actions/LordRangeEffectAction.java b/src/main/java/de/teamlapen/vampirism/entity/player/lord/actions/LordRangeEffectAction.java index 36b633956c..3b6f7d9da7 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/lord/actions/LordRangeEffectAction.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/lord/actions/LordRangeEffectAction.java @@ -1,12 +1,17 @@ package de.teamlapen.vampirism.entity.player.lord.actions; import de.teamlapen.vampirism.api.VampirismAPI; +import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.VampirismTags; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.actions.DefaultAction; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; import de.teamlapen.vampirism.entity.player.IVampirismPlayer; import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.tags.TagKey; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.LivingEntity; @@ -28,7 +33,7 @@ public LordRangeEffectAction(Holder effect) { @Override protected boolean activate(@NotNull T player, ActivationContext context) { int lordLevel = FactionPlayerHandler.get(player.asEntity()).getLordLevel(); - List entitiesOfClass = player.asEntity().level().getEntitiesOfClass(LivingEntity.class, new AABB(player.asEntity().blockPosition()).inflate(10, 10, 10), e -> player.getFaction() == VampirismAPI.factionRegistry().getFaction(e)); + List entitiesOfClass = player.asEntity().level().getEntitiesOfClass(LivingEntity.class, new AABB(player.asEntity().blockPosition()).inflate(10, 10, 10), e -> IFaction.is(player.getFaction(), VampirismAPI.factionRegistry().getFactionHolder(e))); for (LivingEntity entity : entitiesOfClass) { if (entity instanceof Player && FactionPlayerHandler.get(((Player) entity)).getLordLevel() >= lordLevel) { continue; @@ -54,4 +59,9 @@ protected int getEffectAmplifier(@NotNull T player) { public Optional> getFaction() { return Optional.empty(); } + + @Override + public @NotNull TagKey> factions() { + return VampirismTags.Factions.ALL_FACTIONS; + } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/lord/skills/SimpleLordSkill.java b/src/main/java/de/teamlapen/vampirism/entity/player/lord/skills/SimpleLordSkill.java index a80c25d0ab..6b890b4398 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/lord/skills/SimpleLordSkill.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/lord/skills/SimpleLordSkill.java @@ -1,10 +1,13 @@ package de.teamlapen.vampirism.entity.player.lord.skills; import com.mojang.datafixers.util.Either; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; +import de.teamlapen.vampirism.core.tags.ModFactionTags; import de.teamlapen.vampirism.core.tags.ModSkillTreeTags; import de.teamlapen.vampirism.entity.player.skills.VampirismSkill; +import net.minecraft.tags.TagKey; import org.jetbrains.annotations.NotNull; import java.util.Optional; @@ -23,4 +26,9 @@ public SimpleLordSkill(int skillPointCost, boolean hasDescription) { public @NotNull Optional> getFaction() { return Optional.empty(); } + + @Override + public TagKey> factions() { + return ModFactionTags.HAS_LORD_SKILLS; + } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/refinements/RefinementSet.java b/src/main/java/de/teamlapen/vampirism/entity/player/refinements/RefinementSet.java index 33c05b1f94..af9253c5d0 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/refinements/RefinementSet.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/refinements/RefinementSet.java @@ -6,6 +6,7 @@ import de.teamlapen.vampirism.api.entity.player.refinement.IRefinement; import de.teamlapen.vampirism.api.entity.player.refinement.IRefinementSet; import de.teamlapen.vampirism.api.items.IRefinementItem; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.util.RegUtil; import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; @@ -92,8 +93,8 @@ public VampireRefinementSet(Rarity rarity, int color, Holder... ref @NotNull @Override - public IFaction getFaction() { - return VReference.VAMPIRE_FACTION; + public Holder> getFaction() { + return ModFactions.VAMPIRE; } } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/skills/ActionSkill.java b/src/main/java/de/teamlapen/vampirism/entity/player/skills/ActionSkill.java index dcbdeef0ef..835e4648ac 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/skills/ActionSkill.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/skills/ActionSkill.java @@ -1,6 +1,7 @@ package de.teamlapen.vampirism.entity.player.skills; import com.mojang.datafixers.util.Either; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.factions.ISkillTree; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; @@ -84,11 +85,17 @@ public Holder> actionHolder() { } @NotNull + @Deprecated @Override public Optional> getFaction() { return this.action.value().getFaction(); } + @Override + public TagKey> factions() { + return this.action.value().factions(); + } + @Override public MutableComponent getName() { return this.action.value().getName(); diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/skills/SkillHandler.java b/src/main/java/de/teamlapen/vampirism/entity/player/skills/SkillHandler.java index f03442eec9..01f029a74a 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/skills/SkillHandler.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/skills/SkillHandler.java @@ -52,7 +52,7 @@ public class SkillHandler> implements ISkillHandler< private final static Logger LOGGER = LogManager.getLogger(); private final ArrayList>> enabledSkills = new ArrayList<>(); private final T player; - private final IPlayableFaction faction; + private final Holder> faction; private final NonNullList refinementItems = NonNullList.withSize(3, ItemStack.EMPTY); private final Set> activeRefinements = new HashSet<>(); private final Map, AttributeModifier> refinementModifier = new HashMap<>(); @@ -61,7 +61,7 @@ public class SkillHandler> implements ISkillHandler< private boolean dirty = false; private final ISkillTreeData treeData; - public SkillHandler(T player, IPlayableFaction faction) { + public SkillHandler(T player, Holder> faction) { this.player = player; this.faction = faction; this.treeData = ISkillTreeData.getData(player.asEntity().level()); @@ -300,7 +300,7 @@ public void deserializeNBT(HolderLookup.@NotNull Provider provider, @NotNull Com if ("none".equals(setName)) continue; ResourceLocation setId = new ResourceLocation(setName); IRefinementSet set = RegUtil.getRefinementSet(setId); - Item refinementItem = this.faction.getRefinementItem(IRefinementItem.AccessorySlotType.values()[i]); + Item refinementItem = this.faction.value().getRefinementItem(IRefinementItem.AccessorySlotType.values()[i]); ItemStack itemStack = new ItemStack(refinementItem); itemStack.setDamageValue(damage); ((IRefinementItem) refinementItem).applyRefinementSet(itemStack, set); @@ -314,8 +314,8 @@ public void deserializeNBT(HolderLookup.@NotNull Provider provider, @NotNull Com int slot = stackNbt.getInt("slot"); ItemStack stack = ItemStack.parseOptional(provider, stackNbt.getCompound("stack")); if (stack.getItem() instanceof IRefinementItem refinementItem) { - IFaction exclusiveFaction = refinementItem.getExclusiveFaction(stack); - if (exclusiveFaction == null || this.faction.equals(exclusiveFaction)) { + Holder> exclusiveFaction = refinementItem.getExclusiveFaction(stack); + if (exclusiveFaction == null || IFaction.is(this.faction, exclusiveFaction)) { applyRefinementItem(stack, slot); } } @@ -357,8 +357,8 @@ public void deserializeUpdateNBT(HolderLookup.Provider provider, @NotNull Compou int slot = stackNbt.getInt("slot"); ItemStack stack = ItemStack.parseOptional(provider, stackNbt.getCompound("stack")); if (stack.getItem() instanceof IRefinementItem refinementItem) { - IFaction exclusiveFaction = refinementItem.getExclusiveFaction(stack); - if (exclusiveFaction == null || this.faction.equals(exclusiveFaction)) { + Holder> exclusiveFaction = refinementItem.getExclusiveFaction(stack); + if (exclusiveFaction == null || IFaction.is(this.faction, exclusiveFaction)) { applyRefinementItem(stack, slot); } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/skills/SkillTree.java b/src/main/java/de/teamlapen/vampirism/entity/player/skills/SkillTree.java index 20ec02651f..c32efb3c31 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/skills/SkillTree.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/skills/SkillTree.java @@ -2,19 +2,23 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.factions.ISkillTree; +import de.teamlapen.vampirism.core.ModRegistries; +import de.teamlapen.vampirism.util.FactionCodec; import net.minecraft.advancements.critereon.EntityPredicate; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentSerialization; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; -public record SkillTree(@NotNull IPlayableFaction faction, @NotNull EntityPredicate unlockPredicate, @NotNull ItemStack display, @NotNull Component name) implements ISkillTree { +public record SkillTree(@NotNull Holder> faction, @NotNull EntityPredicate unlockPredicate, @NotNull ItemStack display, @NotNull Component name) implements ISkillTree { public static final Codec CODEC = Codec.lazyInitialized(() -> RecordCodecBuilder.create(inst -> inst.group( - IPlayableFaction.CODEC.fieldOf("faction").forGetter(ISkillTree::faction), + FactionCodec.playable().fieldOf("faction").forGetter(ISkillTree::faction), EntityPredicate.CODEC.fieldOf("unlock_predicate").forGetter(ISkillTree::unlockPredicate), ItemStack.CODEC.fieldOf("display").forGetter(ISkillTree::display), ComponentSerialization.CODEC.fieldOf("name").forGetter(ISkillTree::name) diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/skills/VampirismSkill.java b/src/main/java/de/teamlapen/vampirism/entity/player/skills/VampirismSkill.java index d975c111ed..5a4fb3fd3a 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/skills/VampirismSkill.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/skills/VampirismSkill.java @@ -2,12 +2,16 @@ import com.mojang.datafixers.util.Either; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.factions.ISkillTree; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.hunter.IHunterPlayer; import de.teamlapen.vampirism.api.entity.player.skills.DefaultSkill; import de.teamlapen.vampirism.api.entity.player.vampire.IVampirePlayer; +import de.teamlapen.vampirism.core.ModFactions; +import de.teamlapen.vampirism.core.ModTasks; +import de.teamlapen.vampirism.core.tags.ModFactionTags; import de.teamlapen.vampirism.entity.player.hunter.skills.HunterSkills; import de.teamlapen.vampirism.entity.player.vampire.skills.VampireSkills; import net.minecraft.network.chat.Component; @@ -106,6 +110,10 @@ public Optional> getFaction() { return Optional.of(VReference.HUNTER_FACTION); } + @Override + public TagKey> factions() { + return ModFactionTags.IS_HUNTER; + } } public static class HunterLordSkill extends VampirismSkill { @@ -123,6 +131,10 @@ public Optional> getFaction() { return Optional.of(VReference.HUNTER_FACTION); } + @Override + public TagKey> factions() { + return ModFactionTags.IS_HUNTER; + } } /** @@ -136,10 +148,15 @@ public SimpleVampireSkill(int skillPointCost, boolean desc) { @NotNull @Override + @Deprecated public Optional> getFaction() { return Optional.of(VReference.VAMPIRE_FACTION); } + @Override + public TagKey> factions() { + return ModFactionTags.IS_VAMPIRE; + } } public static class VampireLordSkill extends VampirismSkill { @@ -149,9 +166,15 @@ public VampireLordSkill(int skillPointCost, boolean desc) { @NotNull @Override + @Deprecated public Optional> getFaction() { return Optional.of(VReference.VAMPIRE_FACTION); } + + @Override + public TagKey> factions() { + return ModFactionTags.IS_VAMPIRE; + } } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/tasks/reward/RefinementItemReward.java b/src/main/java/de/teamlapen/vampirism/entity/player/tasks/reward/RefinementItemReward.java index 00ca54bb44..1fcfada1f2 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/tasks/reward/RefinementItemReward.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/tasks/reward/RefinementItemReward.java @@ -13,7 +13,9 @@ import de.teamlapen.vampirism.api.items.IRefinementItem; import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.entity.player.refinements.RefinementSet; +import de.teamlapen.vampirism.util.FactionCodec; import de.teamlapen.vampirism.util.RegUtil; +import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.util.RandomSource; import net.minecraft.util.StringRepresentable; @@ -24,23 +26,20 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.function.Supplier; import java.util.stream.Collectors; +import java.util.stream.Stream; public class RefinementItemReward extends ItemReward { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(inst -> { - //noinspection RedundantCast,unchecked return inst.group(BuiltInRegistries.ITEM.byNameCodec().optionalFieldOf("item").forGetter(i -> Optional.ofNullable(i.item.get()).map(IRefinementItem::asItem)), - IFaction.CODEC.optionalFieldOf("faction").forGetter(i -> (Optional>) (Object) Optional.ofNullable(i.faction)), + FactionCodec.playable().optionalFieldOf("faction").forGetter(i -> Optional.ofNullable(i.faction)), StringRepresentable.fromEnum(IRefinementSet.Rarity::values).optionalFieldOf("rarity").forGetter(i -> Optional.ofNullable(i.rarity)) ).apply(inst, (reward, faction, rarity) -> { Preconditions.checkArgument(reward.isEmpty() || reward.get() instanceof IRefinementItem, "Item must be a refinement item"); - Preconditions.checkArgument(reward.isEmpty() || matchFaction(((IRefinementItem) reward.get()).getExclusiveFaction(reward.get().getDefaultInstance()), faction.get()), "Faction must match item faction"); + Preconditions.checkArgument(reward.isEmpty() || IFaction.is(((IRefinementItem) reward.get()).getExclusiveFaction(reward.get().getDefaultInstance()), faction.orElse(null)), "Faction must match item faction"); return new RefinementItemReward((IRefinementItem) reward.orElse(null), faction.orElse(null), rarity.orElse(null)); }); }); @@ -49,27 +48,26 @@ public class RefinementItemReward extends ItemReward { @NotNull private final Supplier<@Nullable IRefinementItem> item; - @Nullable - private final IFaction faction; + private final Holder> faction; @Nullable private final IRefinementSet.Rarity rarity; - public RefinementItemReward(@Nullable IFaction faction) { + public RefinementItemReward(@Nullable Holder> faction) { this(faction, null); } - public RefinementItemReward(@Nullable IFaction faction, @Nullable IRefinementSet.Rarity refinementRarity) { + public RefinementItemReward(@Nullable Holder> faction, @Nullable IRefinementSet.Rarity refinementRarity) { this(faction, () -> null, refinementRarity); } - public RefinementItemReward(@Nullable IFaction faction, @NotNull Supplier<@Nullable IRefinementItem> item, @Nullable IRefinementSet.Rarity refinementRarity) { + public RefinementItemReward(@Nullable Holder> faction, @NotNull Supplier<@Nullable IRefinementItem> item, @Nullable IRefinementSet.Rarity refinementRarity) { super(ItemStack.EMPTY); this.item = item; this.faction = faction; this.rarity = refinementRarity; } - private RefinementItemReward(@Nullable IRefinementItem reward, @Nullable IFaction faction, IRefinementSet.@Nullable Rarity rarity) { + private RefinementItemReward(@Nullable IRefinementItem reward, Holder> faction, IRefinementSet.@Nullable Rarity rarity) { super(ItemStack.EMPTY); this.item = () -> reward; this.faction = faction; @@ -87,23 +85,22 @@ public List getAllPossibleRewards() { } protected @NotNull ItemStack createItem() { - if (this.faction != null && !(this.faction instanceof IPlayableFaction)) return ItemStack.EMPTY; - IPlayableFaction faction = ((IPlayableFaction) this.faction); + Holder> faction = this.faction; IRefinementItem baseItem = this.item.get(); if (faction == null) { if (baseItem != null) { - faction = (IPlayableFaction) baseItem.getExclusiveFaction(baseItem.asItem().getDefaultInstance()); + faction = baseItem.getExclusiveFaction(baseItem.asItem().getDefaultInstance()); } else { faction = getRandomFactionWithAccessories(); } if (faction == null) return ItemStack.EMPTY; } - IPlayableFaction finalFaction = faction; + Holder> finalFaction = faction; - Z item = this.item.get() != null ? (Z) this.item.get() : faction.getRefinementItem(IRefinementItem.AccessorySlotType.values()[RANDOM.nextInt(IRefinementItem.AccessorySlotType.values().length)]); + Z item = this.item.get() != null ? (Z) this.item.get() : faction.value().getRefinementItem(IRefinementItem.AccessorySlotType.values()[RANDOM.nextInt(IRefinementItem.AccessorySlotType.values().length)]); IRefinementItem.AccessorySlotType slot = (item).getSlotType(); List< WeightedEntry.Wrapper> sets = RegUtil.values(ModRegistries.REFINEMENT_SETS).stream() - .filter(set -> set.getFaction() == finalFaction) + .filter(set -> IFaction.is(set.getFaction(), finalFaction)) .filter(set -> this.rarity == null || set.getRarity().ordinal() >= this.rarity.ordinal()) .filter(set -> set.getSlotType().map(slot1 -> slot1 == slot).orElse(true)) .map(set -> ((RefinementSet) set).getWeightedRandom()).collect(Collectors.toList()); @@ -115,12 +112,14 @@ public List getAllPossibleRewards() { } private @NotNull List getAllRefinementItems() { - return Arrays.stream(this.faction != null ? new IPlayableFaction[]{(IPlayableFaction) this.faction} : VampirismAPI.factionRegistry().getPlayableFactions()).filter(IPlayableFaction::hasRefinements).flatMap(function -> Arrays.stream(IRefinementItem.AccessorySlotType.values()).map(function::getRefinementItem)).map(a -> new ItemStack((Item) a)).collect(Collectors.toList()); + Stream> stream = this.faction != null ? Stream.of(this.faction.value()) : ModRegistries.FACTIONS.stream().filter(IPlayableFaction.class::isInstance).map(s -> (IPlayableFaction)s); + return stream.filter(IPlayableFaction::hasRefinements).flatMap(function -> Arrays.stream(IRefinementItem.AccessorySlotType.values()).map(function::getRefinementItem)).map(a -> new ItemStack((Item) a)).collect(Collectors.toList()); } @Nullable - private static IPlayableFaction getRandomFactionWithAccessories() { - List> factions = Arrays.stream(VampirismAPI.factionRegistry().getPlayableFactions()).filter(IPlayableFaction::hasRefinements).toList(); + private static Holder> getRandomFactionWithAccessories() { + //noinspection unchecked,RedundantCast + List>> factions = ModRegistries.FACTIONS.holders().filter(s -> s.value() instanceof IPlayableFaction).map(s -> ((Holder>) (Object) s)).filter(s -> s.value().hasRefinements()).collect(Collectors.toUnmodifiableList()); if (factions.isEmpty()) return null; return factions.get(RANDOM.nextInt(factions.size()) - 1); } @@ -130,7 +129,7 @@ public MapCodec codec() { return CODEC; } - private static boolean matchFaction(IFaction target, IFaction faction) { + private static boolean matchFaction(Holder> target, IFaction faction) { return target == null || faction == null || target == faction; } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/vampire/VampirePlayer.java b/src/main/java/de/teamlapen/vampirism/entity/player/vampire/VampirePlayer.java index f25d4badff..2f3150c9a8 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/vampire/VampirePlayer.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/vampire/VampirePlayer.java @@ -52,6 +52,7 @@ import de.teamlapen.vampirism.world.MinionWorldData; import de.teamlapen.vampirism.world.ModDamageSources; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.core.particles.ItemParticleOption; import net.minecraft.core.particles.ParticleTypes; @@ -181,7 +182,7 @@ public VampirePlayer(Player player) { super(player); bloodStats = new BloodStats(player); actionHandler = new ActionHandler<>(this); - skillHandler = new SkillHandler<>(this, VReference.VAMPIRE_FACTION); + skillHandler = new SkillHandler<>(this, ModFactions.VAMPIRE); this.disguise = new Disguise(); } @@ -1546,7 +1547,7 @@ public String nbtKey() { private class Disguise implements IDisguise, ISyncable { private static final String KEY_DISGUISE = "disguise"; private boolean isDisguised; - private @Nullable IPlayableFaction disguiseFaction = getOriginalFaction(); + private @Nullable Holder> disguiseFaction = getOriginalFaction(); @Override public void unDisguise() { @@ -1554,7 +1555,7 @@ public void unDisguise() { } @Override - public void disguiseAs(@Nullable IPlayableFaction faction) { + public void disguiseAs(@Nullable Holder> faction) { this.disguiseFaction = faction; this.isDisguised = faction != getOriginalFaction(); getSpecialAttributes().disguised = this.isDisguised; @@ -1565,12 +1566,12 @@ public void disguiseAs(@Nullable IPlayableFaction faction) { } @Override - public @NotNull IPlayableFaction getOriginalFaction() { + public @NotNull Holder> getOriginalFaction() { return getFaction(); } @Override - public @Nullable IPlayableFaction getViewedFaction(@Nullable IFaction viewerFaction) { + public @Nullable Holder> getViewedFaction(@Nullable Holder> viewerFaction) { return disguiseFaction; } @@ -1583,18 +1584,14 @@ public boolean isDisguised() { public void deserializeUpdateNBT(HolderLookup.@NotNull Provider provider, @NotNull CompoundTag nbt) { if (nbt.contains("disguise")) { String disguise = nbt.getString("disguise"); - if (disguise.isEmpty()) { - disguiseAs(null); - } else { - disguiseAs((IPlayableFaction) VampirismAPI.factionRegistry().getFactionByID(new ResourceLocation(disguise))); - } + disguiseAs(Optional.of(disguise).filter(s -> !s.isEmpty()).flatMap(s -> ModRegistries.FACTIONS.getHolder(new ResourceLocation(s))).orElse(null)); } } @Override public @NotNull CompoundTag serializeUpdateNBT(HolderLookup.@NotNull Provider provider ) { CompoundTag tag = new CompoundTag(); - tag.putString("disguise", this.disguiseFaction == null ? "" : this.disguiseFaction.getID().toString()); + tag.putString("disguise", Optional.ofNullable(this.disguiseFaction).flatMap(Holder::unwrapKey).map(ResourceKey::location).map(ResourceLocation::toString).orElse("")); return tag; } diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/vampire/actions/VampireActions.java b/src/main/java/de/teamlapen/vampirism/entity/player/vampire/actions/VampireActions.java index 74698e639d..2875ff2b5f 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/vampire/actions/VampireActions.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/vampire/actions/VampireActions.java @@ -1,8 +1,8 @@ package de.teamlapen.vampirism.entity.player.vampire.actions; import de.teamlapen.vampirism.REFERENCE; -import de.teamlapen.vampirism.api.DeferredAction; -import de.teamlapen.vampirism.api.DeferredActionRegister; +import de.teamlapen.vampirism.api.registries.DeferredAction; +import de.teamlapen.vampirism.api.registries.DeferredActionRegister; import de.teamlapen.vampirism.api.entity.player.actions.IAction; import de.teamlapen.vampirism.api.entity.player.actions.ILastingAction; import de.teamlapen.vampirism.api.entity.player.vampire.IVampirePlayer; diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/vampire/skills/VampireSkills.java b/src/main/java/de/teamlapen/vampirism/entity/player/vampire/skills/VampireSkills.java index 78b8494e4d..ff862f964b 100755 --- a/src/main/java/de/teamlapen/vampirism/entity/player/vampire/skills/VampireSkills.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/vampire/skills/VampireSkills.java @@ -11,6 +11,7 @@ import de.teamlapen.vampirism.api.entity.player.vampire.IVampirePlayer; import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModAttributes; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.entity.player.lord.skills.LordSkills; import de.teamlapen.vampirism.entity.player.skills.ActionSkill; @@ -43,8 +44,8 @@ public class VampireSkills { public static final DeferredRegister> SKILLS = DeferredRegister.create(VampirismRegistries.Keys.SKILL, REFERENCE.MODID); - public static final DeferredHolder, ISkill> LEVEL_ROOT = SKILLS.register(VReference.VAMPIRE_FACTION.getID().getPath(), () -> new VampirismSkill.SimpleVampireSkill(0, false)); - public static final DeferredHolder, ISkill> LORD_ROOT = SKILLS.register(VReference.VAMPIRE_FACTION.getID().withSuffix("_lord").getPath(), () -> new VampirismSkill.SimpleVampireSkill(0, false)); + public static final DeferredHolder, ISkill> LEVEL_ROOT = SKILLS.register(ModFactions.VAMPIRE.getKey().location().getPath(), () -> new VampirismSkill.SimpleVampireSkill(0, false)); + public static final DeferredHolder, ISkill> LORD_ROOT = SKILLS.register(ModFactions.VAMPIRE.getKey().location().withSuffix("_lord").getPath(), () -> new VampirismSkill.SimpleVampireSkill(0, false)); public static final DeferredHolder, ISkill> ADVANCED_BITER = SKILLS.register("advanced_biter", () -> new VampirismSkill.SimpleVampireSkill(2, false).setToggleActions(player -> ((VampirePlayer) player).getSpecialAttributes().advanced_biter = true, player -> ((VampirePlayer) player).getSpecialAttributes().advanced_biter = false).setHasDefaultDescription()); public static final DeferredHolder, ISkill> FLEDGLING = SKILLS.register("fledgling", () -> new VampirismSkill.SimpleVampireSkill(2, true) { @Override @@ -179,8 +180,8 @@ private static ResourceKey tree(String path) { public static void createSkillTrees(BootstrapContext context) { HolderGetter lookup = context.lookup(VampirismRegistries.Keys.SKILL_NODE); - context.register(LEVEL, new SkillTree(VReference.VAMPIRE_FACTION, EntityPredicate.Builder.entity().subPredicate(FactionSubPredicate.faction(VReference.VAMPIRE_FACTION)).build(), new ItemStack(ModItems.VAMPIRE_BOOK.get()), Component.translatable("text.vampirism.skills.level"))); - context.register(LORD, new SkillTree(VReference.VAMPIRE_FACTION, EntityPredicate.Builder.entity().subPredicate(FactionSubPredicate.lord(VReference.VAMPIRE_FACTION)).build(), new ItemStack(ModItems.VAMPIRE_MINION_BINDING.get()), Component.translatable("text.vampirism.skills.lord"))); + context.register(LEVEL, new SkillTree(ModFactions.VAMPIRE, EntityPredicate.Builder.entity().subPredicate(FactionSubPredicate.faction(ModFactions.VAMPIRE)).build(), new ItemStack(ModItems.VAMPIRE_BOOK.get()), Component.translatable("text.vampirism.skills.level"))); + context.register(LORD, new SkillTree(ModFactions.VAMPIRE, EntityPredicate.Builder.entity().subPredicate(FactionSubPredicate.lord(ModFactions.VAMPIRE)).build(), new ItemStack(ModItems.VAMPIRE_MINION_BINDING.get()), Component.translatable("text.vampirism.skills.lord"))); } } } diff --git a/src/main/java/de/teamlapen/vampirism/entity/vampire/BasicVampireEntity.java b/src/main/java/de/teamlapen/vampirism/entity/vampire/BasicVampireEntity.java index f17e867bfe..509eda8340 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/vampire/BasicVampireEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/vampire/BasicVampireEntity.java @@ -12,10 +12,7 @@ import de.teamlapen.vampirism.api.world.ICaptureAttributes; import de.teamlapen.vampirism.config.BalanceMobProps; import de.teamlapen.vampirism.config.VampirismConfig; -import de.teamlapen.vampirism.core.ModEffects; -import de.teamlapen.vampirism.core.ModEntities; -import de.teamlapen.vampirism.core.ModItems; -import de.teamlapen.vampirism.core.ModSounds; +import de.teamlapen.vampirism.core.*; import de.teamlapen.vampirism.effects.BadOmenEffect; import de.teamlapen.vampirism.entity.IEntityFollower; import de.teamlapen.vampirism.entity.ai.goals.*; @@ -406,7 +403,7 @@ protected InteractionResult mobInteract(@NotNull Player player, @NotNull Interac if (this.isAlive() && !player.isShiftKeyDown()) { if (!level().isClientSide) { FactionPlayerHandler handler = FactionPlayerHandler.get(player); - int vampireLevel = handler.getCurrentLevel(VReference.VAMPIRE_FACTION); + int vampireLevel = handler.getCurrentLevel(ModFactions.VAMPIRE); if (vampireLevel > 0) { if (handler.getMaxMinions() > 0) { ItemStack heldItem = player.getItemInHand(hand); @@ -443,7 +440,7 @@ protected InteractionResult mobInteract(@NotNull Player player, @NotNull Interac protected void registerGoals() { super.registerGoals(); this.goalSelector.addGoal(1, new BreakDoorGoal(this, (difficulty) -> difficulty == net.minecraft.world.Difficulty.HARD));//Only break doors on hard difficulty - this.tasks_avoidHunter = new AvoidEntityGoal<>(this, PathfinderMob.class, 10, 1.0, 1.1, VampirismAPI.factionRegistry().getPredicate(getFaction(), false, true, false, false, VReference.HUNTER_FACTION)); + this.tasks_avoidHunter = new AvoidEntityGoal<>(this, PathfinderMob.class, 10, 1.0, 1.1, VampirismAPI.factionRegistry().getPredicate(getFaction(), false, true, false, false, ModFactions.HUNTER)); this.goalSelector.addGoal(2, this.tasks_avoidHunter); this.goalSelector.addGoal(2, new RestrictSunVampireGoal<>(this)); this.goalSelector.addGoal(3, new FleeSunVampireGoal<>(this, 0.9, false)); diff --git a/src/main/java/de/teamlapen/vampirism/entity/vampire/VampireTaskMasterEntity.java b/src/main/java/de/teamlapen/vampirism/entity/vampire/VampireTaskMasterEntity.java index 5162c24e27..7a5474486d 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/vampire/VampireTaskMasterEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/vampire/VampireTaskMasterEntity.java @@ -3,6 +3,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; import de.teamlapen.vampirism.config.BalanceMobProps; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.entity.IDefaultTaskMasterEntity; import de.teamlapen.vampirism.entity.ai.goals.FleeSunVampireGoal; import de.teamlapen.vampirism.entity.ai.goals.ForceLookEntityGoal; @@ -119,7 +120,7 @@ protected InteractionResult mobInteract(@NotNull Player playerEntity, @NotNull I protected void registerGoals() { super.registerGoals(); this.goalSelector.addGoal(1, new OpenDoorGoal(this, true)); - this.goalSelector.addGoal(2, new AvoidEntityGoal<>(this, PathfinderMob.class, 10, 1.0, 1.1, VampirismAPI.factionRegistry().getPredicate(getFaction(), false, true, false, false, VReference.HUNTER_FACTION))); + this.goalSelector.addGoal(2, new AvoidEntityGoal<>(this, PathfinderMob.class, 10, 1.0, 1.1, VampirismAPI.factionRegistry().getPredicate(getFaction(), false, true, false, false, ModFactions.HUNTER))); this.goalSelector.addGoal(2, new RestrictSunVampireGoal<>(this)); this.goalSelector.addGoal(2, new ForceLookEntityGoal<>(this)); this.goalSelector.addGoal(3, new FleeSunVampireGoal<>(this, 0.9, false)); diff --git a/src/main/java/de/teamlapen/vampirism/inventory/AltarInfusionMenu.java b/src/main/java/de/teamlapen/vampirism/inventory/AltarInfusionMenu.java index 9ecce405a3..f2a0ec2056 100644 --- a/src/main/java/de/teamlapen/vampirism/inventory/AltarInfusionMenu.java +++ b/src/main/java/de/teamlapen/vampirism/inventory/AltarInfusionMenu.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.core.ModBlocks; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModMenus; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.core.tags.ModItemTags; @@ -37,7 +38,7 @@ public AltarInfusionMenu(int id, @NotNull Inventory playerInventory, @NotNull Co super(ModMenus.ALTAR_INFUSION.get(), id, playerInventory, worldPosCallable); ((ItemCombinerMenuAccessor) this).setInputSlots(inventory); this.init(playerInventory); - this.lvlRequirement = VampireLeveling.getInfusionRequirement(FactionPlayerHandler.get(player).getCurrentLevel(VReference.VAMPIRE_FACTION) + 1); + this.lvlRequirement = VampireLeveling.getInfusionRequirement(FactionPlayerHandler.get(player).getCurrentLevel(ModFactions.VAMPIRE) + 1); } protected void init(@NotNull Inventory playerInventory) { diff --git a/src/main/java/de/teamlapen/vampirism/inventory/HunterBasicMenu.java b/src/main/java/de/teamlapen/vampirism/inventory/HunterBasicMenu.java index 3016903b5c..7dfe81a66d 100644 --- a/src/main/java/de/teamlapen/vampirism/inventory/HunterBasicMenu.java +++ b/src/main/java/de/teamlapen/vampirism/inventory/HunterBasicMenu.java @@ -3,6 +3,7 @@ import de.teamlapen.lib.lib.inventory.InventoryContainerMenu; import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.entity.player.hunter.IHunterPlayer; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModMenus; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; @@ -64,7 +65,7 @@ public void onLevelUpClicked() { HunterLeveling.getBasicHunterRequirement(target).ifPresent(req -> { inventory.removeItem(0, req.vampireBloodAmount()); Player player1 = player.asEntity(); - FactionPlayerHandler.get(player1).setFactionLevel(VReference.HUNTER_FACTION, target); + FactionPlayerHandler.get(player1).setFactionLevel(ModFactions.HUNTER, target); player1.displayClientMessage(Component.translatable("container.vampirism.basic_hunter.levelup"), false); player1.closeContainer(); }); diff --git a/src/main/java/de/teamlapen/vampirism/inventory/HunterTableMenu.java b/src/main/java/de/teamlapen/vampirism/inventory/HunterTableMenu.java index f06957077e..283d029324 100644 --- a/src/main/java/de/teamlapen/vampirism/inventory/HunterTableMenu.java +++ b/src/main/java/de/teamlapen/vampirism/inventory/HunterTableMenu.java @@ -4,6 +4,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.blocks.HunterTableBlock; import de.teamlapen.vampirism.core.ModBlocks; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModMenus; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; @@ -34,7 +35,7 @@ public class HunterTableMenu extends ItemCombinerMenu { public HunterTableMenu(int id, @NotNull Inventory playerInventory, ContainerLevelAccess worldPosCallable) { super(ModMenus.HUNTER_TABLE.get(), id, playerInventory, worldPosCallable); - int hunterLevel = FactionPlayerHandler.get(playerInventory.player).getCurrentLevel(VReference.HUNTER_FACTION); + int hunterLevel = FactionPlayerHandler.get(playerInventory.player).getCurrentLevel(ModFactions.HUNTER); this.tableRequirement = HunterLeveling.getTrainerRequirement(hunterLevel + 1).map(HunterLeveling.HunterTrainerRequirement::tableRequirement); } diff --git a/src/main/java/de/teamlapen/vampirism/inventory/HunterTrainerMenu.java b/src/main/java/de/teamlapen/vampirism/inventory/HunterTrainerMenu.java index bb9c96c6b5..d1ecda0e3f 100644 --- a/src/main/java/de/teamlapen/vampirism/inventory/HunterTrainerMenu.java +++ b/src/main/java/de/teamlapen/vampirism/inventory/HunterTrainerMenu.java @@ -2,6 +2,7 @@ import de.teamlapen.lib.lib.inventory.InventoryHelper; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModMenus; import de.teamlapen.vampirism.core.ModEffects; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; @@ -44,7 +45,7 @@ public HunterTrainerMenu(int id, @NotNull Inventory playerInventory, @Nullable H super(ModMenus.HUNTER_TRAINER.get(), id, playerInventory, trainer == null ? ContainerLevelAccess.NULL : ContainerLevelAccess.create(trainer.level(), trainer.blockPosition())); this.player = playerInventory.player; this.entity = trainer; - this.lvlRequirement = HunterLeveling.getTrainerRequirement(FactionPlayerHandler.get(player).getCurrentLevel(VReference.HUNTER_FACTION) + 1); + this.lvlRequirement = HunterLeveling.getTrainerRequirement(FactionPlayerHandler.get(player).getCurrentLevel(ModFactions.HUNTER) + 1); } @Override @@ -98,7 +99,7 @@ public Optional getRequirement() { public void onLevelupClicked() { if (canLevelup()) { this.lvlRequirement.ifPresent(req -> { - FactionPlayerHandler.get(this.player).setFactionLevel(VReference.HUNTER_FACTION, req.targetLevel()); + FactionPlayerHandler.get(this.player).setFactionLevel(ModFactions.HUNTER, req.targetLevel()); InventoryHelper.removeItems(getInputSlots(), req.ironQuantity(), req.goldQuantity(), 1); this.player.addEffect(new MobEffectInstance(ModEffects.SATURATION, 400, 2)); this.lvlRequirement = HunterLeveling.getTrainerRequirement(req.targetLevel() + 1); diff --git a/src/main/java/de/teamlapen/vampirism/inventory/MinionContainer.java b/src/main/java/de/teamlapen/vampirism/inventory/MinionContainer.java index 8e6745e84c..b409f4dac4 100644 --- a/src/main/java/de/teamlapen/vampirism/inventory/MinionContainer.java +++ b/src/main/java/de/teamlapen/vampirism/inventory/MinionContainer.java @@ -71,7 +71,7 @@ public MinionContainer(int id, @NotNull Inventory playerInventory, @NotNull ILor super(ModMenus.MINION.get(), id, playerInventory, ContainerLevelAccess.create(minionEntity.level(), minionEntity.blockPosition()), inventory, selectorInfos); this.minionEntity = minionEntity; this.extraSlots = extraSlots; - this.availableTasks = this.minionEntity.getAvailableTasks().stream().filter(task -> task.isAvailable(lord.getLordFaction(), lord)).toArray(IMinionTask[]::new); + this.availableTasks = this.minionEntity.getAvailableTasks().stream().filter(task -> task.isAvailable(lord.getLordFaction().orElseThrow(), lord)).toArray(IMinionTask[]::new); this.minionEntity.setInteractingPlayer(playerInventory.player); this.addPlayerSlots(playerInventory, 27, 103); this.previousTask = this.minionEntity.getCurrentTask().map(IMinionTask.IMinionTaskDesc::getTask).orElse(null); diff --git a/src/main/java/de/teamlapen/vampirism/inventory/TaskBoardMenu.java b/src/main/java/de/teamlapen/vampirism/inventory/TaskBoardMenu.java index cd7c6f3866..b927ecc260 100644 --- a/src/main/java/de/teamlapen/vampirism/inventory/TaskBoardMenu.java +++ b/src/main/java/de/teamlapen/vampirism/inventory/TaskBoardMenu.java @@ -1,6 +1,7 @@ package de.teamlapen.vampirism.inventory; import com.google.common.collect.Sets; +import com.mojang.datafixers.types.templates.Hook; import de.teamlapen.lib.VampLib; import de.teamlapen.vampirism.VampirismMod; import de.teamlapen.vampirism.api.VampirismRegistries; @@ -14,6 +15,7 @@ import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.network.ServerboundTaskActionPacket; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.network.chat.TextColor; import net.minecraft.resources.ResourceLocation; @@ -56,7 +58,7 @@ public class TaskBoardMenu extends AbstractContainerMenu implements TaskMenu { public TaskBoardMenu(int id, @NotNull Inventory playerInventory) { super(ModMenus.TASK_MASTER.get(), id); this.factionPlayer = FactionPlayerHandler.getCurrentFactionPlayer(playerInventory.player).orElseThrow(() -> new IllegalStateException("Can't open container without faction")); - this.factionColor = this.factionPlayer.getFaction().getChatColor(); + this.factionColor = this.factionPlayer.getFaction().value().getChatColor(); this.registry = playerInventory.player.level().registryAccess().registryOrThrow(VampirismRegistries.Keys.TASK); } @@ -120,7 +122,7 @@ public void pressButton(@NotNull ITaskInstance taskInfo) { } @NotNull - public IPlayableFaction getFaction() { + public Holder> getFaction() { return this.factionPlayer.getFaction(); } diff --git a/src/main/java/de/teamlapen/vampirism/inventory/VampirismMenu.java b/src/main/java/de/teamlapen/vampirism/inventory/VampirismMenu.java index cde2e1bade..b3da6ebc4d 100644 --- a/src/main/java/de/teamlapen/vampirism/inventory/VampirismMenu.java +++ b/src/main/java/de/teamlapen/vampirism/inventory/VampirismMenu.java @@ -3,6 +3,7 @@ import de.teamlapen.lib.lib.inventory.InventoryContainerMenu; import de.teamlapen.vampirism.VampirismMod; import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.task.ITaskInstance; @@ -13,6 +14,7 @@ import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; import de.teamlapen.vampirism.entity.player.TaskManager; import de.teamlapen.vampirism.network.ServerboundTaskActionPacket; +import net.minecraft.core.Holder; import net.minecraft.core.NonNullList; import net.minecraft.core.Registry; import net.minecraft.network.chat.TextColor; @@ -36,11 +38,11 @@ public class VampirismMenu extends InventoryContainerMenu implements TaskMenu { private static final Function SELECTOR_INFOS = player -> { - IPlayableFaction faction = FactionPlayerHandler.getCurrentFactionPlayer(player).orElseThrow(() -> new IllegalStateException("Opening vampirism container without faction")).getFaction(); + Holder> faction = FactionPlayerHandler.getCurrentFactionPlayer(player).orElseThrow(() -> new IllegalStateException("Opening vampirism container without faction")).getFaction(); return new SelectorInfo[]{ - new SelectorInfo(stack -> stack.getItem() instanceof IRefinementItem && ((IRefinementItem) stack.getItem()).getSlotType() == IRefinementItem.AccessorySlotType.AMULET && faction.equals(((IRefinementItem) stack.getItem()).getExclusiveFaction(stack)), 58, 8), - new SelectorInfo(stack -> stack.getItem() instanceof IRefinementItem && ((IRefinementItem) stack.getItem()).getSlotType() == IRefinementItem.AccessorySlotType.RING && faction.equals(((IRefinementItem) stack.getItem()).getExclusiveFaction(stack)), 58, 26), - new SelectorInfo(stack -> stack.getItem() instanceof IRefinementItem && ((IRefinementItem) stack.getItem()).getSlotType() == IRefinementItem.AccessorySlotType.OBI_BELT && faction.equals(((IRefinementItem) stack.getItem()).getExclusiveFaction(stack)), 58, 44)}; + new SelectorInfo(stack -> stack.getItem() instanceof IRefinementItem && ((IRefinementItem) stack.getItem()).getSlotType() == IRefinementItem.AccessorySlotType.AMULET && IFaction.is(faction, ((IRefinementItem) stack.getItem()).getExclusiveFaction(stack)), 58, 8), + new SelectorInfo(stack -> stack.getItem() instanceof IRefinementItem && ((IRefinementItem) stack.getItem()).getSlotType() == IRefinementItem.AccessorySlotType.RING && IFaction.is(faction, ((IRefinementItem) stack.getItem()).getExclusiveFaction(stack)), 58, 26), + new SelectorInfo(stack -> stack.getItem() instanceof IRefinementItem && ((IRefinementItem) stack.getItem()).getSlotType() == IRefinementItem.AccessorySlotType.OBI_BELT && IFaction.is(faction, ((IRefinementItem) stack.getItem()).getExclusiveFaction(stack)), 58, 44)}; }; private final IFactionPlayer factionPlayer; private final TextColor factionColor; @@ -55,8 +57,8 @@ public class VampirismMenu extends InventoryContainerMenu implements TaskMenu { public VampirismMenu(int id, @NotNull Inventory playerInventory) { super(ModMenus.VAMPIRISM.get(), id, playerInventory, ContainerLevelAccess.NULL, new SimpleContainer(3), RemovingSelectorSlot::new, SELECTOR_INFOS.apply(playerInventory.player)); this.factionPlayer = FactionPlayerHandler.get(playerInventory.player).getCurrentFactionPlayer().orElseThrow(() -> new IllegalStateException("Opening vampirism container without faction")); - this.factionColor = factionPlayer.getFaction().getChatColor(); - this.refinementsAvailable = factionPlayer.getFaction().hasRefinements(); + this.factionColor = factionPlayer.getFaction().value().getChatColor(); + this.refinementsAvailable = factionPlayer.getFaction().value().hasRefinements(); this.addPlayerSlots(playerInventory, 37, 124); this.refinementStacks = this.factionPlayer.getSkillHandler().getRefinementItems(); this.registry = playerInventory.player.level().registryAccess().registryOrThrow(VampirismRegistries.Keys.TASK); @@ -111,7 +113,6 @@ public boolean areRefinementsAvailable() { @Override public int getRequirementStatus(@NotNull ITaskInstance taskInfo, @NotNull TaskRequirement.Requirement requirement) { - assert this.completedRequirements != null; if (this.completedRequirements.containsKey(taskInfo.getTaskBoard())) { return this.completedRequirements.get(taskInfo.getTaskBoard()).get(taskInfo.getId()).get(requirement.id()); } else { @@ -139,11 +140,9 @@ public boolean isCompleted(@NotNull ITaskInstance item) { @Override public boolean isRequirementCompleted(@NotNull ITaskInstance taskInfo, @NotNull TaskRequirement.Requirement requirement) { - if (this.completedRequirements != null) { - if (this.completedRequirements.containsKey(taskInfo.getTaskBoard()) && this.completedRequirements.get(taskInfo.getTaskBoard()).containsKey(taskInfo.getId())) { - Map data = this.completedRequirements.get(taskInfo.getTaskBoard()).get(taskInfo.getId()); - return data.containsKey(requirement.id()) && data.get(requirement.id()) >= requirement.getAmount(this.factionPlayer); - } + if (this.completedRequirements.containsKey(taskInfo.getTaskBoard()) && this.completedRequirements.get(taskInfo.getTaskBoard()).containsKey(taskInfo.getId())) { + Map data = this.completedRequirements.get(taskInfo.getTaskBoard()).get(taskInfo.getId()); + return data.containsKey(requirement.id()) && data.get(requirement.id()) >= requirement.getAmount(this.factionPlayer); } return false; } diff --git a/src/main/java/de/teamlapen/vampirism/items/BlessableItem.java b/src/main/java/de/teamlapen/vampirism/items/BlessableItem.java index 7ea5c53cdf..c2b4fff854 100644 --- a/src/main/java/de/teamlapen/vampirism/items/BlessableItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/BlessableItem.java @@ -7,6 +7,7 @@ import de.teamlapen.vampirism.api.entity.factions.IFactionPlayerHandler; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.core.ModBlocks; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModSounds; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; import de.teamlapen.vampirism.entity.player.hunter.HunterPlayer; @@ -113,7 +114,7 @@ public void onUseTick(@NotNull Level pLevel, @NotNull LivingEntity pLivingEntity public @NotNull ItemStack finishUsingItem(@NotNull ItemStack stack, @NotNull Level world, @NotNull LivingEntity livingEntity) { if (enhancedBlessedItem != null && livingEntity instanceof Player player) { IFactionPlayerHandler handler = FactionPlayerHandler.get(player); - boolean enhanced = handler.isInFaction(VReference.HUNTER_FACTION) && handler.getCurrentFactionPlayer().map(IFactionPlayer::getSkillHandler).map(s -> s.isSkillEnabled(HunterSkills.ENHANCED_BLESSING)).orElse(false); + boolean enhanced = handler.isInFaction(ModFactions.HUNTER) && handler.getCurrentFactionPlayer().map(IFactionPlayer::getSkillHandler).map(s -> s.isSkillEnabled(HunterSkills.ENHANCED_BLESSING)).orElse(false); return new ItemStack(enhanced ? enhancedBlessedItem.get() : blessedItem.get(), stack.getCount()); } return new ItemStack(blessedItem.get(), stack.getCount()); diff --git a/src/main/java/de/teamlapen/vampirism/items/BloodBottleItem.java b/src/main/java/de/teamlapen/vampirism/items/BloodBottleItem.java index 4c763f74d6..bbe678ccfd 100644 --- a/src/main/java/de/teamlapen/vampirism/items/BloodBottleItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/BloodBottleItem.java @@ -6,12 +6,14 @@ import de.teamlapen.vampirism.api.entity.vampire.IVampire; import de.teamlapen.vampirism.api.items.IFactionExclusiveItem; import de.teamlapen.vampirism.core.ModDataComponents; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.entity.player.vampire.VampirePlayer; import de.teamlapen.vampirism.entity.vampire.DrinkBloodContext; import de.teamlapen.vampirism.fluids.BloodHelper; import de.teamlapen.vampirism.items.component.BottleBlood; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; @@ -93,10 +95,9 @@ public void generateCreativeTab(CreativeModeTab.@NotNull ItemDisplayParameters p output.accept(stack9, CreativeModeTab.TabVisibility.PARENT_TAB_ONLY); } - @Nullable @Override - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.VAMPIRE_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.VAMPIRE; } @NotNull diff --git a/src/main/java/de/teamlapen/vampirism/items/CrucifixItem.java b/src/main/java/de/teamlapen/vampirism/items/CrucifixItem.java index 767ccc6742..3553b6691f 100644 --- a/src/main/java/de/teamlapen/vampirism/items/CrucifixItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/CrucifixItem.java @@ -9,6 +9,7 @@ import de.teamlapen.vampirism.api.items.IFactionLevelItem; import de.teamlapen.vampirism.api.items.IItemWithTier; import de.teamlapen.vampirism.core.ModEffects; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModRefinements; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.entity.player.hunter.skills.HunterSkills; @@ -70,10 +71,9 @@ public Holder> requiredSkill(@NotNull ItemStack stack) { return HunterSkills.CRUCIFIX_WIELDER; } - @org.jetbrains.annotations.Nullable @Override - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.HUNTER_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.HUNTER; } @Override @@ -142,7 +142,7 @@ protected static int determineEntityTier(LivingEntity e) { if (e instanceof Player) { int level = VampirismPlayerAttributes.get((Player) e).vampireLevel; int tier = 1; - if (level == VReference.VAMPIRE_FACTION.getHighestReachableLevel()) { + if (level == ModFactions.VAMPIRE.value().getHighestReachableLevel()) { tier = 3; } else if (level >= 8) { tier = 2; diff --git a/src/main/java/de/teamlapen/vampirism/items/GarlicBreadItem.java b/src/main/java/de/teamlapen/vampirism/items/GarlicBreadItem.java index 92d0a873db..733c278f2d 100644 --- a/src/main/java/de/teamlapen/vampirism/items/GarlicBreadItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/GarlicBreadItem.java @@ -3,7 +3,9 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.items.IFactionExclusiveItem; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; +import net.minecraft.core.Holder; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.Item; @@ -18,10 +20,9 @@ public GarlicBreadItem() { super(new Properties().food((new FoodProperties.Builder()).nutrition(6).saturationModifier(0.7F).build())); } - @Nullable @Override - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.HUNTER_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.HUNTER; } diff --git a/src/main/java/de/teamlapen/vampirism/items/GarlicItem.java b/src/main/java/de/teamlapen/vampirism/items/GarlicItem.java index 6b79fbe5be..ada7fd8a21 100644 --- a/src/main/java/de/teamlapen/vampirism/items/GarlicItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/GarlicItem.java @@ -4,8 +4,10 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.items.IFactionExclusiveItem; import de.teamlapen.vampirism.core.ModBlocks; +import de.teamlapen.vampirism.core.ModFactions; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Holder; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -26,10 +28,9 @@ public GarlicItem() { super(new Properties()); } - @Nullable @Override - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.HUNTER_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.HUNTER; } @Override diff --git a/src/main/java/de/teamlapen/vampirism/items/HolyWaterBottleItem.java b/src/main/java/de/teamlapen/vampirism/items/HolyWaterBottleItem.java index 31f0bb5010..f7ffedb993 100644 --- a/src/main/java/de/teamlapen/vampirism/items/HolyWaterBottleItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/HolyWaterBottleItem.java @@ -5,6 +5,8 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.items.IFactionExclusiveItem; import de.teamlapen.vampirism.api.items.IItemWithTier; +import de.teamlapen.vampirism.core.ModFactions; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -36,10 +38,9 @@ public void appendHoverText(@NotNull ItemStack stack, @Nullable TooltipContext c addTierInformation(tooltip); } - @Nullable @Override - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.HUNTER_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.HUNTER; } /** diff --git a/src/main/java/de/teamlapen/vampirism/items/HunterArmorItem.java b/src/main/java/de/teamlapen/vampirism/items/HunterArmorItem.java index 984cf53109..29e08aaa1d 100644 --- a/src/main/java/de/teamlapen/vampirism/items/HunterArmorItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/HunterArmorItem.java @@ -4,8 +4,10 @@ import de.teamlapen.vampirism.VampirismMod; import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.items.IFactionExclusiveItem; import de.teamlapen.vampirism.core.ModEffects; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.util.Helper; import net.minecraft.core.Holder; @@ -37,16 +39,15 @@ public void appendHoverText(@NotNull ItemStack stack, @Nullable TooltipContext c @Override - @Nullable - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.HUNTER_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.HUNTER; } @Override public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pSlotId, boolean pIsSelected) { if (pEntity.tickCount % 16 == 8 && pSlotId >= 36 && pSlotId <= 39 && pEntity instanceof Player player) { - IFaction f = VampirismPlayerAttributes.get(player).faction; - if (f != null && !VReference.HUNTER_FACTION.equals(f)) { + Holder> f = VampirismPlayerAttributes.get(player).faction; + if (f != null && !ModFactions.HUNTER.match(f)) { player.addEffect(new MobEffectInstance(ModEffects.POISON, 20, 1)); } } diff --git a/src/main/java/de/teamlapen/vampirism/items/HunterAxeItem.java b/src/main/java/de/teamlapen/vampirism/items/HunterAxeItem.java index e803f9a79a..faf5b83243 100644 --- a/src/main/java/de/teamlapen/vampirism/items/HunterAxeItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/HunterAxeItem.java @@ -3,6 +3,7 @@ import de.teamlapen.lib.lib.util.ModDisplayItemGenerator; import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.items.IItemWithTier; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.util.ToolMaterial; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; @@ -35,7 +36,7 @@ public HunterAxeItem(ToolMaterial.Tiered material) { @Override public void appendHoverText(@NotNull ItemStack stack, @Nullable TooltipContext context, @NotNull List tooltip, @NotNull TooltipFlag flagIn) { addTierInformation(tooltip); - tooltip.add(Component.translatable("text.vampirism.deals_more_damage_to", Math.round((getVampireMult() - 1) * 100), VReference.VAMPIRE_FACTION.getNamePlural()).withStyle(ChatFormatting.GRAY)); + tooltip.add(Component.translatable("text.vampirism.deals_more_damage_to", Math.round((getVampireMult() - 1) * 100), ModFactions.VAMPIRE.value().getNamePlural()).withStyle(ChatFormatting.GRAY)); super.appendHoverText(stack, context, tooltip, flagIn); } diff --git a/src/main/java/de/teamlapen/vampirism/items/HunterSwordItem.java b/src/main/java/de/teamlapen/vampirism/items/HunterSwordItem.java index 0f1257b0f7..061ea3770a 100755 --- a/src/main/java/de/teamlapen/vampirism/items/HunterSwordItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/HunterSwordItem.java @@ -9,6 +9,7 @@ import de.teamlapen.vampirism.api.items.IFactionLevelItem; import de.teamlapen.vampirism.api.items.IFactionSlayerItem; import de.teamlapen.vampirism.api.items.IVampireFinisher; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.util.ToolMaterial; import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; @@ -33,10 +34,9 @@ public void appendHoverText(@NotNull ItemStack stack, @Nullable TooltipContext c addFactionToolTips(stack, context, tooltip, flagIn, VampirismMod.proxy.getClientPlayer()); } - @Nullable @Override - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.HUNTER_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.HUNTER; } @Nullable @@ -46,7 +46,7 @@ public Holder> requiredSkill(@NotNull ItemStack stack) { } @Override - public IFaction getSlayedFaction() { - return VReference.VAMPIRE_FACTION; + public Holder> getSlayedFaction() { + return ModFactions.VAMPIRE; } } diff --git a/src/main/java/de/teamlapen/vampirism/items/MinionUpgradeItem.java b/src/main/java/de/teamlapen/vampirism/items/MinionUpgradeItem.java index a1d7727802..1171b577d9 100644 --- a/src/main/java/de/teamlapen/vampirism/items/MinionUpgradeItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/MinionUpgradeItem.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import net.minecraft.ChatFormatting; +import net.minecraft.core.Holder; import net.minecraft.network.chat.Component; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -15,9 +16,9 @@ public class MinionUpgradeItem extends Item { private final int minLevel; private final int maxLevel; - private final IFaction faction; + private final Holder> faction; - public MinionUpgradeItem(int minLevel, int maxLevel, IFaction faction) { + public MinionUpgradeItem(int minLevel, int maxLevel, Holder> faction) { super(new Item.Properties()); this.faction = faction; this.maxLevel = maxLevel; @@ -31,7 +32,7 @@ public void appendHoverText(@NotNull ItemStack stack, @Nullable TooltipContext c tooltip.add(Component.translatable("text.vampirism.for_to_levels", minLevel + 1, maxLevel + 1).withStyle(ChatFormatting.GRAY)); } - public IFaction getFaction() { + public Holder> getFaction() { return faction; } diff --git a/src/main/java/de/teamlapen/vampirism/items/PureBloodItem.java b/src/main/java/de/teamlapen/vampirism/items/PureBloodItem.java index c854ad6988..3e2f2dc6f7 100644 --- a/src/main/java/de/teamlapen/vampirism/items/PureBloodItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/PureBloodItem.java @@ -3,6 +3,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; import de.teamlapen.vampirism.core.ModEffects; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.entity.player.vampire.VampireLeveling; import de.teamlapen.vampirism.entity.player.vampire.VampirePlayer; @@ -91,7 +92,7 @@ public UseAnim getUseAnimation(@NotNull ItemStack stack) { @NotNull @Override public InteractionResultHolder use(@NotNull Level worldIn, @NotNull Player playerIn, @NotNull InteractionHand handIn) { - int playerLevel = VampirismAPI.factionPlayerHandler(playerIn).getCurrentLevel(VReference.VAMPIRE_FACTION); + int playerLevel = VampirismAPI.factionPlayerHandler(playerIn).getCurrentLevel(ModFactions.VAMPIRE); if (VampireLeveling.getInfusionRequirement(playerLevel).filter(x -> x.pureBloodLevel() < getLevel()).isPresent()) { playerIn.startUsingItem(handIn); return InteractionResultHolder.sidedSuccess(playerIn.getItemInHand(handIn), worldIn.isClientSide); diff --git a/src/main/java/de/teamlapen/vampirism/items/RefinementItem.java b/src/main/java/de/teamlapen/vampirism/items/RefinementItem.java index 607aceb707..5272a36a03 100644 --- a/src/main/java/de/teamlapen/vampirism/items/RefinementItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/RefinementItem.java @@ -57,8 +57,8 @@ public abstract class RefinementItem extends Item implements IRefinementItem, Mo return ItemStack.EMPTY; } - public static @Nullable IRefinementSet getRandomRefinementForItem(@Nullable IFaction faction, @NotNull IRefinementItem stack) { - List> sets = RegUtil.values(ModRegistries.REFINEMENT_SETS).stream().filter(set -> faction == null || set.getFaction() == faction).filter(set -> set.getSlotType().map(s -> s == stack.getSlotType()).orElse(true)).map(a -> ((RefinementSet) a).getWeightedRandom()).collect(Collectors.toList()); + public static @Nullable IRefinementSet getRandomRefinementForItem(@Nullable Holder> faction, @NotNull IRefinementItem stack) { + List> sets = RegUtil.values(ModRegistries.REFINEMENT_SETS).stream().filter(set -> faction == null || IFaction.is(set.getFaction(), faction)).filter(set -> set.getSlotType().map(s -> s == stack.getSlotType()).orElse(true)).map(a -> ((RefinementSet) a).getWeightedRandom()).collect(Collectors.toList()); if (sets.isEmpty()) return null; return WeightedRandom.getRandomItem(RANDOM, sets).map(WeightedEntry.Wrapper::data).orElse(null); } diff --git a/src/main/java/de/teamlapen/vampirism/items/StakeItem.java b/src/main/java/de/teamlapen/vampirism/items/StakeItem.java index f9fa6339ec..6a897b8383 100644 --- a/src/main/java/de/teamlapen/vampirism/items/StakeItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/StakeItem.java @@ -10,6 +10,7 @@ import de.teamlapen.vampirism.api.items.IVampireFinisher; import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModAdvancements; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModSounds; import de.teamlapen.vampirism.core.ModStats; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; @@ -33,7 +34,7 @@ public static boolean canKillInstant(@NotNull LivingEntity target, LivingEntity boolean instaKillLowHealth = false; if (attacker instanceof Player && attacker.isAlive()) { @Nullable IFactionPlayer factionPlayer = FactionPlayerHandler.getCurrentFactionPlayer((Player) attacker).orElse(null); - if (factionPlayer != null && factionPlayer.getFaction().equals(VReference.HUNTER_FACTION)) { + if (factionPlayer != null && ModFactions.HUNTER.match(factionPlayer.getFaction())) { ISkillHandler skillHandler = factionPlayer.getSkillHandler(); if (skillHandler.isSkillEnabled(HunterSkills.STAKE1)) { instaKillLowHealth = true; diff --git a/src/main/java/de/teamlapen/vampirism/items/VampireClothingItem.java b/src/main/java/de/teamlapen/vampirism/items/VampireClothingItem.java index 4babcac61b..896601b2ff 100644 --- a/src/main/java/de/teamlapen/vampirism/items/VampireClothingItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/VampireClothingItem.java @@ -2,13 +2,12 @@ import de.teamlapen.lib.lib.util.UtilLib; import de.teamlapen.vampirism.VampirismMod; -import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.api.VampirismAPI; import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.items.IFactionExclusiveItem; import de.teamlapen.vampirism.client.extensions.ItemExtensions; -import de.teamlapen.vampirism.core.ModArmorMaterials; import de.teamlapen.vampirism.core.ModEffects; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; import de.teamlapen.vampirism.util.Helper; import net.minecraft.core.Holder; @@ -54,10 +53,9 @@ public boolean canEquip(ItemStack stack, EquipmentSlot armorType, Entity entity) return super.canEquip(stack, armorType, entity) && Helper.isVampire(entity); } - @Nullable @Override - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.VAMPIRE_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.VAMPIRE; } @Override diff --git a/src/main/java/de/teamlapen/vampirism/items/VampireRefinementItem.java b/src/main/java/de/teamlapen/vampirism/items/VampireRefinementItem.java index cf1c8c02c3..d3904fb5fb 100644 --- a/src/main/java/de/teamlapen/vampirism/items/VampireRefinementItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/VampireRefinementItem.java @@ -1,8 +1,10 @@ package de.teamlapen.vampirism.items; import de.teamlapen.vampirism.api.VReference; -import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModItems; +import net.minecraft.core.Holder; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; @@ -12,10 +14,9 @@ public VampireRefinementItem(@NotNull Properties properties, AccessorySlotType t super(properties, type); } - @NotNull @Override - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.VAMPIRE_FACTION; + public Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.VAMPIRE; } public static @NotNull RefinementItem getItemForType(@NotNull AccessorySlotType type) { diff --git a/src/main/java/de/teamlapen/vampirism/items/VampireSwordItem.java b/src/main/java/de/teamlapen/vampirism/items/VampireSwordItem.java index 53414241a0..ae8c186021 100644 --- a/src/main/java/de/teamlapen/vampirism/items/VampireSwordItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/VampireSwordItem.java @@ -13,6 +13,7 @@ import de.teamlapen.vampirism.api.items.IItemWithTier; import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModDataComponents; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModParticles; import de.teamlapen.vampirism.core.ModRefinements; import de.teamlapen.vampirism.core.tags.ModEntityTags; @@ -109,10 +110,9 @@ public void doNotName(@NotNull ItemStack stack) { stack.set(ModDataComponents.DO_NOT_NAME, Unit.INSTANCE); } - @Nullable @Override - public IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.VAMPIRE_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.VAMPIRE; } @Override @@ -135,7 +135,7 @@ public int getUseDuration(@NotNull ItemStack stack) { @Override public ItemStack finishUsingItem(@NotNull ItemStack stack, @NotNull Level worldIn, @NotNull LivingEntity entityLiving) { if (!(entityLiving instanceof Player)) return stack; - VReference.VAMPIRE_FACTION.getPlayerCapability((Player) entityLiving).ifPresent(vampire -> { + ModFactions.VAMPIRE.value().getPlayerCapability((Player) entityLiving).ifPresent(vampire -> { int amount = (vampire.getSkillHandler().isRefinementEquipped(ModRefinements.BLOOD_CHARGE_SPEED) ? VampirismConfig.BALANCE.vrBloodChargeSpeedMod.get() : 2); if (((Player) entityLiving).isCreative() || vampire.useBlood(amount, false)) { this.charge(stack, amount * VReference.FOOD_TO_FLUID_BLOOD); diff --git a/src/main/java/de/teamlapen/vampirism/items/crossbow/HunterCrossbowItem.java b/src/main/java/de/teamlapen/vampirism/items/crossbow/HunterCrossbowItem.java index 0eaa7a6fd1..3a6d64ceca 100644 --- a/src/main/java/de/teamlapen/vampirism/items/crossbow/HunterCrossbowItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/crossbow/HunterCrossbowItem.java @@ -8,6 +8,7 @@ import de.teamlapen.vampirism.api.items.*; import de.teamlapen.vampirism.core.ModDataComponents; import de.teamlapen.vampirism.client.extensions.ItemExtensions; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.items.component.SelectedAmmunition; import de.teamlapen.vampirism.entity.player.hunter.HunterPlayer; import de.teamlapen.vampirism.entity.player.hunter.skills.HunterSkills; @@ -43,7 +44,6 @@ import java.util.function.Consumer; import java.util.*; import java.util.function.Predicate; -import java.util.function.Supplier; public abstract class HunterCrossbowItem extends CrossbowItem implements IFactionLevelItem, IHunterCrossbow { @@ -103,8 +103,8 @@ public int getMinLevel(@NotNull ItemStack stack) { } @Override - public @Nullable IFaction getExclusiveFaction(@NotNull ItemStack stack) { - return VReference.HUNTER_FACTION; + public @Nullable Holder> getExclusiveFaction(@NotNull ItemStack stack) { + return ModFactions.HUNTER; } @NotNull diff --git a/src/main/java/de/teamlapen/vampirism/modcompat/guide/GuideBook.java b/src/main/java/de/teamlapen/vampirism/modcompat/guide/GuideBook.java index 338dd3896b..26dd4c1523 100755 --- a/src/main/java/de/teamlapen/vampirism/modcompat/guide/GuideBook.java +++ b/src/main/java/de/teamlapen/vampirism/modcompat/guide/GuideBook.java @@ -241,14 +241,14 @@ private static Component loc(@NotNull Item i) { entries.put(new ResourceLocation(base + "dbno"), new EntryText(dbnoPages, translateComponent(base + "dbno"))); List lordPages = new ArrayList<>(); - lordPages.addAll(helper.addLinks(PageHelper.pagesForLongText(translateComponent(base + "lord.text", ModEntities.TASK_MASTER_VAMPIRE.get().getDescription().getString(), VReference.VAMPIRE_FACTION.getLordTitle(1, IPlayableFaction.TitleGender.MALE).getString(), VReference.VAMPIRE_FACTION.getLordTitle(1, IPlayableFaction.TitleGender.FEMALE).getString(), VReference.VAMPIRE_FACTION.getLordTitle(VReference.VAMPIRE_FACTION.getHighestLordLevel(), IPlayableFaction.TitleGender.MALE).getString(), VReference.VAMPIRE_FACTION.getLordTitle(VReference.VAMPIRE_FACTION.getHighestLordLevel(), IPlayableFaction.TitleGender.FEMALE).getString())), new ResourceLocation("guide.vampirism.entity.taskmaster"))); + lordPages.addAll(helper.addLinks(PageHelper.pagesForLongText(translateComponent(base + "lord.text", ModEntities.TASK_MASTER_VAMPIRE.get().getDescription().getString(), ModFactions.VAMPIRE.value().getLordTitle(1, IPlayableFaction.TitleGender.MALE).getString(), ModFactions.VAMPIRE.value().getLordTitle(1, IPlayableFaction.TitleGender.FEMALE).getString(), ModFactions.VAMPIRE.value().getLordTitle(ModFactions.VAMPIRE.value().getHighestLordLevel(), IPlayableFaction.TitleGender.MALE).getString(), ModFactions.VAMPIRE.value().getLordTitle(ModFactions.VAMPIRE.value().getHighestLordLevel(), IPlayableFaction.TitleGender.FEMALE).getString())), new ResourceLocation("guide.vampirism.entity.taskmaster"))); PageTable.Builder lordTitleBuilder = new PageTable.Builder(3).setHeadline(translateComponent(base + "lord.titles")); lordTitleBuilder.addLine(Component.translatable("text.vampirism.level"), Component.translatable("text.vampirism.title"), Component.translatable("text.vampirism.title")); - lordTitleBuilder.addLine(1, VReference.VAMPIRE_FACTION.getLordTitle(1, IPlayableFaction.TitleGender.MALE).getString(), VReference.VAMPIRE_FACTION.getLordTitle(1, IPlayableFaction.TitleGender.FEMALE).getString()); - lordTitleBuilder.addLine(2, VReference.VAMPIRE_FACTION.getLordTitle(2, IPlayableFaction.TitleGender.MALE).getString(), VReference.VAMPIRE_FACTION.getLordTitle(2, IPlayableFaction.TitleGender.FEMALE).getString()); - lordTitleBuilder.addLine(3, VReference.VAMPIRE_FACTION.getLordTitle(3, IPlayableFaction.TitleGender.MALE).getString(), VReference.VAMPIRE_FACTION.getLordTitle(3, IPlayableFaction.TitleGender.FEMALE).getString()); - lordTitleBuilder.addLine(4, VReference.VAMPIRE_FACTION.getLordTitle(4, IPlayableFaction.TitleGender.MALE).getString(), VReference.VAMPIRE_FACTION.getLordTitle(4, IPlayableFaction.TitleGender.FEMALE).getString()); - lordTitleBuilder.addLine(5, VReference.VAMPIRE_FACTION.getLordTitle(5, IPlayableFaction.TitleGender.MALE).getString(), VReference.VAMPIRE_FACTION.getLordTitle(5, IPlayableFaction.TitleGender.FEMALE).getString()); + lordTitleBuilder.addLine(1, ModFactions.VAMPIRE.value().getLordTitle(1, IPlayableFaction.TitleGender.MALE).getString(), ModFactions.VAMPIRE.value().getLordTitle(1, IPlayableFaction.TitleGender.FEMALE).getString()); + lordTitleBuilder.addLine(2, ModFactions.VAMPIRE.value().getLordTitle(2, IPlayableFaction.TitleGender.MALE).getString(), ModFactions.VAMPIRE.value().getLordTitle(2, IPlayableFaction.TitleGender.FEMALE).getString()); + lordTitleBuilder.addLine(3, ModFactions.VAMPIRE.value().getLordTitle(3, IPlayableFaction.TitleGender.MALE).getString(), ModFactions.VAMPIRE.value().getLordTitle(3, IPlayableFaction.TitleGender.FEMALE).getString()); + lordTitleBuilder.addLine(4, ModFactions.VAMPIRE.value().getLordTitle(4, IPlayableFaction.TitleGender.MALE).getString(), ModFactions.VAMPIRE.value().getLordTitle(4, IPlayableFaction.TitleGender.FEMALE).getString()); + lordTitleBuilder.addLine(5, ModFactions.VAMPIRE.value().getLordTitle(5, IPlayableFaction.TitleGender.MALE).getString(), ModFactions.VAMPIRE.value().getLordTitle(5, IPlayableFaction.TitleGender.FEMALE).getString()); lordPages.add(lordTitleBuilder.build()); lordPages.addAll(helper.addLinks(PageHelper.pagesForLongText(translateComponent(base + "lord.minion", loc(ModItems.VAMPIRE_MINION_BINDING.get()), loc(ModItems.VAMPIRE_MINION_UPGRADE_SIMPLE.get()), loc(ModItems.VAMPIRE_MINION_UPGRADE_ENHANCED.get()), loc(ModItems.VAMPIRE_MINION_UPGRADE_SPECIAL.get()))), new ResourceLocation("guide.vampirism.items.vampire_minion_binding"))); lordPages.addAll(helper.addLinks(PageHelper.pagesForLongText(translateComponent("guide.vampirism.common.minion_control", ModKeys.MINION.getTranslatedKeyMessage(), translate("text.vampirism.minion.call_single"), translate("text.vampirism.minion.respawn"))))); @@ -337,15 +337,15 @@ private static Component loc(@NotNull Item i) { entries.put(new ResourceLocation(base + "vamp_slayer"), new EntryText(vampSlayerPages, translateComponent(base + "vamp_slayer"))); List lordPages = new ArrayList<>(); - lordPages.addAll(helper.addLinks(PageHelper.pagesForLongText(translateComponent(base + "lord.text", ModEntities.TASK_MASTER_HUNTER.get().getDescription().getString(), VReference.HUNTER_FACTION.getLordTitle(1, IPlayableFaction.TitleGender.MALE).getString(), VReference.HUNTER_FACTION.getLordTitle(VReference.HUNTER_FACTION.getHighestLordLevel(), IPlayableFaction.TitleGender.MALE).getString())), new ResourceLocation("guide.vampirism.entity.taskmaster"))); + lordPages.addAll(helper.addLinks(PageHelper.pagesForLongText(translateComponent(base + "lord.text", ModEntities.TASK_MASTER_HUNTER.get().getDescription().getString(), ModFactions.HUNTER.value().getLordTitle(1, IPlayableFaction.TitleGender.MALE).getString(), ModFactions.HUNTER.value().getLordTitle(ModFactions.HUNTER.value().getHighestLordLevel(), IPlayableFaction.TitleGender.MALE).getString())), new ResourceLocation("guide.vampirism.entity.taskmaster"))); PageTable.Builder lordTitleBuilder = new PageTable.Builder(2); lordTitleBuilder.setHeadline(translateComponent(base + "lord.titles")); lordTitleBuilder.addLine(Component.translatable("text.vampirism.level"), "text.vampirism.title"); - lordTitleBuilder.addLine(1, VReference.HUNTER_FACTION.getLordTitle(1, IPlayableFaction.TitleGender.MALE).getString()); - lordTitleBuilder.addLine(2, VReference.HUNTER_FACTION.getLordTitle(2, IPlayableFaction.TitleGender.MALE).getString()); - lordTitleBuilder.addLine(3, VReference.HUNTER_FACTION.getLordTitle(3, IPlayableFaction.TitleGender.MALE).getString()); - lordTitleBuilder.addLine(4, VReference.HUNTER_FACTION.getLordTitle(4, IPlayableFaction.TitleGender.MALE).getString()); - lordTitleBuilder.addLine(5, VReference.HUNTER_FACTION.getLordTitle(5, IPlayableFaction.TitleGender.MALE).getString()); + lordTitleBuilder.addLine(1, ModFactions.HUNTER.value().getLordTitle(1, IPlayableFaction.TitleGender.MALE).getString()); + lordTitleBuilder.addLine(2, ModFactions.HUNTER.value().getLordTitle(2, IPlayableFaction.TitleGender.MALE).getString()); + lordTitleBuilder.addLine(3, ModFactions.HUNTER.value().getLordTitle(3, IPlayableFaction.TitleGender.MALE).getString()); + lordTitleBuilder.addLine(4, ModFactions.HUNTER.value().getLordTitle(4, IPlayableFaction.TitleGender.MALE).getString()); + lordTitleBuilder.addLine(5, ModFactions.HUNTER.value().getLordTitle(5, IPlayableFaction.TitleGender.MALE).getString()); lordPages.add(lordTitleBuilder.build()); lordPages.addAll(helper.addLinks(PageHelper.pagesForLongText(translateComponent(base + "lord.minion", loc(ModItems.HUNTER_MINION_EQUIPMENT.get()), loc(ModItems.HUNTER_MINION_UPGRADE_SIMPLE.get()), loc(ModItems.HUNTER_MINION_UPGRADE_ENHANCED.get()), loc(ModItems.HUNTER_MINION_UPGRADE_SPECIAL.get()))), new ResourceLocation("guide.vampirism.items.hunter_minion_equipment"))); lordPages.addAll(helper.addLinks(PageHelper.pagesForLongText(translateComponent("guide.vampirism.common.minion_control", ModKeys.MINION.getTranslatedKeyMessage(), translate("text.vampirism.minion.call_single"), translate("text.vampirism.minion.respawn"))))); diff --git a/src/main/java/de/teamlapen/vampirism/modcompat/guide/pages/PageTaskItemStack.java b/src/main/java/de/teamlapen/vampirism/modcompat/guide/pages/PageTaskItemStack.java index d250c92241..00a4aaf2c1 100644 --- a/src/main/java/de/teamlapen/vampirism/modcompat/guide/pages/PageTaskItemStack.java +++ b/src/main/java/de/teamlapen/vampirism/modcompat/guide/pages/PageTaskItemStack.java @@ -10,6 +10,7 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.player.task.Task; import de.teamlapen.vampirism.api.entity.player.task.TaskUnlocker; +import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.core.tags.ModTaskTags; import de.teamlapen.vampirism.entity.player.tasks.reward.ItemReward; import net.minecraft.client.gui.Font; @@ -45,7 +46,7 @@ private void setupTask(RegistryAccess access) { List text = new ArrayList<>(); Component newLine = Component.literal("\n"); if (holder.is(ModTaskTags.HAS_FACTION)) { - text.add(Component.translatable("text.vampirism.task.reward_obtain_for", String.join(", ", Arrays.stream(VampirismAPI.factionRegistry().getFactions()).filter(x -> x.getTag(VampirismRegistries.Keys.TASK).filter(holder::is).isPresent()).map(IFaction::getNamePlural).map(Component::getString).toList()) + " ")); + text.add(Component.translatable("text.vampirism.task.reward_obtain_for", String.join(", ", ModRegistries.FACTIONS.stream().filter(x -> x.getTag(VampirismRegistries.Keys.TASK).filter(holder::is).isPresent()).map(IFaction::getNamePlural).map(Component::getString).toList()) + " ")); } else { text.add(Component.translatable("text.vampirism.task.reward_obtain_all")); } diff --git a/src/main/java/de/teamlapen/vampirism/modcompat/jei/TaskRecipeCategory.java b/src/main/java/de/teamlapen/vampirism/modcompat/jei/TaskRecipeCategory.java index 16e338cc46..1784463f39 100644 --- a/src/main/java/de/teamlapen/vampirism/modcompat/jei/TaskRecipeCategory.java +++ b/src/main/java/de/teamlapen/vampirism/modcompat/jei/TaskRecipeCategory.java @@ -9,6 +9,7 @@ import de.teamlapen.vampirism.api.entity.player.task.TaskReward; import de.teamlapen.vampirism.api.entity.player.task.TaskUnlocker; import de.teamlapen.vampirism.core.ModItems; +import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.entity.player.tasks.reward.ItemReward; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; @@ -51,7 +52,7 @@ public void draw(@NotNull Task task, @NotNull IRecipeSlotsView recipeSlotsView, int y = 40; graphics.drawString(minecraft.font, task.getTitle(), 1, 1, Color.GRAY.getRGB(), false); Registry tasks = minecraft.level.registryAccess().registryOrThrow(VampirismRegistries.Keys.TASK); - Component taskmasterComponent = Arrays.stream(VampirismAPI.factionRegistry().getFactions()).filter(s -> s.getTag(VampirismRegistries.Keys.TASK).filter(t -> tasks.wrapAsHolder(task).is(t)).isPresent()).map(a -> a.getVillageData().getTaskMasterEntity()).filter(Objects::nonNull).map(EntityType::getDescriptionId).map(Component::translatable).reduce((comp1, comp2) -> comp1.append(", ").append(comp2)).orElse(Component.translatable("text.vampirism.faction_representative")); + Component taskmasterComponent = ModRegistries.FACTIONS.stream().filter(s -> s.getTag(VampirismRegistries.Keys.TASK).filter(t -> tasks.wrapAsHolder(task).is(t)).isPresent()).map(a -> a.getVillageData().getTaskMasterEntity()).filter(Objects::nonNull).map(EntityType::getDescriptionId).map(Component::translatable).reduce((comp1, comp2) -> comp1.append(", ").append(comp2)).orElse(Component.translatable("text.vampirism.faction_representative")); Component text = Component.translatable("text.vampirism.task.reward_obtain", taskmasterComponent); y += UtilLib.renderMultiLine(minecraft.font, graphics, text, 160, x, y, Color.GRAY.getRGB()); diff --git a/src/main/java/de/teamlapen/vampirism/modcompat/jei/VampirismJEIPlugin.java b/src/main/java/de/teamlapen/vampirism/modcompat/jei/VampirismJEIPlugin.java index 25d2bbf4fe..8f30eae689 100755 --- a/src/main/java/de/teamlapen/vampirism/modcompat/jei/VampirismJEIPlugin.java +++ b/src/main/java/de/teamlapen/vampirism/modcompat/jei/VampirismJEIPlugin.java @@ -223,7 +223,7 @@ public void registerVanillaCategoryExtensions(@NotNull IVanillaCategoryExtension .map(s -> (Holder )(Object)s) .flatMap(oil -> BuiltInRegistries.ITEM.stream() .map(Item::getDefaultInstance) - .filter(item -> (!(item.getItem() instanceof IFactionExclusiveItem) || ((IFactionExclusiveItem) item.getItem()).getExclusiveFaction(item) == VReference.HUNTER_FACTION)) + .filter(item -> (!(item.getItem() instanceof IFactionExclusiveItem) || ModFactions.HUNTER.match(((IFactionExclusiveItem) item.getItem()).getExclusiveFaction(item)))) .filter(item -> oil.value().canBeApplied(item)) .map(stack -> new RecipeHolder(new ResourceLocation(REFERENCE.MODID, (oil.unwrapKey().get().toString() + RegUtil.id(stack.getItem())).replace(':', '_')), new ShapelessRecipe( "", CraftingBookCategory.EQUIPMENT, AppliedOilContent.apply(stack.copy(), oil), NonNullList.of(Ingredient.EMPTY, Ingredient.of(stack), Ingredient.of(OilContent.createItemStack(ModItems.OIL_BOTTLE.get(), oil))))))).toList(); } diff --git a/src/main/java/de/teamlapen/vampirism/recipes/ApplicableOilRecipe.java b/src/main/java/de/teamlapen/vampirism/recipes/ApplicableOilRecipe.java index 2e73811dc7..af70c04bc0 100644 --- a/src/main/java/de/teamlapen/vampirism/recipes/ApplicableOilRecipe.java +++ b/src/main/java/de/teamlapen/vampirism/recipes/ApplicableOilRecipe.java @@ -5,6 +5,7 @@ import de.teamlapen.vampirism.api.items.IOilItem; import de.teamlapen.vampirism.api.items.oil.IApplicableOil; import de.teamlapen.vampirism.api.items.oil.IOil; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.ModRecipes; import de.teamlapen.vampirism.items.component.AppliedOilContent; import de.teamlapen.vampirism.items.component.OilContent; @@ -43,7 +44,7 @@ public boolean matches(@NotNull CraftingContainer inventory, @NotNull Level worl } } } - return oil != null && tool != null && (!(tool.getItem() instanceof IFactionExclusiveItem) || ((IFactionExclusiveItem) tool.getItem()).getExclusiveFaction(tool) == VReference.HUNTER_FACTION) && oil.canBeApplied(tool); + return oil != null && tool != null && (!(tool.getItem() instanceof IFactionExclusiveItem) || ModFactions.HUNTER.match(((IFactionExclusiveItem) tool.getItem()).getExclusiveFaction(tool))) && oil.canBeApplied(tool); } @NotNull diff --git a/src/main/java/de/teamlapen/vampirism/util/FactionCodec.java b/src/main/java/de/teamlapen/vampirism/util/FactionCodec.java index 7694b8f276..d66139fb3d 100644 --- a/src/main/java/de/teamlapen/vampirism/util/FactionCodec.java +++ b/src/main/java/de/teamlapen/vampirism/util/FactionCodec.java @@ -2,6 +2,8 @@ import com.mojang.serialization.Codec; import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; import de.teamlapen.vampirism.api.entity.player.actions.IAction; import de.teamlapen.vampirism.api.entity.player.skills.ISkill; @@ -36,4 +38,12 @@ public static > StreamCodec> Codec> actionCodec() { return ModRegistries.ACTIONS.byNameCodec().xmap(s -> (IAction) s, s -> s); } + + public static Codec>> playable() { + return ModRegistries.FACTIONS.holderByNameCodec().xmap(s -> (Holder>) (Object) s, s -> (Holder>) (Object) s); + } + + public static Codec>> faction() { + return ModRegistries.FACTIONS.holderByNameCodec().xmap(s -> (Holder>) (Object) s, s -> (Holder>) (Object) s); + } } diff --git a/src/main/java/de/teamlapen/vampirism/util/Helper.java b/src/main/java/de/teamlapen/vampirism/util/Helper.java index 23aa0a20b3..d6a564fc1a 100644 --- a/src/main/java/de/teamlapen/vampirism/util/Helper.java +++ b/src/main/java/de/teamlapen/vampirism/util/Helper.java @@ -16,9 +16,12 @@ import de.teamlapen.vampirism.api.items.IFactionLevelItem; import de.teamlapen.vampirism.api.items.IVampireFinisher; import de.teamlapen.vampirism.config.VampirismConfig; +import de.teamlapen.vampirism.core.ModFactions; import de.teamlapen.vampirism.core.tags.ModBiomeTags; import de.teamlapen.vampirism.core.tags.ModDamageTypeTags; +import de.teamlapen.vampirism.core.tags.ModFactionTags; import de.teamlapen.vampirism.entity.CrossbowArrowEntity; +import de.teamlapen.vampirism.entity.factions.Faction; import de.teamlapen.vampirism.entity.factions.FactionPlayerHandler; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.items.StakeItem; @@ -127,7 +130,7 @@ public static ResourceKey getWorldKey(LevelAccessor world) { } public static boolean canBecomeVampire(@NotNull Player player) { - return FactionPlayerHandler.get(player).canJoin(VReference.VAMPIRE_FACTION); + return FactionPlayerHandler.get(player).canJoin(ModFactions.VAMPIRE); } public static boolean canTurnPlayer(IVampire biter, @Nullable Player target) { @@ -146,19 +149,19 @@ public static boolean canTurnPlayer(IVampire biter, @Nullable Player target) { * @return If the given entity is a vampire (Either a player in the vampire faction or a vampire entity */ public static boolean isVampire(Entity entity) { - return VReference.VAMPIRE_FACTION.equals(VampirismAPI.factionRegistry().getFaction(entity)); + return IFaction.is(ModFactions.VAMPIRE, VampirismAPI.factionRegistry().getFactionHolder(entity)); } public static boolean isHunter(Entity entity) { - return VReference.HUNTER_FACTION.equals(VampirismAPI.factionRegistry().getFaction(entity)); + return IFaction.is(ModFactions.HUNTER, VampirismAPI.factionRegistry().getFactionHolder(entity)); } public static boolean isHunter(@NotNull Player entity) { - return VReference.HUNTER_FACTION.equals(VampirismPlayerAttributes.get(entity).faction); + return IFaction.is(ModFactions.HUNTER, VampirismPlayerAttributes.get(entity).faction); } public static boolean isVampire(Player entity) { - return VReference.VAMPIRE_FACTION.equals(VampirismPlayerAttributes.get(entity).faction); + return IFaction.is(ModFactions.VAMPIRE, VampirismPlayerAttributes.get(entity).faction); } public static boolean appearsAsVampire(Entity entity, Entity viewer) { @@ -170,11 +173,11 @@ public static boolean appearsAsVampire(Entity entity, Entity viewer) { } public static boolean appearsAsVampire(Player player, Entity viewer) { - return VReference.VAMPIRE_FACTION == viewedFaction(player, viewer); + return IFaction.is(ModFactions.VAMPIRE, viewedFaction(player, viewer)); } - public static IPlayableFaction viewedFaction(Player player, Entity viewer) { - return FactionPlayerHandler.getCurrentFactionPlayer(player).map(IFactionPlayer::getDisguise).map(s -> s.getViewedFaction(VampirismAPI.factionRegistry().getFaction(viewer))).orElse(null); + public static Holder> viewedFaction(Player player, Entity viewer) { + return FactionPlayerHandler.getCurrentFactionPlayer(player).map(IFactionPlayer::getDisguise).map(s -> s.getViewedFaction(VampirismAPI.factionRegistry().getFactionHolder(viewer))).orElse(null); } /** @@ -229,7 +232,7 @@ public static ResourceLocation getBiomeId(@NotNull CommonLevelAccessor world, @N * Checks if the given {@link IFactionLevelItem} can be used by the given player */ public static > boolean canUseFactionItem(@NotNull ItemStack stack, @NotNull IFactionLevelItem item, @NotNull IFactionPlayerHandler playerHandler) { - IFaction usingFaction = item.getExclusiveFaction(stack); + Holder> usingFaction = item.getExclusiveFaction(stack); Holder> requiredSkill = item.requiredSkill(stack); int reqLevel = item.getMinLevel(stack); if (usingFaction != null && !playerHandler.isInFaction(usingFaction)) return false; diff --git a/src/main/java/de/teamlapen/vampirism/util/RegUtil.java b/src/main/java/de/teamlapen/vampirism/util/RegUtil.java index aa2aad2aab..0144b0dc6b 100644 --- a/src/main/java/de/teamlapen/vampirism/util/RegUtil.java +++ b/src/main/java/de/teamlapen/vampirism/util/RegUtil.java @@ -1,6 +1,9 @@ package de.teamlapen.vampirism.util; import de.teamlapen.vampirism.api.VampirismRegistries; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.entity.factions.IFactionPlayerHandler; +import de.teamlapen.vampirism.api.entity.factions.IPlayableFaction; import de.teamlapen.vampirism.api.entity.factions.ISkillTree; import de.teamlapen.vampirism.api.entity.minion.IMinionTask; import de.teamlapen.vampirism.api.entity.player.IFactionPlayer; @@ -189,4 +192,14 @@ public static > Holder> holder(IAction public static > Holder> holder(ILastingAction action) { return (Holder>) (Object) ModRegistries.ACTIONS.wrapAsHolder(action); } + + @SuppressWarnings("unchecked") + public static Holder> holder(IPlayableFaction faction) { + return (Holder>) (Object) ModRegistries.FACTIONS.wrapAsHolder(faction); + } + + @SuppressWarnings("unchecked") + public static > Holder holder(T faction) { + return (Holder) ModRegistries.FACTIONS.wrapAsHolder(faction); + } } diff --git a/src/main/java/de/teamlapen/vampirism/util/TotemHelper.java b/src/main/java/de/teamlapen/vampirism/util/TotemHelper.java index 01d5aea497..4a5464cff8 100644 --- a/src/main/java/de/teamlapen/vampirism/util/TotemHelper.java +++ b/src/main/java/de/teamlapen/vampirism/util/TotemHelper.java @@ -8,6 +8,7 @@ import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.tags.ModPoiTypeTags; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceKey; @@ -211,7 +212,7 @@ public static Optional getTotemNearPos(@NotNull ServerLevel wo * @param player the player that requests the faction * @return the feedback for the player */ - public static @NotNull Component forceFactionCommand(@Nullable IFaction faction, @NotNull ServerPlayer player) { + public static @NotNull Component forceFactionCommand(@Nullable Holder> faction, @NotNull ServerPlayer player) { Map totemPositions = TotemHelper.totemPositions.computeIfAbsent(player.getCommandSenderWorld().dimension(), key -> new HashMap<>()); List pointOfInterests = ((ServerLevel) player.getCommandSenderWorld()).getPoiManager().getInRange(point -> true, player.blockPosition(), 25, PoiManager.Occupancy.ANY).sorted(Comparator.comparingInt(point -> (int) (point.getPos()).distSqr(player.blockPosition()))).toList(); if (pointOfInterests.stream().noneMatch(point -> totemPositions.containsKey(point.getPos()))) { @@ -223,7 +224,7 @@ public static Optional getTotemNearPos(@NotNull ServerLevel wo return Component.literal(""); } tile.setForcedFaction(faction); - return Component.translatable("command.vampirism.test.village.success", faction == null ? "none" : faction.getName()); + return Component.translatable("command.vampirism.test.village.success", faction == null ? "none" : faction.value().getName()); } /** diff --git a/src/main/java/de/teamlapen/vampirism/util/VampirismEventFactory.java b/src/main/java/de/teamlapen/vampirism/util/VampirismEventFactory.java index 0d2fd62629..fb1f240bd5 100644 --- a/src/main/java/de/teamlapen/vampirism/util/VampirismEventFactory.java +++ b/src/main/java/de/teamlapen/vampirism/util/VampirismEventFactory.java @@ -44,20 +44,20 @@ public static void fireVillagerCaptureEventPost(@NotNull ITotem totem, @NotNull return event.getNewVillager(); } - public static PlayerFactionEvent.CanJoinFaction.Behavior fireCanJoinFactionEvent(@NotNull IFactionPlayerHandler playerHandler, @Nullable IPlayableFaction currentFaction, IPlayableFaction newFaction) { - PlayerFactionEvent.CanJoinFaction event = new PlayerFactionEvent.CanJoinFaction(playerHandler, currentFaction, newFaction); + public static PlayerFactionEvent.CanJoinFaction.Behavior fireCanJoinFactionEvent(@NotNull IFactionPlayerHandler playerHandler, @Nullable Holder> currentFaction, Holder> newFaction) { + PlayerFactionEvent.CanJoinFaction event = new PlayerFactionEvent.CanJoinFaction(playerHandler, (Holder>) currentFaction, (Holder>) newFaction); NeoForge.EVENT_BUS.post(event); return event.getBehavior(); } - public static boolean fireChangeLevelOrFactionEvent(@NotNull IFactionPlayerHandler player, @Nullable IPlayableFaction currentFaction, int currentLevel, @Nullable IPlayableFaction newFaction, int newLevel) { - PlayerFactionEvent.FactionLevelChangePre event = new PlayerFactionEvent.FactionLevelChangePre(player, currentFaction, currentLevel, newFaction, newLevel); + public static boolean fireChangeLevelOrFactionEvent(@NotNull IFactionPlayerHandler player, @Nullable Holder> currentFaction, int currentLevel, @Nullable Holder> newFaction, int newLevel) { + PlayerFactionEvent.FactionLevelChangePre event = new PlayerFactionEvent.FactionLevelChangePre(player, (Holder>) currentFaction, currentLevel,(Holder>) newFaction, newLevel); NeoForge.EVENT_BUS.post(event); return event.isCanceled(); } - public static void fireFactionLevelChangedEvent(@NotNull IFactionPlayerHandler player, @Nullable IPlayableFaction oldFaction, int oldLevel, @Nullable IPlayableFaction newFaction, int newLevel) { - PlayerFactionEvent.FactionLevelChanged event = new PlayerFactionEvent.FactionLevelChanged(player, oldFaction, oldLevel, newFaction, newLevel); + public static void fireFactionLevelChangedEvent(@NotNull IFactionPlayerHandler player, @Nullable Holder> oldFaction, int oldLevel, @Nullable Holder> newFaction, int newLevel) { + PlayerFactionEvent.FactionLevelChanged event = new PlayerFactionEvent.FactionLevelChanged(player, (Holder>) oldFaction, oldLevel, (Holder>) newFaction, newLevel); NeoForge.EVENT_BUS.post(event); } diff --git a/src/main/java/de/teamlapen/vampirism/world/MinionWorldData.java b/src/main/java/de/teamlapen/vampirism/world/MinionWorldData.java index d855f7f560..f5dc01544a 100644 --- a/src/main/java/de/teamlapen/vampirism/world/MinionWorldData.java +++ b/src/main/java/de/teamlapen/vampirism/world/MinionWorldData.java @@ -65,7 +65,7 @@ public PlayerMinionController getOrCreateController(@NotNull FactionPlayerHandle return controllers.get(id); } else { PlayerMinionController c = new PlayerMinionController(server, id); - c.setMaxMinions(lord.getCurrentFaction(), lord.getMaxMinions()); + c.setMaxMinions(lord.getFaction(), lord.getMaxMinions()); controllers.put(id, c); return c; } diff --git a/src/main/java/de/teamlapen/vampirism/world/loot/conditions/FactionCondition.java b/src/main/java/de/teamlapen/vampirism/world/loot/conditions/FactionCondition.java index a41b44614d..effe50ada5 100644 --- a/src/main/java/de/teamlapen/vampirism/world/loot/conditions/FactionCondition.java +++ b/src/main/java/de/teamlapen/vampirism/world/loot/conditions/FactionCondition.java @@ -7,6 +7,8 @@ import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.factions.IFactionPlayerHandler; import de.teamlapen.vampirism.core.ModLoot; +import de.teamlapen.vampirism.core.ModRegistries; +import net.minecraft.core.Holder; import net.minecraft.util.StringRepresentable; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -21,27 +23,28 @@ @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public class FactionCondition implements LootItemCondition { + @SuppressWarnings("unchecked") public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(inst -> inst.group( StringRepresentable.fromEnum(Type::values).fieldOf("type").forGetter(s -> s.type), - IFaction.CODEC.optionalFieldOf("faction").forGetter(a -> a.faction), + ModRegistries.FACTIONS.holderByNameCodec().optionalFieldOf("faction").forGetter(a -> (Optional>>) (Object) a.faction), Codec.INT.optionalFieldOf( "min_level").forGetter(a -> a.minLevel), Codec.INT.optionalFieldOf( "max_level").forGetter(a -> a.maxLevel) ).apply(inst, FactionCondition::new)); private final @NotNull Type type; - private final Optional> faction; + private final Optional>> faction; private final Optional minLevel; private final Optional maxLevel; - @SuppressWarnings("OptionalUsedAsFieldOrParameterType") - private FactionCondition(@NotNull Type type, Optional> faction, Optional minLevel, Optional maxLevel) { + @SuppressWarnings({"OptionalUsedAsFieldOrParameterType", "unchecked"}) + private FactionCondition(@NotNull Type type, Optional>> faction, Optional minLevel, Optional maxLevel) { this.type = type; - this.faction = faction; + this.faction = (Optional>>) (Object) faction; this.minLevel = minLevel; this.maxLevel = maxLevel; } - public FactionCondition(@NotNull IFaction faction, int minLevel, int maxLevel) { + public FactionCondition(@NotNull Holder> faction, int minLevel, int maxLevel) { this.type = Type.FACTION; this.faction = Optional.of(faction); this.minLevel = Optional.of(minLevel); diff --git a/src/main/java/de/teamlapen/vampirism/world/loot/functions/RefinementSetFunction.java b/src/main/java/de/teamlapen/vampirism/world/loot/functions/RefinementSetFunction.java index 87b20ee55b..454db9a834 100644 --- a/src/main/java/de/teamlapen/vampirism/world/loot/functions/RefinementSetFunction.java +++ b/src/main/java/de/teamlapen/vampirism/world/loot/functions/RefinementSetFunction.java @@ -6,7 +6,9 @@ import de.teamlapen.vampirism.api.entity.player.refinement.IRefinementSet; import de.teamlapen.vampirism.api.items.IRefinementItem; import de.teamlapen.vampirism.core.ModLoot; +import de.teamlapen.vampirism.core.ModRegistries; import de.teamlapen.vampirism.items.RefinementItem; +import net.minecraft.core.Holder; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.functions.LootItemConditionalFunction; @@ -19,11 +21,12 @@ public class RefinementSetFunction extends LootItemConditionalFunction { + @SuppressWarnings("unchecked") public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(inst -> - commonFields(inst).and(IFaction.CODEC.fieldOf("faction").forGetter(l -> l.faction)) + commonFields(inst).and(ModRegistries.FACTIONS.holderByNameCodec().fieldOf("faction").forGetter(l -> (Holder>) l.faction)) .apply(inst, RefinementSetFunction::new) ); - public static @NotNull Builder builder(IFaction faction) { + public static @NotNull Builder builder(Holder> faction) { return simpleBuilder(conditions -> new RefinementSetFunction(conditions, faction)); } @@ -32,9 +35,9 @@ public class RefinementSetFunction extends LootItemConditionalFunction { } @Nullable - public final IFaction faction; + public final Holder> faction; - public RefinementSetFunction(@NotNull List conditionsIn, @Nullable IFaction faction) { + public RefinementSetFunction(@NotNull List conditionsIn, @Nullable Holder> faction) { super(conditionsIn); this.faction = faction; }