This commit is contained in:
Jenny 2025-03-12 09:01:44 +01:00
parent 3b115a1781
commit 7c003642c5
Signed by: Jenny
GPG Key ID: 2072A14E40940632
3 changed files with 26 additions and 16 deletions

View File

@ -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

View File

@ -13,4 +13,4 @@ plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
}
rootProject.name = 'jonasmod'
rootProject.name = 'xp2items'

View File

@ -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;
}
}