Skip to content

Commit 127f091

Browse files
committed
Merge remote-tracking branch 'origin/1.16' into 1.18
2 parents 454256d + 16d317a commit 127f091

File tree

21 files changed

+461
-26
lines changed

21 files changed

+461
-26
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ libs
44
media
55
classes/
66
.architectury-transformer/
7+
fabric/fabricloader.log
8+
fabric/test_run
79

810
# Changelog
911
CHANGELOG.md

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id "architectury-plugin" version "3.4-SNAPSHOT"
3-
id "dev.architectury.loom" version "1.1-SNAPSHOT" apply false
3+
id "dev.architectury.loom" version "1.2-SNAPSHOT" apply false
44
id "maven-publish"
55
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
66
id 'com.palantir.git-version' version '1.0.0'
@@ -93,7 +93,7 @@ allprojects {
9393
}
9494
}
9595

96-
subprojects {
96+
configure(subprojects.findAll {it.name == "common" || it.name == "forge" || it.name == "fabric"}) {
9797
apply plugin: "dev.architectury.loom"
9898

9999
loom {

common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/reduce_blockstate_cache_rebuilds/BlockStateBaseMixin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public void clearCache() {
2525
cacheInvalid = true;
2626
}
2727

28+
@Override
29+
public boolean isCacheInvalid() {
30+
return cacheInvalid;
31+
}
32+
2833
private BlockBehaviour.BlockStateBase.Cache generateCache(BlockBehaviour.BlockStateBase base) {
2934
if(cacheInvalid) {
3035
// Ensure that only one block's cache is built at a time

common/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,21 @@ public Option getEffectiveOptionForMixin(String mixinClassName) {
311311
public static ModernFixEarlyConfig load(File file) {
312312
ModernFixEarlyConfig config = new ModernFixEarlyConfig(file);
313313
Properties props = new Properties();
314-
if(file.exists()) {
315-
try (FileInputStream fin = new FileInputStream(file)){
316-
props.load(fin);
317-
} catch (IOException e) {
318-
throw new RuntimeException("Could not load config file", e);
314+
if(!Boolean.getBoolean("modernfix.ignoreConfigForTesting")) {
315+
if(file.exists()) {
316+
try (FileInputStream fin = new FileInputStream(file)){
317+
props.load(fin);
318+
} catch (IOException e) {
319+
throw new RuntimeException("Could not load config file", e);
320+
}
321+
config.readProperties(props);
319322
}
320-
config.readProperties(props);
321-
}
322323

323-
try {
324-
config.save();
325-
} catch (IOException e) {
326-
LOGGER.warn("Could not write configuration file", e);
324+
try {
325+
config.save();
326+
} catch (IOException e) {
327+
LOGGER.warn("Could not write configuration file", e);
328+
}
327329
}
328330

329331
return config;

common/src/main/java/org/embeddedt/modernfix/duck/IBlockState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
public interface IBlockState {
55
void clearCache();
6+
boolean isCacheInvalid();
67
}

common/src/main/java/org/embeddedt/modernfix/util/ClassInfoManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ private static void doClear() {
4949
if(entry.getKey().equals("java/lang/Object"))
5050
return false;
5151
ClassInfo mixinClz = entry.getValue();
52+
if(mixinClz == null)
53+
return true;
5254
try {
5355
if(mixinClz.isMixin()) {
5456
// clear classNode in MixinInfo.State

fabric/build.gradle

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id "com.github.johnrengelman.shadow" version "7.1.2"
3+
id 'com.adarshr.test-logger' version '3.2.0'
34
}
45

56
architectury {
@@ -22,10 +23,16 @@ configurations {
2223

2324
include.extendsFrom modIncludeImplementation
2425
modImplementation.extendsFrom modIncludeImplementation
26+
27+
testAgent {
28+
canBeConsumed = false
29+
}
2530
}
2631

2732
dependencies {
2833
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
34+
testImplementation "net.fabricmc:fabric-loader-junit:${rootProject.fabric_loader_version}"
35+
2936
modIncludeImplementation(fabricApi.module("fabric-api-base", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
3037
modIncludeImplementation(fabricApi.module("fabric-lifecycle-events-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
3138
modIncludeImplementation(fabricApi.module("fabric-screen-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
@@ -40,7 +47,33 @@ dependencies {
4047
// modApi "me.shedaniel:architectury-fabric:${rootProject.architectury_version}"
4148

4249
common(project(path: ":common", configuration: "namedElements")) { transitive false }
43-
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
50+
testImplementation(shadowCommon(project(path: ":common", configuration: "transformProductionFabric"))) { transitive false }
51+
52+
testImplementation(platform("org.junit:junit-bom:${project.junit_version}"))
53+
testImplementation("org.junit.jupiter:junit-jupiter-api")
54+
testImplementation("org.junit.jupiter:junit-jupiter-params")
55+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
56+
testImplementation("org.junit.platform:junit-platform-launcher")
57+
testImplementation("org.assertj:assertj-core:3.19.0")
58+
testImplementation("com.google.guava:guava-testlib:21.0")
59+
testImplementation("org.mockito:mockito-junit-jupiter:5.3.1")
60+
61+
testAgent(project("path": ":test_agent", "configuration": "agentJar"))
62+
}
63+
64+
test {
65+
useJUnitPlatform()
66+
def runDir = file('test_run')
67+
doFirst() {
68+
runDir.mkdir()
69+
}
70+
workingDir = runDir
71+
systemProperty 'modernfix.ignoreConfigForTesting', 'true'
72+
73+
// inject our custom agent to fix #817
74+
FileCollection agentFile = configurations.getByName("testAgent")
75+
jvmArgs "-javaagent:${agentFile.singleFile.absolutePath}"
76+
dependsOn(agentFile)
4477
}
4578

4679
processResources {
@@ -55,18 +88,18 @@ shadowJar {
5588
exclude "architectury.common.json"
5689

5790
configurations = [project.configurations.shadowCommon]
58-
classifier "dev-shadow"
91+
archiveClassifier.set("dev-shadow")
5992
}
6093

6194
remapJar {
6295
injectAccessWidener = true
6396
input.set shadowJar.archiveFile
6497
dependsOn shadowJar
65-
classifier null
98+
archiveClassifier.set(null)
6699
}
67100

68101
jar {
69-
classifier "dev"
102+
archiveClassifier.set("dev")
70103
}
71104

72105
components.java {

fabric/src/main/java/org/embeddedt/modernfix/ModernFixPreLaunchFabric.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
public class ModernFixPreLaunchFabric implements PreLaunchEntrypoint {
1010
@Override
1111
public void onPreLaunch() {
12+
if(ModernFixMixinPlugin.instance == null) {
13+
System.err.println("Mixin plugin not loaded yet");
14+
return;
15+
}
1216
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.spark_profile_launch.OnFabric")) {
1317
CommonModUtil.runWithoutCrash(() -> SparkLaunchProfiler.start("launch"), "Failed to start profiler");
1418
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package net.minecraft.world.level.block.state;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.world.level.EmptyBlockGetter;
5+
import net.minecraft.world.level.block.Blocks;
6+
import org.embeddedt.modernfix.duck.IBlockState;
7+
import org.embeddedt.modernfix.testing.util.BootstrapMinecraft;
8+
import org.junit.jupiter.api.*;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
@BootstrapMinecraft
13+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
14+
public class BlockStateCacheTest {
15+
@BeforeEach
16+
public void rebuildCache() {
17+
Blocks.rebuildCache();
18+
}
19+
20+
/**
21+
* Initially, the cache should be invalid, and null.
22+
*/
23+
@Test
24+
@Order(1)
25+
public void testCacheNullInitially() {
26+
BlockState stoneBlock = Blocks.STONE.defaultBlockState();
27+
assertTrue(((IBlockState)stoneBlock).isCacheInvalid());
28+
assertNull(stoneBlock.cache);
29+
}
30+
31+
/**
32+
* When an API that needs the cache is called, it should be built and the invalid flag
33+
* becomes false.
34+
*/
35+
@Test
36+
@Order(2)
37+
public void testCacheBuiltByRequest() {
38+
BlockState stoneBlock = Blocks.STONE.defaultBlockState();
39+
stoneBlock.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
40+
assertFalse(((IBlockState)stoneBlock).isCacheInvalid());
41+
assertNotNull(stoneBlock.cache);
42+
}
43+
44+
/**
45+
* When a second rebuild occurs, the invalid flag should be set to true, but the old cache
46+
* is not set to null, in order to prevent NPEs if a second thread is accessing the cache
47+
* when this takes place.
48+
*/
49+
@Test
50+
@Order(3)
51+
public void testCacheInvalidatedByLateRebuild() {
52+
BlockState stoneBlock = Blocks.STONE.defaultBlockState();
53+
stoneBlock.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
54+
Blocks.rebuildCache();
55+
assertTrue(((IBlockState)stoneBlock).isCacheInvalid());
56+
assertNotNull(stoneBlock.cache);
57+
}
58+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.embeddedt.modernfix.testing.util;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
import org.junit.jupiter.api.extension.ExtendWith;
9+
10+
@Retention(RetentionPolicy.RUNTIME)
11+
@Target(ElementType.TYPE)
12+
@ExtendWith({ BootstrapMinecraftExtension.class })
13+
public @interface BootstrapMinecraft {
14+
}

0 commit comments

Comments
 (0)