5 Commits
Author SHA1 Message Date
Jenny 377b506192 1.20.1 working 2025-03-13 13:29:14 +01:00
Jenny e9ebfc7598 remove print statement 2025-03-13 13:25:01 +01:00
Jenny 2c113c5879 1.20 working 2025-03-13 13:24:26 +01:00
Jenny 7c003642c5 sfx 2025-03-12 12:03:12 +01:00
Jenny 3b115a1781 add option to disable normal loot 2025-03-12 09:19:18 +01:00
9 changed files with 102 additions and 46 deletions

No files matched your search

+28 -15
View File
@@ -1,10 +1,21 @@
buildscript {
repositories {
// These repositories are only for Gradle plugins, put any other repositories in the repository block further below
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
mavenCentral()
}
dependencies {
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}
plugins {
id 'eclipse'
id 'idea'
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
}
apply plugin: 'org.spongepowered.mixin'
group = mod_group_id
version = mod_version
@@ -14,7 +25,7 @@ base {
}
java {
toolchain.languageVersion = JavaLanguageVersion.of(21)
toolchain.languageVersion = JavaLanguageVersion.of(17)
}
minecraft {
@@ -33,8 +44,6 @@ minecraft {
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: mapping_channel, version: mapping_version
// Tell FG to not automatically create the reobf tasks, as we now use Official mappings at runtime, If you don't use them at dev time then you'll have to fix your reobf yourself.
reobf = false
// When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game.
// In most cases, it is not necessary to enable.
@@ -78,6 +87,12 @@ minecraft {
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'
mods {
"${mod_id}" {
source sourceSets.main
}
}
}
client {
@@ -107,6 +122,12 @@ minecraft {
}
}
mixin {
add sourceSets.main, "${mod_id}.refmap.json"
config "${mod_id}.mixins.json"
}
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
@@ -129,6 +150,7 @@ dependencies {
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
@@ -177,18 +199,9 @@ tasks.named('jar', Jar).configure {
"Implementation-Vendor" : mod_authors,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")])
}
finalizedBy 'reobfJar'
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
// Merge the resources and classes into the same directory.
// This is done because java expects modules to be in a single directory.
// And if we have it in multiple we have to do performance intensive hacks like having the UnionFileSystem
// This will eventually be migrated to ForgeGradle so modders don't need to manually do it. But that is later.
sourceSets.each {
def dir = layout.buildDirectory.dir("sourcesSets/$it.name")
it.output.resourcesDir = dir
it.java.destinationDirectory = dir
}
}
+7 -7
View File
@@ -1,17 +1,17 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
# The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.21.4
minecraft_version=1.20.1
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.21.4,1.22)
minecraft_version_range=[1.20.1]
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=54.1.0
forge_version=47.4.0
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[54,)
forge_version_range=[47,)
# The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[54,)
loader_version_range=[47,)
# The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
@@ -29,7 +29,7 @@ loader_version_range=[54,)
mapping_channel=official
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=1.21.4
mapping_version=1.20.1
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=xp2items
@@ -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.0.1
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
+1 -1
View File
@@ -13,4 +13,4 @@ plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
}
rootProject.name = 'jonasmod'
rootProject.name = 'xp2items'
@@ -14,14 +14,13 @@ public class Xp2Items {
public static final String MODID = "xp2items";
public Xp2Items(FMLJavaModLoadingContext context) {
IEventBus modEventBus = context.getModEventBus();
public Xp2Items() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
items.register(modEventBus);
creativeTab.register(modEventBus);
MinecraftForge.EVENT_BUS.register(this);
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ServerConfig.SPEC, "xp2items.toml");
}
}
@@ -12,10 +12,12 @@ public class ServerConfig {
public static final ForgeConfigSpec.ConfigValue<Integer> C_XP_AMOUNT;
public static final ForgeConfigSpec.ConfigValue<Integer> C_ITEM_AMOUNT;
public static final ForgeConfigSpec.ConfigValue<Boolean> C_DISABLE_LOOT_TABLES;
static {
C_XP_AMOUNT = BUILDER.comment("xp needed per loot drop, 0=per level").define("xp_amount", 25);
C_ITEM_AMOUNT = BUILDER.comment("items per loot drop").define("item_amount", 1);
C_DISABLE_LOOT_TABLES = BUILDER.comment("disable all loot tables").define("disable_loot_tables", false);
SPEC = BUILDER.build();
}
@@ -1,8 +1,5 @@
package com.jenny.xp2items.items;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
@@ -14,7 +11,7 @@ import static com.jenny.xp2items.Xp2Items.MODID;
public class items {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static final RegistryObject<Item> XP_TALISMAN = ITEMS.register("xp_talisman", () -> new xpTalisman(new Item.Properties().setId(ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MODID, "xp_talisman"))).stacksTo(1)));
public static final RegistryObject<Item> XP_TALISMAN = ITEMS.register("xp_talisman", () -> new xpTalisman(new Item.Properties().stacksTo(1)));
public static void register(IEventBus bus) {
ITEMS.register(bus);
@@ -1,18 +1,19 @@
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;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
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,22 +23,13 @@ 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) {
List<Item> itemList = ForgeRegistries.ITEMS.getValues().stream().toList();
int xpNeeded = ServerConfig.C_XP_AMOUNT.get();
System.out.println(getPlayerXP(player));
while (true) {
int expLevelBefore = player.experienceLevel;
float expProgressBefore = player.experienceProgress;
@@ -53,8 +45,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 +66,18 @@ public class xpTalisman extends Item {
player.setExperiencePoints(0);
player.giveExperiencePoints(xpPoints);
}
@Override
public InteractionResultHolder<ItemStack> 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 InteractionResultHolder.success(player.getItemInHand(interactionHand));
}
}
@@ -0,0 +1,21 @@
package com.jenny.xp2items.mixins;
import com.jenny.xp2items.config.ServerConfig;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootTable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LootTable.class)
public class LootTableMixin {
@Inject(method = "getRandomItems(Lnet/minecraft/world/level/storage/loot/LootContext;)Lit/unimi/dsi/fastutil/objects/ObjectArrayList;", at = @At("RETURN"), cancellable = true)
private void getRandomItems(LootContext p_230923_, CallbackInfoReturnable<ObjectArrayList<ItemStack>> cir) {
if (ServerConfig.C_DISABLE_LOOT_TABLES.get()) {
cir.setReturnValue(new ObjectArrayList<>());
}
}
}
+15
View File
@@ -0,0 +1,15 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.jenny.xp2items.mixins",
"compatibilityLevel": "JAVA_17",
"refmap": "xp2items.refmap.json",
"client": [
],
"injectors": {
"defaultRequire": 1
},
"mixins": [
"LootTableMixin"
]
}