Improved default professions

This commit is contained in:
Indyuce 2022-01-22 15:25:58 +01:00
parent 67cd4e44d1
commit c9fe2c805c
6 changed files with 133 additions and 42 deletions

View File

@ -3,34 +3,34 @@ package net.Indyuce.mmocore.api.util.math.formula;
import java.util.Random;
public class RandomAmount {
private final double min, max;
private final double min, max;
private static final Random random = new Random();
private static final Random random = new Random();
public RandomAmount(double min, double max) {
this.min = min;
this.max = max;
}
public RandomAmount(double min, double max) {
this.min = min;
this.max = max;
}
public RandomAmount(String value) {
String[] split = value.split("-");
min = Double.parseDouble(split[0]);
max = split.length > 1 ? Double.parseDouble(split[1]) : 0;
}
public RandomAmount(String value) {
String[] split = value.split("-");
min = Double.parseDouble(split[0]);
max = split.length > 1 ? Double.parseDouble(split[1]) : min;
}
public double getMax() {
return max;
}
public double getMax() {
return max;
}
public double getMin() {
return min;
}
public double getMin() {
return min;
}
public double calculate() {
return max > 0 ? random.nextDouble() * Math.abs((max - min)) + Math.min(max, min) : min;
}
public double calculate() {
return min + random.nextDouble() * (max - min);
}
public int calculateInt() {
return (int) (max > 0 ? (random.nextInt((int) (max - min + 1)) + min) : min);
}
public int calculateInt() {
return (int) (min + random.nextInt((int) (max - min + 1)));
}
}

View File

