Skip to content

Commit

Permalink
Update to 1.20.6
Browse files Browse the repository at this point in the history
No longer supports 1.20.4 and lower due to changes to constants
Still need to add methods to get tags for enchanting table/anvil applicable materials from enchantments.
  • Loading branch information
Jikoo committed May 23, 2024
1 parent be53fe2 commit 2d045fc
Show file tree
Hide file tree
Showing 26 changed files with 424 additions and 451 deletions.
8 changes: 2 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.jikoo</groupId>
<artifactId>planarenchanting</artifactId>
<version>1.1.1-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>

<name>PlanarEnchanting</name>

Expand Down Expand Up @@ -49,10 +49,6 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>

<dependencyManagement>
Expand All @@ -66,7 +62,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.github.jikoo.planarenchanting.anvil;

import com.github.jikoo.planarenchanting.enchant.EnchantData;
import com.github.jikoo.planarenchanting.enchant.EnchantRarity;
import com.github.jikoo.planarenchanting.util.ItemUtil;
import com.github.jikoo.planarenchanting.util.MetaCachedStack;
import java.util.Objects;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.Repairable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;

/**
* An interface representing a portion of the functionality of an anvil. By using several in
Expand Down Expand Up @@ -240,19 +238,16 @@ protected int getNonApplicableCost() {
/** Constant for combining enchantments from source and target like Bedrock Edition. */
AnvilFunction COMBINE_ENCHANTMENTS_BEDROCK_EDITION = new CombineEnchantments() {
@Override
protected EnchantRarity getRarity(Enchantment enchantment) {
// Bedrock Edition rarity is 1 tier lower for trident enchantments.
if (enchantment.getItemTarget() != EnchantmentTarget.TRIDENT) {
return super.getRarity(enchantment);
protected int getAnvilCost(Enchantment enchantment, boolean isFromBook) {
EnchantData enchantData = EnchantData.of(enchantment);
if (!enchantData.getSecondaryItems().isTagged(Material.TRIDENT)) {
return super.getAnvilCost(enchantment, isFromBook);
}

EnchantRarity rarity = EnchantData.of(enchantment).getRarity();
int base = enchantData.getAnvilCost();

if (rarity.ordinal() < 1) {
return rarity;
}

return EnchantRarity.values()[rarity.ordinal() - 1];
// Bedrock Edition rarity is 1 tier lower for trident enchantments.
return Math.max(1, isFromBook ? base / 4 : base / 2);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.github.jikoo.planarenchanting.anvil;

import com.github.jikoo.planarenchanting.enchant.EnchantData;
import com.github.jikoo.planarenchanting.enchant.EnchantRarity;
import com.github.jikoo.planarenchanting.enchant.EnchantmentUtil;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

abstract class CombineEnchantments implements AnvilFunction {

Expand Down Expand Up @@ -77,12 +76,8 @@ public void modifyResult(@Nullable ItemMeta itemMeta) {

}

protected EnchantRarity getRarity(Enchantment enchantment) {
return EnchantData.of(enchantment).getRarity();
}

private int getAnvilCost(Enchantment enchantment, boolean isFromBook) {
int value = getRarity(enchantment).getAnvilValue();
protected int getAnvilCost(Enchantment enchantment, boolean isFromBook) {
int value = EnchantData.of(enchantment).getAnvilCost();
return isFromBook ? Math.max(1, value / 2) : value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.jikoo.planarenchanting.anvil;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
Expand Down Expand Up @@ -30,8 +30,7 @@ public static boolean repairs(@NotNull ItemStack base, @NotNull ItemStack additi
return recipeChoice != null && recipeChoice.test(addition);
}

private static final Map<Material, RecipeChoice> MATERIALS_TO_REPAIRABLE
= new EnumMap<>(Material.class);
private static final Map<Material, RecipeChoice> MATERIALS_TO_REPAIRABLE = new HashMap<>();

static {
String[] armor = new String[] { "_HELMET", "_CHESTPLATE", "_LEGGINGS", "_BOOTS" };
Expand Down Expand Up @@ -62,8 +61,9 @@ public static boolean repairs(@NotNull ItemStack base, @NotNull ItemStack additi
addGear("NETHERITE", armortools, Material.NETHERITE_INGOT);

// Misc. repairable items
MATERIALS_TO_REPAIRABLE.put(Material.TURTLE_HELMET, singleChoice(Material.SCUTE));
MATERIALS_TO_REPAIRABLE.put(Material.TURTLE_HELMET, singleChoice(Material.TURTLE_SCUTE));
MATERIALS_TO_REPAIRABLE.put(Material.ELYTRA, singleChoice(Material.PHANTOM_MEMBRANE));
MATERIALS_TO_REPAIRABLE.put(Material.MACE, singleChoice(Material.BREEZE_ROD));
}

private static void addGear(String type, String[] gearType, RecipeChoice repairChoice) {
Expand Down
Loading

0 comments on commit 2d045fc

Please sign in to comment.