Skip to content

Commit

Permalink
Merged 4.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Majrusz committed Jun 3, 2023
1 parent 56b17a5 commit 0d1e7eb
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
14 changes: 10 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ 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 {
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
}

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.

Expand Down Expand Up @@ -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'
}
Expand Down
7 changes: 6 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
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
14 changes: 14 additions & 0 deletions src/main/java/com/mlib/Utility.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/mlib/gamemodifiers/Condition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
};
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/mlib/gamemodifiers/Contexts.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/mlib/gamemodifiers/contexts/OnLoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

0 comments on commit 0d1e7eb

Please sign in to comment.