@ -3,9 +3,9 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
@ -19,6 +19,10 @@ import java.util.Map;
import java.util.Map.Entry;
public class EnchantItemExperienceSource extends ExperienceSource<Void> {
/**
* When empty, this applies for all enchants
*/
private final List<Enchantment> enchants = new ArrayList<>();
public EnchantItemExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
@ -43,16 +47,17 @@ public class EnchantItemExperienceSource extends ExperienceSource<Void> {
PlayerData player = PlayerData.get(event.getEnchanter());
for (EnchantItemExperienceSource source : getSources())
if (source.matches(player, null)) {
Map<Enchantment, Integer> ench = new HashMap<>(event.getEnchantsToAdd());
Map<Enchantment, Integer> applicableEnchants = new HashMap<>(event.getEnchantsToAdd());
// Filter out enchants if required
if (!source.enchants.isEmpty())
ench.keySet().removeIf(enchantment -> !source.enchants.contains(enchantment));
applicableEnchants.keySet().removeIf(enchantment -> !source.enchants.contains(enchantment));
if (ench.isEmpty())
if (applicableEnchants.isEmpty())
continue;
double exp = 0;
for (Entry<Enchantment, Integer> entry : ench.entrySet())
for (Entry<Enchantment, Integer> entry : applicableEnchants.entrySet())
exp += MMOCore.plugin.enchantManager.getBaseExperience(entry.getKey()) * entry.getValue();
getDispenser().giveExperience(player, (int) exp, event.getEnchantBlock().getLocation());
}

View File

@ -17,10 +17,13 @@ exp-curve: levels
# Specifying enchants like that lets you create different
# enchanting professions, like DESTRUCTION for offense enchants
# (Smite, Bane of Arth., Sharpness, Power, Fire Aspect, Flame)
# and ALTERATION for strategic enchants for e.g
# and ALTERATION for strategic enchants for example.
#
# Use enchantitem{} to have it apply for any enchant.
#
# Use enchantitem{enchant="sharpness,power"} for multiple enchants
exp-sources:
- 'enchantitem{enchant=sharpness}'
- 'enchantitem{}'
# When enchanting an item, players earn Enchanting experience.
# Experience given by an item is the sum of the EXP given by every extra enchantment.

View File

@ -1,17 +1,31 @@
# Display options
name: Farming
# Experience given to the main level
# when leveling up this profession
experience:
base: 10
per-level: 2
base: 10
per-level: 2
# Must match an existing exp curve filename from the 'expcurves' folder
exp-curve: levels
exp-sources:
- 'mineblock{type=CARROTS;amount=1-3;crop=true;player-placed:true}'
- 'mineblock{type=POTATOES;amount=1-3;crop=true;player-placed:true}'
- 'mineblock{type=WHEAT;amount=1-3;crop=true;player-placed:true}'
- 'mineblock{type=WHEAT;amount=1-3;crop=true;player-placed=true;silk-touch=false}'
- 'mineblock{type=BEETROOTS;amount=1-3;crop=true;player-placed=true;silk-touch=false}'
- 'mineblock{type=CARROTS;amount=1-3;crop=true;player-placed=true;silk-touch=false}'
- 'mineblock{type=POTATOES;amount=1-3;crop=true;player-placed=true;silk-touch=false}'
- 'mineblock{type=MELON;amount=1-3}'
- 'mineblock{type=PUMPKIN;amount=1-3;silk-touch=false}'
- 'mineblock{type=BAMBOO;amount=1-3;silk-touch=false}'
- 'mineblock{type=COCOA;amount=1-3;crop=true;player-placed=true;silk-touch=false}'
- 'mineblock{type=SUGAR_CANE;amount=1-3;silk-touch=false}'
- 'mineblock{type=CACTUS;amount=1-3;silk-touch=false}'
- 'mineblock{type=RED_MUSHROOM;amount=1-3;silk-touch=false}'
- 'mineblock{type=BROWN_MUSHROOM;amount=1-3;silk-touch=false}'
- 'mineblock{type=KELP;amount=1-3;silk-touch=false}'
- 'mineblock{type=SEA_PICKLE;amount=1-3;silk-touch=false}'
- 'mineblock{type=NETHER_WART;amount=1-3;crop=true;silk-touch=false}'
- 'mineblock{type=CHORUS_FLOWER;amount=1-3;silk-touch=false}'
- 'mineblock{type=CRIMSON_FUNGUS;amount=1-3;silk-touch=false}'
- 'mineblock{type=WARPED_FUNGUS;amount=1-3;silk-touch=false}'

View File

@ -36,7 +36,65 @@ on-mine:
temp-block: 'skull{value="eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTU0ODE4MjMzYzgxMTg3M2U4NWY1YTRlYTQ0MjliNzVmMjNiNmFlMGVhNmY1ZmMwZjdiYjQyMGQ3YzQ3MSJ9fX0="}'
triggers:
- 'exp{profession=mining;amount=20}'
# Gold ore
gold:
material: vanilla{type=GOLD_ORE}
drop-table:
items:
- 'vanilla{type=GOLD_ORE}'
options:
vanilla-drops: false
regen:
time: 2000
temp-block: vanilla{type=STONE}
triggers:
- 'exp{profession=mining;amount=5}'
# Iron ore
iron:
material: vanilla{type=IRON_ORE}
drop-table:
items:
- 'vanilla{type=IRON_ORE}'
options:
vanilla-drops: false
regen:
time: 2000
temp-block: vanilla{type=STONE}
triggers:
- 'exp{profession=mining;amount=5}'
# Lapis ore
lapis:
material: vanilla{type=LAPIS_ORE}
drop-table:
items:
- 'vanilla{type=LAPIS_LAZULI} 1 4-20'
options:
vanilla-drops: false
regen:
time: 2000
temp-block: vanilla{type=STONE}
triggers:
- 'exp{profession=mining;amount=13}'
# Redstone ore
redstone:
material: vanilla{type=REDSTONE_ORE}
drop-table:
items:
- 'vanilla{type=REDSTONE} 1 4-20'
- 'vanilla{type=REDSTONE_TORCH} .1 1-3'
options:
vanilla-drops: false
regen:
time: 2000
temp-block: vanilla{type=STONE}
triggers:
- 'exp{profession=mining;amount=10}'
# Emerald ore
emerald:
material: vanilla{type=EMERALD_ORE}
drop-table:
@ -50,6 +108,7 @@ on-mine:
triggers:
- 'exp{profession=mining;amount=32}'
# Diamond ore
diamond:
# The material you need to mine
material: vanilla{type=DIAMOND_ORE}

View File

@ -1,12 +1,22 @@
# Display options
name: Smelting
# Experience given to the main level
# when leveling up this profession
experience:
base: 20
per-level: 3
base: 20
per-level: 3
# Must match an existing exp curve filename from the 'expcurves' folder
exp-curve: levels
exp-curve: levels
exp-sources:
- 'craftitem{type=BLAST_FURNACE;amount=1}'
- 'craftitem{type=SMOKER;amount=1}'
- 'smeltitem{type=COOKED_BEEF;amount=1-3}'
- 'smeltitem{type=COOKED_CHICKEN;amount=1-3}'
- 'smeltitem{type=COOKED_COD;amount=1-3}'
- 'smeltitem{type=COOKED_MUTTON;amount=1-3}'
- 'smeltitem{type=COOKED_PORKCHOP;amount=1-3}'
- 'smeltitem{type=COOKED_RABBIT;amount=1-3}'
- 'smeltitem{type=COOKED_SALMON;amount=1-3}'