Skip to content

Commit

Permalink
enchantmenttag.full_name, .script
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 27, 2021
1 parent 7a871c9 commit 106491f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
Expand Up @@ -35,6 +35,10 @@ public int getMaxCost(Enchantment enchantment, int level) {
throw new UnsupportedOperationException();
}

public String getFullName(Enchantment enchantment, int level) {
throw new UnsupportedOperationException();
}

public float getDamageBonus(Enchantment enchantment, int level, String type) {
throw new UnsupportedOperationException();
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.scripts.ScriptRegistry;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.ObjectTagProcessor;
Expand Down Expand Up @@ -176,6 +177,34 @@ public static void registerTags() {
return new ElementTag(object.enchantment.getKey().toString());
});

// <--[tag]
// @attribute <EnchantmentTag.full_name[<level>]>
// @returns ElementTag
// @description
// Returns the full name for this enchantment for a given level, like "Sharpness V".
// For vanilla enchantments, uses language translation keys.
// -->
registerTag("full_name", (attribute, object) -> {
return new ElementTag(object.enchantment.getKey().toString());
});

// <--[tag]
// @attribute <EnchantmentTag.script>
// @returns ScriptTag
// @description
// Returns the script that created this enchantment type, if any.
// -->
registerTag("script", (attribute, object) -> {
if (!object.enchantment.getKey().getNamespace().equals("denizen")) {
return null;
}
EnchantmentScriptContainer.EnchantmentReference ref = EnchantmentScriptContainer.registeredEnchantmentContainers.get(object.enchantment.getKey().getKey());
if (ref == null) {
return null;
}
return new ScriptTag(ref.script);
});

// <--[tag]
// @attribute <EnchantmentTag.min_level>
// @returns ElementTag(Number)
Expand Down
Expand Up @@ -188,7 +188,7 @@ public void adjust(Mechanism mechanism) {
// Removes the specified enchantments from the item (as a list of EnchantmentTags).
// Give no value input to remove all enchantments.
// @tags
// <ItemTag.enchantments>
// <ItemTag.enchantment_types>
// <ItemTag.enchantment_map>
// -->
if (mechanism.matches("remove_enchantments")) {
Expand Down
Expand Up @@ -275,7 +275,7 @@ public BaseComponent[] getFullName(int level) {
return result;
}
String tagged = autoTagForLevel(fullNameTaggable, level);
result = FormattedTextHelper.parse(tagged, ChatColor.WHITE);
result = FormattedTextHelper.parse(tagged, ChatColor.GRAY);
fullNamePerLevel.put(level, result);
return result;
}
Expand Down
Expand Up @@ -3,8 +3,10 @@
import com.denizenscript.denizen.nms.interfaces.EnchantmentHelper;
import com.denizenscript.denizen.nms.v1_17.Handler;
import com.denizenscript.denizen.scripts.containers.core.EnchantmentScriptContainer;
import com.denizenscript.denizen.utilities.FormattedTextHelper;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.utilities.ReflectionHelper;
import net.md_5.bungee.api.ChatColor;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -171,6 +173,11 @@ public int getMaxCost(Enchantment enchantment, int level) {
return ((CraftEnchantment) enchantment).getHandle().getMaxCost(level);
}

@Override
public String getFullName(Enchantment enchantment, int level) {
return FormattedTextHelper.stringify(Handler.componentToSpigot(((CraftEnchantment) enchantment).getHandle().getFullname(level)), ChatColor.GRAY);
}

@Override
public float getDamageBonus(Enchantment enchantment, int level, String type) {
MobType mobType = MobType.UNDEFINED;
Expand Down

0 comments on commit 106491f

Please sign in to comment.