mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2026-01-04 15:41:35 +00:00
checkpoint - 24
This commit is contained in:
@@ -33,6 +33,7 @@ dependencies {
|
||||
implementation("com.saicone.rtag:rtag-item:${rootProject.properties["rtag_version"]}")
|
||||
// nms util
|
||||
implementation("com.github.Xiao-MoMi:Sparrow-Heart:${rootProject.properties["sparrow_heart_version"]}")
|
||||
//implementation(files("libs/Sparrow-Heart-${rootProject.properties["sparrow_heart_version"]}.jar"))
|
||||
// bstats
|
||||
compileOnly("org.bstats:bstats-bukkit:${rootProject.properties["bstats_version"]}")
|
||||
// config
|
||||
|
||||
Binary file not shown.
@@ -245,15 +245,49 @@ public class BukkitConfigManager extends ConfigManager {
|
||||
return map;
|
||||
}
|
||||
|
||||
private List<Tuple<Double, String, Short>> getPossibleEnchantments(Section section) {
|
||||
List<Tuple<Double, String, Short>> list = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof Section inner) {
|
||||
Tuple<Double, String, Short> tuple = Tuple.of(
|
||||
inner.getDouble("chance"),
|
||||
inner.getString("enchant"),
|
||||
Short.valueOf(String.valueOf(inner.getInt("level")))
|
||||
);
|
||||
list.add(tuple);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private Pair<Key, Short> getEnchantmentPair(String enchantmentWithLevel) {
|
||||
String[] split = enchantmentWithLevel.split(":", 3);
|
||||
return Pair.of(Key.of(split[0], split[1]), Short.parseShort(split[2]));
|
||||
}
|
||||
|
||||
private void registerBuiltInItemProperties() {
|
||||
Function<Object, BiConsumer<Item<ItemStack>, Context<Player>>> function = arg -> {
|
||||
Function<Object, BiConsumer<Item<ItemStack>, Context<Player>>> f2 = arg -> {
|
||||
Section section = (Section) arg;
|
||||
boolean stored = Objects.equals(section.getNameAsString(), "stored-random-enchantments");
|
||||
List<Tuple<Double, String, Short>> enchantments = getPossibleEnchantments(section);
|
||||
return (item, context) -> {
|
||||
HashSet<String> ids = new HashSet<>();
|
||||
for (Tuple<Double, String, Short> pair : enchantments) {
|
||||
if (Math.random() < pair.left() && !ids.contains(pair.mid())) {
|
||||
if (stored) {
|
||||
item.addStoredEnchantment(Key.fromString(pair.mid()), pair.right());
|
||||
} else {
|
||||
item.addEnchantment(Key.fromString(pair.mid()), pair.right());
|
||||
}
|
||||
ids.add(pair.mid());
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
this.registerItemParser(f2, 4850, "random-stored-enchantments");
|
||||
this.registerItemParser(f2, 4750, "random-enchantments");
|
||||
Function<Object, BiConsumer<Item<ItemStack>, Context<Player>>> f1 = arg -> {
|
||||
Section section = (Section) arg;
|
||||
System.out.println(section.getNameAsString());
|
||||
boolean stored = Objects.equals(section.getNameAsString(), "stored-enchantment-pool");
|
||||
Section amountSection = section.getSection("amount");
|
||||
Section enchantSection = section.getSection("pool");
|
||||
@@ -286,7 +320,8 @@ public class BukkitConfigManager extends ConfigManager {
|
||||
Pair<Key, Short> enchantPair = WeightUtils.getRandom(cloned);
|
||||
Enchantment enchantment = Registry.ENCHANTMENT.get(Objects.requireNonNull(NamespacedKey.fromString(enchantPair.left().toString())));
|
||||
if (enchantment == null) {
|
||||
throw new NullPointerException("Enchantment: " + enchantPair.left() + " doesn't exist.");
|
||||
plugin.getPluginLogger().warn("Enchantment: " + enchantPair.left() + " doesn't exist.");
|
||||
return;
|
||||
}
|
||||
if (!stored) {
|
||||
for (Enchantment added : addedEnchantments) {
|
||||
@@ -307,8 +342,8 @@ public class BukkitConfigManager extends ConfigManager {
|
||||
}
|
||||
};
|
||||
};
|
||||
this.registerItemParser(function, 4800, "stored-enchantment-pool");
|
||||
this.registerItemParser(function, 4700, "enchantment-pool");
|
||||
this.registerItemParser(f1, 4800, "stored-enchantment-pool");
|
||||
this.registerItemParser(f1, 4700, "enchantment-pool");
|
||||
this.registerItemParser(arg -> {
|
||||
Section section = (Section) arg;
|
||||
Map<Key, Short> map = getEnchantments(section);
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.momirealms.customfishing.bukkit.item.BukkitItemFactory;
|
||||
import net.momirealms.customfishing.common.item.ComponentKeys;
|
||||
import net.momirealms.customfishing.common.plugin.CustomFishingPlugin;
|
||||
import net.momirealms.customfishing.common.util.Key;
|
||||
import net.momirealms.sparrow.heart.SparrowHeart;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -150,11 +151,17 @@ public class ComponentItemFactory extends BukkitItemFactory {
|
||||
|
||||
@Override
|
||||
protected void addEnchantment(RtagItem item, Key enchantment, int level) {
|
||||
|
||||
Object enchant = item.getComponent(ComponentKeys.ENCHANTMENTS);
|
||||
Map<String, Integer> map = SparrowHeart.getInstance().itemEnchantmentsToMap(enchant);
|
||||
map.put(enchantment.toString(), level);
|
||||
item.setComponent(ComponentKeys.ENCHANTMENTS, map);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addStoredEnchantment(RtagItem item, Key enchantment, int level) {
|
||||
|
||||
Object enchant = item.getComponent(ComponentKeys.STORED_ENCHANTMENTS);
|
||||
Map<String, Integer> map = SparrowHeart.getInstance().itemEnchantmentsToMap(enchant);
|
||||
map.put(enchantment.toString(), level);
|
||||
item.setComponent(ComponentKeys.STORED_ENCHANTMENTS, map);
|
||||
}
|
||||
}
|
||||
@@ -218,8 +218,6 @@ enchantment_book:
|
||||
'minecraft:looting:1': 12
|
||||
'minecraft:looting:2': 6
|
||||
'minecraft:looting:3': 2
|
||||
'minecraft:sweeping:1': 8
|
||||
'minecraft:sweeping:2': 4
|
||||
'minecraft:soul_speed:1': 8
|
||||
'minecraft:soul_speed:2': 4
|
||||
'minecraft:fire_aspect:1': 10
|
||||
|
||||
@@ -150,7 +150,7 @@ magical_rod:
|
||||
requirements:
|
||||
requirement_1:
|
||||
type: level
|
||||
value: 10
|
||||
value: 1
|
||||
not-met-actions:
|
||||
action_1:
|
||||
type: message
|
||||
@@ -169,7 +169,7 @@ magical_rod:
|
||||
cast:
|
||||
action_level:
|
||||
type: level
|
||||
value: -10
|
||||
value: -1
|
||||
effects:
|
||||
effect_1:
|
||||
type: group-mod-ignore-conditions
|
||||
|
||||
Reference in New Issue
Block a user