pala M-enchants-1: voleur dXP (datapack + hook vol)
This commit is contained in:
@@ -42,6 +42,39 @@ public final class PalaJobEvents {
|
||||
// M-alchi-2 (wiki objets alchimiste) : capture d'eclair — foudre sur joueur avec
|
||||
// casque fer/or + fiole vanilla en main = 1 fiole -> lightning potion + 30 XP@1.
|
||||
// Degats conserves (risque de mort fidele au wiki).
|
||||
// M-enchants-1 (wiki enchants moddes, Hunter) : voleur d'XP — chance de voler
|
||||
// l'XP vanilla de la victime (niv 1 : 2 %/40, niv 2 : 4 %/50, niv 3 : 7 %/70,
|
||||
// niv 4 : 10 %/90). ECART : table moddee absente (table vanilla/enclume//enchant).
|
||||
private static void xpStealer(ServerPlayer attacker, LivingEntity victim) {
|
||||
net.minecraft.world.item.ItemStack weapon = attacker.getMainHandItem();
|
||||
if (weapon.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> holder =
|
||||
attacker.level().registryAccess()
|
||||
.lookupOrThrow(net.minecraft.core.registries.Registries.ENCHANTMENT)
|
||||
.getOrThrow(net.minecraft.resources.ResourceKey.create(
|
||||
net.minecraft.core.registries.Registries.ENCHANTMENT,
|
||||
net.minecraft.resources.Identifier.fromNamespaceAndPath(
|
||||
"pala", "xp_stealer")));
|
||||
int level = net.minecraft.world.item.enchantment.EnchantmentHelper
|
||||
.getItemEnchantmentLevel(holder, weapon);
|
||||
if (level < 1 || level > 4) {
|
||||
return;
|
||||
}
|
||||
int[] chances = {0, 2, 4, 7, 10};
|
||||
int[] amounts = {0, 40, 50, 70, 90};
|
||||
if (Math.random() * 100.0 >= chances[level]) {
|
||||
return;
|
||||
}
|
||||
int take = amounts[level];
|
||||
if (victim instanceof ServerPlayer target) {
|
||||
take = Math.min(take, target.totalExperience);
|
||||
target.giveExperiencePoints(-take);
|
||||
}
|
||||
attacker.giveExperiencePoints(take);
|
||||
}
|
||||
|
||||
private static void afterDamage(LivingEntity entity, DamageSource source, float dealt,
|
||||
float taken, boolean blocked) {
|
||||
Entity killer = source.getEntity();
|
||||
@@ -55,6 +88,10 @@ public final class PalaJobEvents {
|
||||
net.minecraft.sounds.SoundEvents.CHICKEN_EGG,
|
||||
net.minecraft.sounds.SoundSource.PLAYERS, 1.0F, 1.0F);
|
||||
}
|
||||
// M-enchants-1 : vol d'XP a chaque coup porte par un joueur.
|
||||
if (killer instanceof ServerPlayer attacker) {
|
||||
xpStealer(attacker, entity);
|
||||
}
|
||||
if (entity instanceof ServerPlayer victim
|
||||
&& source.is(net.minecraft.world.damagesource.DamageTypes.LIGHTNING_BOLT)) {
|
||||
net.minecraft.world.item.ItemStack head =
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"item.pala.amethyst_mixed_coal": "Amethyst Mixed Coal",
|
||||
"item.pala.amethyst_stick": "Amethyst Stick",
|
||||
"item.pala.compressed_amethyst": "Compressed Amethyst",
|
||||
"enchantment.pala.xp_stealer": "Voleur d'XP",
|
||||
"block.pala.mystical_bookshelf": "Bibliotheque mystique",
|
||||
"block.pala.cauldron_block": "Bloc du chaudron",
|
||||
"block.pala.cauldron_core": "Coeur du chaudron",
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"anvil_cost": 4,
|
||||
"description": {
|
||||
"translate": "enchantment.pala.xp_stealer"
|
||||
},
|
||||
"effects": {
|
||||
},
|
||||
"max_cost": {
|
||||
"base": 40,
|
||||
"per_level_above_first": 10
|
||||
},
|
||||
"max_level": 4,
|
||||
"min_cost": {
|
||||
"base": 20,
|
||||
"per_level_above_first": 10
|
||||
},
|
||||
"primary_items": "#minecraft:enchantable/sharp_weapon",
|
||||
"slots": [
|
||||
"mainhand"
|
||||
],
|
||||
"supported_items": "#minecraft:enchantable/sharp_weapon",
|
||||
"weight": 2
|
||||
}
|
||||
Reference in New Issue
Block a user