From 0d1e7eb3828d520d7c5052899c12c0cfffba7d30 Mon Sep 17 00:00:00 2001 From: Majrusz Date: Sat, 3 Jun 2023 10:29:19 +0200 Subject: [PATCH] Merged 4.1.0 release --- build.gradle | 14 ++++++++++---- gradle.properties | 7 ++++++- src/main/java/com/mlib/Utility.java | 14 ++++++++++++++ .../java/com/mlib/gamemodifiers/Condition.java | 5 ++++- src/main/java/com/mlib/gamemodifiers/Contexts.java | 9 +++++++-- .../com/mlib/gamemodifiers/contexts/OnLoot.java | 3 ++- src/main/resources/META-INF/mods.toml | 6 +++--- 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 2562092f..0f800380 100644 --- a/build.gradle +++ b/build.gradle @@ -14,9 +14,9 @@ apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: 'org.spongepowered.mixin' -version = '4.0.0' +version = versions_mod group = 'com.mlib' // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = 'majrusz-library-1.18.2' +archivesBaseName = "majrusz-library-${versions_minecraft}" java.toolchain.languageVersion = JavaLanguageVersion.of(17) compileJava { @@ -24,7 +24,7 @@ compileJava { } minecraft { - mappings channel: 'official', version: '1.18.2' + mappings channel: 'official', version: versions_minecraft accessTransformer = file( 'src/main/resources/META-INF/accesstransformer.cfg' ) // Currently, this location cannot be changed from the default. @@ -93,8 +93,14 @@ mixin { config 'mixins.mlib.json' } +processResources { + filesMatching('META-INF/mods.toml') { + expand project.properties + } +} + dependencies { - minecraft 'net.minecraftforge:forge:1.18.2-40.2.0' + minecraft "net.minecraftforge:forge:${versions_minecraft}-${versions_forge}" annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' } diff --git a/gradle.properties b/gradle.properties index 878bf1f7..81a962b6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,9 @@ # Sets default memory used for gradle commands. Can be overridden by user or command line properties. # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G -org.gradle.daemon=false \ No newline at end of file +org.gradle.daemon=false +versions_minecraft=1.18.2 +versions_minecraft_range=[1.18.2,1.19) +versions_forge=40.2.0 +versions_forge_range=[40.2.0,) +versions_mod=4.1.0 \ No newline at end of file diff --git a/src/main/java/com/mlib/Utility.java b/src/main/java/com/mlib/Utility.java index be503982..0f660d25 100644 --- a/src/main/java/com/mlib/Utility.java +++ b/src/main/java/com/mlib/Utility.java @@ -1,6 +1,8 @@ package com.mlib; +import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; @@ -11,6 +13,7 @@ import net.minecraftforge.fml.loading.FMLEnvironment; import net.minecraftforge.fml.util.thread.SidedThreadGroups; import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.server.ServerLifecycleHooks; import javax.annotation.Nullable; @@ -126,4 +129,15 @@ public static boolean isClientSide() { public static boolean isDevBuild() { return !FMLEnvironment.production; } + + public static void profile( String sectionName, Runnable runnable ) { + ProfilerFiller profiler = getProfiler(); + profiler.push( sectionName ); + runnable.run(); + profiler.pop(); + } + + public static ProfilerFiller getProfiler() { + return isServerSide() ? ServerLifecycleHooks.getCurrentServer().getProfiler() : Minecraft.getInstance().getProfiler(); + } } diff --git a/src/main/java/com/mlib/gamemodifiers/Condition.java b/src/main/java/com/mlib/gamemodifiers/Condition.java index b29bb703..9e0edf51 100644 --- a/src/main/java/com/mlib/gamemodifiers/Condition.java +++ b/src/main/java/com/mlib/gamemodifiers/Condition.java @@ -76,7 +76,10 @@ public static < DataType > Condition< DataType > chance( double defaultChance ) public static < DataType extends ILevelData & IPositionData > Condition< DataType > chanceCRD( DoubleConfig chance, boolean defaultScaledByCRD ) { BooleanConfig scaledByCRD = new BooleanConfig( defaultScaledByCRD ); Predicate< DataType > predicate = data->{ - double multiplier = scaledByCRD.isEnabled() ? LevelHelper.getClampedRegionalDifficultyAt( data.getLevel(), AnyPos.from( data.getPosition() ).block() ) : 1.0; + double multiplier = 1.0; + if( scaledByCRD.isEnabled() && data.getLevel() != null ) { + multiplier *= LevelHelper.getClampedRegionalDifficultyAt( data.getLevel(), AnyPos.from( data.getPosition() ).block() ); + } return Random.tryChance( multiplier * chance.getOrDefault() ); }; diff --git a/src/main/java/com/mlib/gamemodifiers/Contexts.java b/src/main/java/com/mlib/gamemodifiers/Contexts.java index 07d32770..ee9da07a 100644 --- a/src/main/java/com/mlib/gamemodifiers/Contexts.java +++ b/src/main/java/com/mlib/gamemodifiers/Contexts.java @@ -1,5 +1,7 @@ package com.mlib.gamemodifiers; +import com.mlib.Utility; + import java.util.*; import java.util.function.Consumer; import java.util.stream.Stream; @@ -28,8 +30,11 @@ public Context< DataType > add( Consumer< DataType > consumer ) { } public DataType dispatch( DataType data ) { - this.tryToSort(); - this.contexts.forEach( context->context.accept( data ) ); + String sectionName = data.getClass().getName(); + Utility.profile( sectionName, ()->{ + this.tryToSort(); + this.stream().forEach( context->context.accept( data ) ); // IMPORTANT: it uses unsynchronized stream to avoid deadlocks on recursive calls + } ); return data; } diff --git a/src/main/java/com/mlib/gamemodifiers/contexts/OnLoot.java b/src/main/java/com/mlib/gamemodifiers/contexts/OnLoot.java index d954096e..24913dcb 100644 --- a/src/main/java/com/mlib/gamemodifiers/contexts/OnLoot.java +++ b/src/main/java/com/mlib/gamemodifiers/contexts/OnLoot.java @@ -127,8 +127,9 @@ public void addAsChestLoot( ResourceLocation id ) { this.generatedLoot.addAll( itemStacks ); } + @Nullable private < Type > Type getParameter( LootContextParam< Type > parameter ) { - return this.context.hasParam( parameter ) ? this.context.getParam( parameter ) : null; + return this.context.getParamOrNull( parameter ); } } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index e8813281..5dc66ecb 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -5,7 +5,7 @@ issueTrackerURL="https://github.com/Majrusz/MajruszLibrary/issues" [[mods]] modId="mlib" - version="4.0.0" + version="${versions_mod}" displayName="Majrusz Library" updateJSONURL="https://raw.githubusercontent.com/Majrusz/MinecraftCommon/main/Library/update.json" displayURL="https://www.curseforge.com/minecraft/mc-mods/majrusz-library" @@ -17,13 +17,13 @@ issueTrackerURL="https://github.com/Majrusz/MajruszLibrary/issues" [[dependencies.mlib]] modId="forge" mandatory=true - versionRange="[40.2.0,)" + versionRange="${versions_forge_range}" ordering="NONE" side="BOTH" [[dependencies.mlib]] modId="minecraft" mandatory=true - versionRange="[1.18.2,1.19)" + versionRange="${versions_minecraft_range}" ordering="NONE" side="BOTH"