Premier commit
Cette révision appartient à :
révision
d1a26567b6
42 fichiers modifiés
+1378
Aucun fichier ne correspond à votre recherche
@@ -0,0 +1,35 @@
|
||||
package com.sculkorbs;
|
||||
|
||||
import com.sculkorbs.event.AnvilEnchantHandler;
|
||||
import com.sculkorbs.event.SculkDropHandler;
|
||||
import com.sculkorbs.registry.ModCreativeTabs;
|
||||
import com.sculkorbs.registry.ModItems;
|
||||
import com.sculkorbs.registry.ModRecipeSerializers;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.ModContainer;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Mod(SculkOrbsMod.MOD_ID)
|
||||
public class SculkOrbsMod {
|
||||
|
||||
public static final String MOD_ID = "sculkorbs";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(SculkOrbsMod.class);
|
||||
|
||||
public SculkOrbsMod(IEventBus modEventBus, ModContainer modContainer) {
|
||||
LOGGER.info("[SculkOrbs] Initialisation du mod Sculk Orbs & Perfect Enchant 1.21.1...");
|
||||
|
||||
// Enregistrement des items, onglets et sérialiseurs de recettes
|
||||
ModItems.ITEMS.register(modEventBus);
|
||||
ModCreativeTabs.CREATIVE_MODE_TABS.register(modEventBus);
|
||||
ModRecipeSerializers.RECIPE_SERIALIZERS.register(modEventBus);
|
||||
|
||||
// Enregistrement des gestionnaires d'événements NeoForge
|
||||
NeoForge.EVENT_BUS.register(SculkDropHandler.class);
|
||||
NeoForge.EVENT_BUS.register(AnvilEnchantHandler.class);
|
||||
|
||||
LOGGER.info("[SculkOrbs] Sculk Orbs, Perfect Enchant et Enclume universelle prêts !");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.sculkorbs.enchant;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.item.enchantment.ItemEnchantments;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PerfectEnchantApplier {
|
||||
|
||||
private record EnchantTarget(ResourceKey<Enchantment> key, int maxLevel) {}
|
||||
|
||||
public static ItemStack applyPerfectEnchantments(ItemStack original, int tier, HolderLookup.Provider registries) {
|
||||
if (original.isEmpty()) return ItemStack.EMPTY;
|
||||
|
||||
ItemStack result = original.copy();
|
||||
Item item = result.getItem();
|
||||
|
||||
List<EnchantTarget> targets = getEnchantmentsForItem(item);
|
||||
if (targets.isEmpty()) {
|
||||
// Si c'est un item endommagé / enchantable générique (ex: moddé, bouclier, briquet, etc.)
|
||||
if (result.isDamageableItem() || item.isEnchantable(result)) {
|
||||
targets = List.of(
|
||||
new EnchantTarget(Enchantments.UNBREAKING, 3),
|
||||
new EnchantTarget(Enchantments.MENDING, 1)
|
||||
);
|
||||
} else {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
var enchantmentLookup = registries.lookupOrThrow(Registries.ENCHANTMENT);
|
||||
ItemEnchantments existing = EnchantmentHelper.getEnchantmentsForCrafting(result);
|
||||
ItemEnchantments.Mutable mutable = new ItemEnchantments.Mutable(existing);
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
for (EnchantTarget target : targets) {
|
||||
var holderOpt = enchantmentLookup.get(target.key());
|
||||
if (holderOpt.isPresent()) {
|
||||
Holder<Enchantment> holder = holderOpt.get();
|
||||
int targetLevel = Math.min(tier, target.maxLevel());
|
||||
int currentLevel = mutable.getLevel(holder);
|
||||
|
||||
if (targetLevel > currentLevel) {
|
||||
mutable.set(holder, targetLevel);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!modified && !existing.isEmpty()) {
|
||||
// Même si tous les enchants étaient déjà au max, on peut valider l'opération
|
||||
modified = true;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
EnchantmentHelper.setEnchantments(result, mutable.toImmutable());
|
||||
return result;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
private static List<EnchantTarget> getEnchantmentsForItem(Item item) {
|
||||
List<EnchantTarget> list = new ArrayList<>();
|
||||
|
||||
if (item instanceof PickaxeItem) {
|
||||
// Pioche : Fortune par défaut (le plus polyvalent comme demandé), Efficacité, Solidité, Raccommodage
|
||||
list.add(new EnchantTarget(Enchantments.EFFICIENCY, 5));
|
||||
list.add(new EnchantTarget(Enchantments.FORTUNE, 3));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
} else if (item instanceof AxeItem) {
|
||||
// Hache : Efficacité, Tranchant, Fortune, Solidité, Raccommodage
|
||||
list.add(new EnchantTarget(Enchantments.EFFICIENCY, 5));
|
||||
list.add(new EnchantTarget(Enchantments.SHARPNESS, 5));
|
||||
list.add(new EnchantTarget(Enchantments.FORTUNE, 3));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
} else if (item instanceof ShovelItem || item instanceof HoeItem) {
|
||||
// Pelle & Houe : Efficacité, Fortune, Solidité, Raccommodage
|
||||
list.add(new EnchantTarget(Enchantments.EFFICIENCY, 5));
|
||||
list.add(new EnchantTarget(Enchantments.FORTUNE, 3));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
} else if (item instanceof SwordItem) {
|
||||
// Épée : Tranchant, Butin, Balayage, Aura de Feu, Recul, Solidité, Raccommodage
|
||||
list.add(new EnchantTarget(Enchantments.SHARPNESS, 5));
|
||||
list.add(new EnchantTarget(Enchantments.LOOTING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.SWEEPING_EDGE, 3));
|
||||
list.add(new EnchantTarget(Enchantments.FIRE_ASPECT, 2));
|
||||
list.add(new EnchantTarget(Enchantments.KNOCKBACK, 2));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
} else if (item instanceof MaceItem) {
|
||||
// Masse (1.21) : Densité, Brèche, Rafale, Solidité, Raccommodage
|
||||
list.add(new EnchantTarget(Enchantments.DENSITY, 5));
|
||||
list.add(new EnchantTarget(Enchantments.BREACH, 4));
|
||||
list.add(new EnchantTarget(Enchantments.WIND_BURST, 3));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
} else if (item instanceof BowItem) {
|
||||
// Arc : Puissance, Flamme, Frappe, Infinité, Solidité
|
||||
list.add(new EnchantTarget(Enchantments.POWER, 5));
|
||||
list.add(new EnchantTarget(Enchantments.FLAME, 1));
|
||||
list.add(new EnchantTarget(Enchantments.PUNCH, 2));
|
||||
list.add(new EnchantTarget(Enchantments.INFINITY, 1));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
} else if (item instanceof CrossbowItem) {
|
||||
// Arbalète : Tir multiple, Charge rapide, Solidité, Raccommodage
|
||||
list.add(new EnchantTarget(Enchantments.MULTISHOT, 1));
|
||||
list.add(new EnchantTarget(Enchantments.QUICK_CHARGE, 3));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
} else if (item instanceof TridentItem) {
|
||||
// Trident : Empalement, Loyauté, Canalisation, Solidité, Raccommodage
|
||||
list.add(new EnchantTarget(Enchantments.IMPALING, 5));
|
||||
list.add(new EnchantTarget(Enchantments.LOYALTY, 3));
|
||||
list.add(new EnchantTarget(Enchantments.CHANNELING, 1));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
} else if (item instanceof ArmorItem armor) {
|
||||
// Armures
|
||||
list.add(new EnchantTarget(Enchantments.PROTECTION, 4));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
list.add(new EnchantTarget(Enchantments.THORNS, 3));
|
||||
|
||||
switch (armor.getType()) {
|
||||
case HELMET -> {
|
||||
list.add(new EnchantTarget(Enchantments.RESPIRATION, 3));
|
||||
list.add(new EnchantTarget(Enchantments.AQUA_AFFINITY, 1));
|
||||
}
|
||||
case LEGGINGS -> {
|
||||
list.add(new EnchantTarget(Enchantments.SWIFT_SNEAK, 3));
|
||||
}
|
||||
case BOOTS -> {
|
||||
list.add(new EnchantTarget(Enchantments.FEATHER_FALLING, 4));
|
||||
list.add(new EnchantTarget(Enchantments.DEPTH_STRIDER, 3));
|
||||
list.add(new EnchantTarget(Enchantments.SOUL_SPEED, 3));
|
||||
}
|
||||
default -> {}
|
||||
}
|
||||
} else if (item instanceof ElytraItem) {
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
} else if (item instanceof FishingRodItem) {
|
||||
list.add(new EnchantTarget(Enchantments.LUCK_OF_THE_SEA, 3));
|
||||
list.add(new EnchantTarget(Enchantments.LURE, 3));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
} else if (item instanceof ShearsItem) {
|
||||
list.add(new EnchantTarget(Enchantments.EFFICIENCY, 5));
|
||||
list.add(new EnchantTarget(Enchantments.UNBREAKING, 3));
|
||||
list.add(new EnchantTarget(Enchantments.MENDING, 1));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.sculkorbs.event;
|
||||
|
||||
import com.sculkorbs.enchant.PerfectEnchantApplier;
|
||||
import com.sculkorbs.item.PerfectEnchantItem;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.event.AnvilUpdateEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||
|
||||
public class AnvilEnchantHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onAnvilUpdate(AnvilUpdateEvent event) {
|
||||
ItemStack left = event.getLeft();
|
||||
ItemStack right = event.getRight();
|
||||
|
||||
if (left.isEmpty() || right.isEmpty()) return;
|
||||
|
||||
if (right.getItem() instanceof PerfectEnchantItem enchantItem) {
|
||||
HolderLookup.Provider registries;
|
||||
if (event.getPlayer() != null) {
|
||||
registries = event.getPlayer().level().registryAccess();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack output = PerfectEnchantApplier.applyPerfectEnchantments(left, enchantItem.getLevel(), registries);
|
||||
|
||||
if (!output.isEmpty()) {
|
||||
event.setOutput(output);
|
||||
event.setCost(1); // 1 niveau d'XP de coût à l'enclume
|
||||
event.setMaterialCost(1); // Consomme 1 Perfect Enchant
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onItemCrafted(PlayerEvent.ItemCraftedEvent event) {
|
||||
ItemStack crafted = event.getCrafting();
|
||||
if (crafted.getItem() instanceof PerfectEnchantItem) {
|
||||
Container container = event.getInventory();
|
||||
|
||||
// Calcul du nombre de slots contenant du sculk
|
||||
int sculkSlots = 0;
|
||||
for (int i = 0; i < container.getContainerSize(); i++) {
|
||||
ItemStack stack = container.getItem(i);
|
||||
if (stack.is(Blocks.SCULK.asItem())) {
|
||||
sculkSlots++;
|
||||
}
|
||||
}
|
||||
|
||||
// Minecraft a déjà décrémenté 1 item par slot non vide lors du clic de craft.
|
||||
// On retire le reste des 64 blocs de sculk nécessaires :
|
||||
int sculkToConsume = Math.max(0, 64 - sculkSlots);
|
||||
|
||||
for (int i = 0; i < container.getContainerSize(); i++) {
|
||||
if (sculkToConsume <= 0) break;
|
||||
ItemStack stack = container.getItem(i);
|
||||
if (stack.is(Blocks.SCULK.asItem())) {
|
||||
int toTake = Math.min(stack.getCount(), sculkToConsume);
|
||||
stack.shrink(toTake);
|
||||
sculkToConsume -= toTake;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.sculkorbs.event;
|
||||
|
||||
import com.sculkorbs.registry.ModItems;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.event.level.BlockDropsEvent;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class SculkDropHandler {
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBlockDrops(BlockDropsEvent event) {
|
||||
Level level = event.getLevel();
|
||||
if (level.isClientSide() || !(level instanceof ServerLevel serverLevel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockState state = event.getState();
|
||||
if (!state.is(Blocks.SCULK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity breaker = event.getBreaker();
|
||||
if (breaker instanceof Player player && player.isCreative()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack tool = event.getTool();
|
||||
|
||||
// Vérification de Silk Touch (Toucher de soie)
|
||||
boolean hasSilkTouch = false;
|
||||
if (!tool.isEmpty()) {
|
||||
var silkTouchHolder = level.registryAccess().lookupOrThrow(Registries.ENCHANTMENT).get(Enchantments.SILK_TOUCH);
|
||||
if (silkTouchHolder.isPresent()) {
|
||||
hasSilkTouch = EnchantmentHelper.getItemEnchantmentLevel(silkTouchHolder.get(), tool) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSilkTouch) {
|
||||
return; // Silk Touch conserve le bloc de sculk vanilla
|
||||
}
|
||||
|
||||
// Vider les drops par défaut
|
||||
event.getDrops().clear();
|
||||
|
||||
// Tirage aléatoire :
|
||||
// 25% Orbe Massif (0.00 à 0.25)
|
||||
// 25% Orbe Géant (0.25 à 0.50)
|
||||
// 25% Orbe Colossal (0.50 à 0.75)
|
||||
// 20% Orbe Mythique (0.75 à 0.95)
|
||||
// 5% Orbe Maximal (0.95 à 1.00)
|
||||
double roll = RANDOM.nextDouble();
|
||||
ItemStack droppedOrb;
|
||||
|
||||
if (roll < 0.25) {
|
||||
droppedOrb = new ItemStack(ModItems.MASSIVE_ORB.get());
|
||||
} else if (roll < 0.50) {
|
||||
droppedOrb = new ItemStack(ModItems.GIANT_ORB.get());
|
||||
} else if (roll < 0.75) {
|
||||
droppedOrb = new ItemStack(ModItems.COLOSSAL_ORB.get());
|
||||
} else if (roll < 0.95) {
|
||||
droppedOrb = new ItemStack(ModItems.MYTHIC_ORB.get());
|
||||
} else {
|
||||
droppedOrb = new ItemStack(ModItems.MAXIMAL_ORB.get());
|
||||
}
|
||||
|
||||
BlockPos pos = event.getPos();
|
||||
ItemEntity orbEntity = new ItemEntity(
|
||||
serverLevel,
|
||||
pos.getX() + 0.5,
|
||||
pos.getY() + 0.5,
|
||||
pos.getZ() + 0.5,
|
||||
droppedOrb
|
||||
);
|
||||
orbEntity.setDefaultPickUpDelay();
|
||||
event.getDrops().add(orbEntity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.sculkorbs.item;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PerfectEnchantItem extends Item {
|
||||
|
||||
private final int level;
|
||||
|
||||
public PerfectEnchantItem(int level, Properties properties) {
|
||||
super(properties);
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoil(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
|
||||
String roman = switch (level) {
|
||||
case 1 -> "I";
|
||||
case 2 -> "II";
|
||||
case 3 -> "III";
|
||||
case 4 -> "IV";
|
||||
case 5 -> "V";
|
||||
default -> String.valueOf(level);
|
||||
};
|
||||
|
||||
tooltipComponents.add(Component.translatable("tooltip.sculkorbs.perfect_enchant_tier", roman).withStyle(ChatFormatting.GOLD));
|
||||
tooltipComponents.add(Component.translatable("tooltip.sculkorbs.perfect_enchant_desc").withStyle(ChatFormatting.AQUA));
|
||||
tooltipComponents.add(Component.translatable("tooltip.sculkorbs.perfect_enchant_max", level).withStyle(ChatFormatting.YELLOW));
|
||||
tooltipComponents.add(Component.empty());
|
||||
|
||||
if (level == 1) {
|
||||
tooltipComponents.add(Component.translatable("tooltip.sculkorbs.craft_hint_t1").withStyle(ChatFormatting.DARK_GRAY, ChatFormatting.ITALIC));
|
||||
} else {
|
||||
String prevRoman = switch (level - 1) {
|
||||
case 1 -> "I";
|
||||
case 2 -> "II";
|
||||
case 3 -> "III";
|
||||
case 4 -> "IV";
|
||||
default -> String.valueOf(level - 1);
|
||||
};
|
||||
tooltipComponents.add(Component.translatable("tooltip.sculkorbs.craft_hint_tn", prevRoman).withStyle(ChatFormatting.DARK_GRAY, ChatFormatting.ITALIC));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.sculkorbs.item;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SculkOrbItem extends Item {
|
||||
|
||||
private final SculkOrbTier tier;
|
||||
|
||||
public SculkOrbItem(SculkOrbTier tier, Properties properties) {
|
||||
super(properties);
|
||||
this.tier = tier;
|
||||
}
|
||||
|
||||
public SculkOrbTier getTier() {
|
||||
return tier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoil(ItemStack stack) {
|
||||
return tier.isFoil() || super.isFoil(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
ItemStack itemStack = player.getItemInHand(hand);
|
||||
|
||||
if (!level.isClientSide && level instanceof ServerLevel serverLevel) {
|
||||
// Donner l'expérience
|
||||
player.giveExperiencePoints(tier.getXpAmount());
|
||||
|
||||
// Effets, particules et sons selon le palier de l'orbe
|
||||
double px = player.getX();
|
||||
double py = player.getY();
|
||||
double pz = player.getZ();
|
||||
|
||||
switch (tier) {
|
||||
case MASSIVE -> {
|
||||
serverLevel.sendParticles(ParticleTypes.SCULK_CHARGE_POP, px, py + 1.0, pz, 20, 0.4, 0.5, 0.4, 0.05);
|
||||
level.playSound(null, px, py, pz, SoundEvents.EXPERIENCE_ORB_PICKUP, SoundSource.PLAYERS, 1.0f, 1.2f);
|
||||
}
|
||||
case GIANT -> {
|
||||
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 300, 0)); // 15s Vitesse I
|
||||
serverLevel.sendParticles(ParticleTypes.SCULK_SOUL, px, py + 1.0, pz, 30, 0.5, 0.6, 0.5, 0.08);
|
||||
level.playSound(null, px, py, pz, SoundEvents.SCULK_CATALYST_BLOOM, SoundSource.PLAYERS, 1.0f, 1.3f);
|
||||
level.playSound(null, px, py, pz, SoundEvents.EXPERIENCE_ORB_PICKUP, SoundSource.PLAYERS, 1.0f, 1.0f);
|
||||
}
|
||||
case COLOSSAL -> {
|
||||
player.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 200, 1)); // 10s Regen II
|
||||
player.addEffect(new MobEffectInstance(MobEffects.NIGHT_VISION, 600, 0)); // 30s Vision nocturne
|
||||
serverLevel.sendParticles(ParticleTypes.SCULK_SOUL, px, py + 1.0, pz, 45, 0.6, 0.8, 0.6, 0.1);
|
||||
serverLevel.sendParticles(ParticleTypes.END_ROD, px, py + 1.0, pz, 15, 0.4, 0.5, 0.4, 0.05);
|
||||
level.playSound(null, px, py, pz, SoundEvents.AMETHYST_BLOCK_RESONATE, SoundSource.PLAYERS, 1.5f, 0.8f);
|
||||
level.playSound(null, px, py, pz, SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 0.8f, 1.2f);
|
||||
}
|
||||
case MYTHIC -> {
|
||||
player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 600, 1)); // 30s Résistance II
|
||||
player.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 300, 2)); // 15s Regen III
|
||||
player.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, 1200, 3)); // 60s Absorption IV
|
||||
serverLevel.sendParticles(ParticleTypes.TOTEM_OF_UNDYING, px, py + 1.0, pz, 50, 0.5, 0.8, 0.5, 0.3);
|
||||
serverLevel.sendParticles(ParticleTypes.SCULK_SOUL, px, py + 1.0, pz, 50, 0.6, 0.8, 0.6, 0.1);
|
||||
level.playSound(null, px, py, pz, SoundEvents.TOTEM_USE, SoundSource.PLAYERS, 0.8f, 1.4f);
|
||||
level.playSound(null, px, py, pz, SoundEvents.SCULK_SHRIEKER_SHRIEK, SoundSource.PLAYERS, 0.5f, 1.3f);
|
||||
}
|
||||
case MAXIMAL -> {
|
||||
player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 900, 2)); // 45s Force III
|
||||
player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 900, 2)); // 45s Résistance III
|
||||
player.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 600, 3)); // 30s Regen IV
|
||||
player.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, 2400, 4)); // 2m Absorption V
|
||||
player.addEffect(new MobEffectInstance(MobEffects.DIG_SPEED, 1200, 1)); // 1m Célérité II
|
||||
serverLevel.sendParticles(ParticleTypes.SONIC_BOOM, px, py + 1.0, pz, 1, 0, 0, 0, 0);
|
||||
serverLevel.sendParticles(ParticleTypes.FLASH, px, py + 1.0, pz, 3, 0.2, 0.5, 0.2, 0);
|
||||
serverLevel.sendParticles(ParticleTypes.SCULK_SOUL, px, py + 1.0, pz, 80, 0.8, 1.2, 0.8, 0.2);
|
||||
serverLevel.sendParticles(ParticleTypes.ENCHANTED_HIT, px, py + 1.0, pz, 60, 0.8, 1.0, 0.8, 0.5);
|
||||
level.playSound(null, px, py, pz, SoundEvents.WARDEN_SONIC_BOOM, SoundSource.PLAYERS, 1.2f, 1.0f);
|
||||
level.playSound(null, px, py, pz, SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, SoundSource.PLAYERS, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
// Consommation de l'item en mode survie
|
||||
if (!player.getAbilities().instabuild) {
|
||||
itemStack.shrink(1);
|
||||
}
|
||||
|
||||
player.awardStat(Stats.ITEM_USED.get(this));
|
||||
}
|
||||
|
||||
return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
|
||||
tooltipComponents.add(Component.translatable("tooltip.sculkorbs.drop_rate", tier.getDropRatePercent() + "%").withStyle(ChatFormatting.GRAY));
|
||||
tooltipComponents.add(Component.translatable("tooltip.sculkorbs.xp_gain", String.format("%,d", tier.getXpAmount())).withStyle(ChatFormatting.GREEN));
|
||||
tooltipComponents.add(Component.empty());
|
||||
tooltipComponents.add(Component.translatable("tooltip.sculkorbs.use_hint").withStyle(ChatFormatting.DARK_GRAY, ChatFormatting.ITALIC));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.sculkorbs.item;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
|
||||
public enum SculkOrbTier {
|
||||
MASSIVE("massive", "Orbe Massif", "Massive Orb", 25.0, 75, ChatFormatting.GREEN, false),
|
||||
GIANT("giant", "Orbe Géant", "Giant Orb", 25.0, 350, ChatFormatting.AQUA, false),
|
||||
COLOSSAL("colossal", "Orbe Colossal", "Colossal Orb", 25.0, 1500, ChatFormatting.LIGHT_PURPLE, true),
|
||||
MYTHIC("mythic", "Orbe Mythique", "Mythic Orb", 20.0, 6000, ChatFormatting.GOLD, true),
|
||||
MAXIMAL("maximal", "Orbe Maximal", "Maximal Orb", 5.0, 30000, ChatFormatting.DARK_RED, true);
|
||||
|
||||
private final String id;
|
||||
private final String frenchName;
|
||||
private final String englishName;
|
||||
private final double dropRatePercent;
|
||||
private final int xpAmount;
|
||||
private final ChatFormatting color;
|
||||
private final boolean foil;
|
||||
|
||||
SculkOrbTier(String id, String frenchName, String englishName, double dropRatePercent, int xpAmount, ChatFormatting color, boolean foil) {
|
||||
this.id = id;
|
||||
this.frenchName = frenchName;
|
||||
this.englishName = englishName;
|
||||
this.dropRatePercent = dropRatePercent;
|
||||
this.xpAmount = xpAmount;
|
||||
this.color = color;
|
||||
this.foil = foil;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getFrenchName() {
|
||||
return frenchName;
|
||||
}
|
||||
|
||||
public String getEnglishName() {
|
||||
return englishName;
|
||||
}
|
||||
|
||||
public double getDropRatePercent() {
|
||||
return dropRatePercent;
|
||||
}
|
||||
|
||||
public int getXpAmount() {
|
||||
return xpAmount;
|
||||
}
|
||||
|
||||
public ChatFormatting getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean isFoil() {
|
||||
return foil;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.sculkorbs.recipe;
|
||||
|
||||
import com.sculkorbs.item.PerfectEnchantItem;
|
||||
import com.sculkorbs.registry.ModItems;
|
||||
import com.sculkorbs.registry.ModRecipeSerializers;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.CraftingBookCategory;
|
||||
import net.minecraft.world.item.crafting.CraftingInput;
|
||||
import net.minecraft.world.item.crafting.CustomRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
public class PerfectEnchantCraftingRecipe extends CustomRecipe {
|
||||
|
||||
public PerfectEnchantCraftingRecipe(CraftingBookCategory category) {
|
||||
super(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(CraftingInput input, Level level) {
|
||||
return getResultTier(input) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) {
|
||||
int targetTier = getResultTier(input);
|
||||
return switch (targetTier) {
|
||||
case 1 -> new ItemStack(ModItems.PERFECT_ENCHANT_1.get());
|
||||
case 2 -> new ItemStack(ModItems.PERFECT_ENCHANT_2.get());
|
||||
case 3 -> new ItemStack(ModItems.PERFECT_ENCHANT_3.get());
|
||||
case 4 -> new ItemStack(ModItems.PERFECT_ENCHANT_4.get());
|
||||
case 5 -> new ItemStack(ModItems.PERFECT_ENCHANT_5.get());
|
||||
default -> ItemStack.EMPTY;
|
||||
};
|
||||
}
|
||||
|
||||
private int getResultTier(CraftingInput input) {
|
||||
int totalSculk = 0;
|
||||
int prevEnchantLevel = 0;
|
||||
int enchantCount = 0;
|
||||
|
||||
for (int i = 0; i < input.size(); i++) {
|
||||
ItemStack stack = input.getItem(i);
|
||||
if (stack.isEmpty()) continue;
|
||||
|
||||
if (stack.is(Blocks.SCULK.asItem())) {
|
||||
totalSculk += stack.getCount();
|
||||
} else if (stack.getItem() instanceof PerfectEnchantItem enchantItem) {
|
||||
enchantCount++;
|
||||
prevEnchantLevel = enchantItem.getLevel();
|
||||
} else {
|
||||
return 0; // Item non autorisé dans la recette
|
||||
}
|
||||
}
|
||||
|
||||
// Il faut au moins 64 blocs de sculk au total dans la grille
|
||||
if (totalSculk < 64) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Niveau 1 : 64 sculk et aucun item précédent
|
||||
if (enchantCount == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Niveau N+1 : 1 item de niveau N + 64 sculk (jusqu'à 5)
|
||||
if (enchantCount == 1 && prevEnchantLevel >= 1 && prevEnchantLevel < 5) {
|
||||
return prevEnchantLevel + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getRemainingItems(CraftingInput input) {
|
||||
return NonNullList.withSize(input.size(), ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraftInDimensions(int width, int height) {
|
||||
return width * height >= 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return ModRecipeSerializers.PERFECT_ENCHANT_CRAFTING.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.sculkorbs.registry;
|
||||
|
||||
import com.sculkorbs.SculkOrbsMod;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
|
||||
public class ModCreativeTabs {
|
||||
|
||||
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS =
|
||||
DeferredRegister.create(Registries.CREATIVE_MODE_TAB, SculkOrbsMod.MOD_ID);
|
||||
|
||||
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> SCULK_ORBS_TAB = CREATIVE_MODE_TABS.register("sculk_orbs_tab",
|
||||
() -> CreativeModeTab.builder()
|
||||
.title(Component.translatable("itemGroup.sculkorbs"))
|
||||
.icon(() -> new ItemStack(ModItems.PERFECT_ENCHANT_5.get()))
|
||||
.displayItems((parameters, output) -> {
|
||||
// Orbes de Sculk
|
||||
output.accept(ModItems.MASSIVE_ORB.get());
|
||||
output.accept(ModItems.GIANT_ORB.get());
|
||||
output.accept(ModItems.COLOSSAL_ORB.get());
|
||||
output.accept(ModItems.MYTHIC_ORB.get());
|
||||
output.accept(ModItems.MAXIMAL_ORB.get());
|
||||
|
||||
// Perfect Enchants
|
||||
output.accept(ModItems.PERFECT_ENCHANT_1.get());
|
||||
output.accept(ModItems.PERFECT_ENCHANT_2.get());
|
||||
output.accept(ModItems.PERFECT_ENCHANT_3.get());
|
||||
output.accept(ModItems.PERFECT_ENCHANT_4.get());
|
||||
output.accept(ModItems.PERFECT_ENCHANT_5.get());
|
||||
})
|
||||
.build());
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.sculkorbs.registry;
|
||||
|
||||
import com.sculkorbs.SculkOrbsMod;
|
||||
import com.sculkorbs.item.PerfectEnchantItem;
|
||||
import com.sculkorbs.item.SculkOrbItem;
|
||||
import com.sculkorbs.item.SculkOrbTier;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.neoforged.neoforge.registries.DeferredItem;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
|
||||
public class ModItems {
|
||||
|
||||
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(SculkOrbsMod.MOD_ID);
|
||||
|
||||
// --- Les 5 Orbes de Sculk ---
|
||||
public static final DeferredItem<SculkOrbItem> MASSIVE_ORB = ITEMS.register("massive_orb",
|
||||
() -> new SculkOrbItem(SculkOrbTier.MASSIVE, new Item.Properties().rarity(Rarity.COMMON).stacksTo(64)));
|
||||
|
||||
public static final DeferredItem<SculkOrbItem> GIANT_ORB = ITEMS.register("giant_orb",
|
||||
() -> new SculkOrbItem(SculkOrbTier.GIANT, new Item.Properties().rarity(Rarity.UNCOMMON).stacksTo(64)));
|
||||
|
||||
public static final DeferredItem<SculkOrbItem> COLOSSAL_ORB = ITEMS.register("colossal_orb",
|
||||
() -> new SculkOrbItem(SculkOrbTier.COLOSSAL, new Item.Properties().rarity(Rarity.RARE).stacksTo(64)));
|
||||
|
||||
public static final DeferredItem<SculkOrbItem> MYTHIC_ORB = ITEMS.register("mythic_orb",
|
||||
() -> new SculkOrbItem(SculkOrbTier.MYTHIC, new Item.Properties().rarity(Rarity.EPIC).stacksTo(64)));
|
||||
|
||||
public static final DeferredItem<SculkOrbItem> MAXIMAL_ORB = ITEMS.register("maximal_orb",
|
||||
() -> new SculkOrbItem(SculkOrbTier.MAXIMAL, new Item.Properties().rarity(Rarity.EPIC).stacksTo(64)));
|
||||
|
||||
// --- Les 5 Niveaux de Perfect Enchant ---
|
||||
public static final DeferredItem<PerfectEnchantItem> PERFECT_ENCHANT_1 = ITEMS.register("perfect_enchant_1",
|
||||
() -> new PerfectEnchantItem(1, new Item.Properties().rarity(Rarity.COMMON).stacksTo(16)));
|
||||
|
||||
public static final DeferredItem<PerfectEnchantItem> PERFECT_ENCHANT_2 = ITEMS.register("perfect_enchant_2",
|
||||
() -> new PerfectEnchantItem(2, new Item.Properties().rarity(Rarity.UNCOMMON).stacksTo(16)));
|
||||
|
||||
public static final DeferredItem<PerfectEnchantItem> PERFECT_ENCHANT_3 = ITEMS.register("perfect_enchant_3",
|
||||
() -> new PerfectEnchantItem(3, new Item.Properties().rarity(Rarity.RARE).stacksTo(16)));
|
||||
|
||||
public static final DeferredItem<PerfectEnchantItem> PERFECT_ENCHANT_4 = ITEMS.register("perfect_enchant_4",
|
||||
() -> new PerfectEnchantItem(4, new Item.Properties().rarity(Rarity.EPIC).stacksTo(16)));
|
||||
|
||||
public static final DeferredItem<PerfectEnchantItem> PERFECT_ENCHANT_5 = ITEMS.register("perfect_enchant_5",
|
||||
() -> new PerfectEnchantItem(5, new Item.Properties().rarity(Rarity.EPIC).stacksTo(16)));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.sculkorbs.registry;
|
||||
|
||||
import com.sculkorbs.SculkOrbsMod;
|
||||
import com.sculkorbs.recipe.PerfectEnchantCraftingRecipe;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
|
||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
|
||||
public class ModRecipeSerializers {
|
||||
|
||||
public static final DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZERS =
|
||||
DeferredRegister.create(Registries.RECIPE_SERIALIZER, SculkOrbsMod.MOD_ID);
|
||||
|
||||
public static final DeferredHolder<RecipeSerializer<?>, SimpleCraftingRecipeSerializer<PerfectEnchantCraftingRecipe>> PERFECT_ENCHANT_CRAFTING =
|
||||
RECIPE_SERIALIZERS.register("perfect_enchant_crafting",
|
||||
() -> new SimpleCraftingRecipeSerializer<>(PerfectEnchantCraftingRecipe::new));
|
||||
}
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur