Skip to content

Commit

Permalink
add skill tag provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Charismara committed Jan 31, 2024
1 parent d8f14cd commit ed3d330
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void onRightClickBlock(ManasSkillInstance instance, Player player, Intera
*
* @see ManasSkillInstance#onBeingTargeted(Changeable, LivingEntity)
*/
public boolean onBeingTargeted(ManasSkillInstance instance, Changeable<LivingEntity> target, LivingEntity owner) {
public boolean onBeingTargeted(ManasSkillInstance instance, Changeable<LivingEntity> target, LivingEntity owner) {
// Override this method to add your own logic
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.TagKey;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -548,4 +549,8 @@ public MutableComponent getChatDisplayName(boolean withDescription) {
MutableComponent component = Component.literal("[").append(getDisplayName()).append("]");
return component.withStyle(style);
}

public boolean is(TagKey<ManasSkill> tag) {
return this.skillRegistryObject.is(tag);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.manasmods.manascore.data.tags;

import com.github.manasmods.manascore.api.skill.ManasSkill;
import com.github.manasmods.manascore.skill.SkillRegistry;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.PackOutput;
import net.minecraft.data.tags.IntrinsicHolderTagsProvider;

import java.util.concurrent.CompletableFuture;

public abstract class SkillTagProvider extends IntrinsicHolderTagsProvider<ManasSkill> {
public SkillTagProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider) {
super(output, SkillRegistry.KEY, lookupProvider, manasSkill -> SkillRegistry.SKILLS.getKey(manasSkill).orElseThrow());
}

public SkillTagProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, CompletableFuture<TagLookup<ManasSkill>> parentProvider) {
super(output, SkillRegistry.KEY, lookupProvider, parentProvider, manasSkill -> SkillRegistry.SKILLS.getKey(manasSkill).orElseThrow());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.EntityHitResult;

Expand All @@ -25,8 +24,6 @@ public class SkillRegistry {
.syncToClients()
.build();
public static final ResourceKey<Registry<ManasSkill>> KEY = (ResourceKey<Registry<ManasSkill>>) SKILLS.key();
public static final TagKey<ManasSkill> SKILL_TAG = TagKey.create(KEY, new ResourceLocation(ManasCore.MOD_ID, "skills"));


public static void init() {
InteractionEvent.RIGHT_CLICK_BLOCK.register((player, hand, pos, face) -> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import dev.architectury.registry.registries.Registrar;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ai.attributes.RangedAttribute;
import net.minecraft.world.entity.npc.Villager;
Expand Down Expand Up @@ -52,6 +54,8 @@ public class RegisterTest {
.end();
private static final RegistrySupplier<TestSkill> TEST_SKILL = REGISTER.skill("test_skill", TestSkill::new).end();

static final TagKey<ManasSkill> TEST_SKILL_TAG = TagKey.create(SkillAPI.getSkillRegistryKey(), new ResourceLocation(ManasCore.MOD_ID, "test_skill"));

public static void init() {
ManasCore.Logger.info("Registered test content!");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ public boolean onTouchEntity(ManasSkillInstance instance, LivingEntity owner, Li
}

public boolean onTakenDamage(ManasSkillInstance instance, LivingEntity owner, DamageSource source, Changeable<Float> amount) {
owner.heal(amount.get());
ManasCore.Logger.info("Healed {} by {} health", owner.getName(), amount.get());
if (instance.is(RegisterTest.TEST_SKILL_TAG)) {
owner.heal(amount.get());
ManasCore.Logger.info("Healed {} by {} health", owner.getName(), amount.get());
}
return true;
}

Expand Down

0 comments on commit ed3d330

Please sign in to comment.