From 7c003642c56f9379b5236891af905e6e81de1202 Mon Sep 17 00:00:00 2001 From: Jenny Date: Wed, 12 Mar 2025 09:01:44 +0100 Subject: [PATCH] sfx --- gradle.properties | 2 +- settings.gradle | 2 +- .../com/jenny/xp2items/items/xpTalisman.java | 38 ++++++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3ead030..837c73a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -38,7 +38,7 @@ mod_name=XP -> items # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=All Rights Reserved # The mod version. See https://semver.org/ -mod_version=0.1.0 +mod_version=0.2.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/settings.gradle b/settings.gradle index 0129630..0723925 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,4 +13,4 @@ plugins { id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' } -rootProject.name = 'jonasmod' +rootProject.name = 'xp2items' diff --git a/src/main/java/com/jenny/xp2items/items/xpTalisman.java b/src/main/java/com/jenny/xp2items/items/xpTalisman.java index 685716f..b3c7477 100644 --- a/src/main/java/com/jenny/xp2items/items/xpTalisman.java +++ b/src/main/java/com/jenny/xp2items/items/xpTalisman.java @@ -1,8 +1,10 @@ package com.jenny.xp2items.items; import com.jenny.xp2items.config.ServerConfig; -import net.minecraft.server.commands.ExperienceCommand; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -12,7 +14,6 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraftforge.registries.ForgeRegistries; -import org.apache.logging.log4j.core.jmx.Server; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -22,16 +23,8 @@ public class xpTalisman extends Item { super(properties); } - @Override - public @NotNull InteractionResult use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand interactionHand) { - if (!level.isClientSide) { - if (ServerConfig.C_XP_AMOUNT.get() > 0) { // xp amount mode - spawnItem(level, (ServerPlayer) player); - } else { // xp level mode - spawnItemLevels(level, (ServerPlayer) player); - } - } - return InteractionResult.SUCCESS; + private static int getPlayerXP(@NotNull ServerPlayer player) { + return Mth.floor(player.experienceProgress * (float) player.getXpNeededForNextLevel()); } private static void spawnItem(Level level, ServerPlayer player) { @@ -53,8 +46,11 @@ public class xpTalisman extends Item { } } - private static int getPlayerXP(ServerPlayer player) { - return Mth.floor(player.experienceProgress * (float) player.getXpNeededForNextLevel()); + private static void effects(@NotNull Level level, Player player) { + level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.EXPERIENCE_ORB_PICKUP, SoundSource.PLAYERS, 1.0F, 1.0F); + for (int i = 0; i < 9; ++i) { + level.addParticle(ParticleTypes.PORTAL, player.getRandomX(0.5F), player.getRandomY() - (double) 0.25F, player.getRandomZ(0.5F), (player.getRandom().nextDouble() - (double) 0.5F) * (double) 2.0F, -player.getRandom().nextDouble(), (player.getRandom().nextDouble() - (double) 0.5F) * (double) 2.0F); + } } private static void spawnItemLevels(Level level, ServerPlayer player) { @@ -71,4 +67,18 @@ public class xpTalisman extends Item { player.setExperiencePoints(0); player.giveExperiencePoints(xpPoints); } + + @Override + public @NotNull InteractionResult use(@NotNull Level level, @NotNull Player player, @NotNull InteractionHand interactionHand) { + if (!level.isClientSide) { + if (ServerConfig.C_XP_AMOUNT.get() > 0) { // xp amount mode + spawnItem(level, (ServerPlayer) player); + } else { // xp level mode + spawnItemLevels(level, (ServerPlayer) player); + } + } else { + effects(level, player); + } + return InteractionResult.SUCCESS; + } }