-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: missed threading fixes in stronghold and nether fortress
- Loading branch information
Showing
8 changed files
with
97 additions
and
43 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
...shland/c2me/fixes/worldgen/threading_issues/common/INetherFortressGeneratorPieceData.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...ain/java/com/ishland/c2me/fixes/worldgen/threading_issues/common/XPieceDataExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.ishland.c2me.fixes.worldgen.threading_issues.common; | ||
|
||
public interface XPieceDataExtension { | ||
|
||
ThreadLocal<Integer> c2me$getGeneratedCountThreadLocal(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 13 additions & 9 deletions
22
...ixes/worldgen/threading_issues/mixin/threading/MixinNetherFortressGeneratorPieceData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
package com.ishland.c2me.fixes.worldgen.threading_issues.mixin.threading; | ||
|
||
import com.ishland.c2me.fixes.worldgen.threading_issues.common.INetherFortressGeneratorPieceData; | ||
import com.ishland.c2me.fixes.worldgen.threading_issues.common.XPieceDataExtension; | ||
import net.minecraft.structure.NetherFortressGenerator; | ||
import org.objectweb.asm.Opcodes; | ||
import org.spongepowered.asm.mixin.Dynamic; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
@Mixin(NetherFortressGenerator.PieceData.class) | ||
public class MixinNetherFortressGeneratorPieceData implements INetherFortressGeneratorPieceData { | ||
public class MixinNetherFortressGeneratorPieceData implements XPieceDataExtension { | ||
|
||
private final AtomicInteger generatedCountAtomic = new AtomicInteger(); | ||
@Unique | ||
private final ThreadLocal<Integer> generatedCountThreadLocal = ThreadLocal.withInitial(() -> 0); | ||
|
||
@Dynamic | ||
@Redirect(method = "*", at = @At(value = "FIELD", target = "Lnet/minecraft/structure/NetherFortressGenerator$PieceData;generatedCount:I", opcode = Opcodes.GETFIELD)) | ||
private int redirectGetGeneratedCount(NetherFortressGenerator.PieceData pieceData) { | ||
return this.generatedCountAtomic.get(); | ||
return this.generatedCountThreadLocal.get(); | ||
} | ||
|
||
@SuppressWarnings("MixinAnnotationTarget") | ||
@Dynamic | ||
@Redirect(method = "*", at = @At(value = "FIELD", target = "Lnet/minecraft/structure/NetherFortressGenerator$PieceData;generatedCount:I", opcode = Opcodes.PUTFIELD), require = 0, expect = 0) | ||
private void redirectSetGeneratedCount(NetherFortressGenerator.PieceData pieceData, int value) { | ||
this.generatedCountAtomic.set(value); | ||
if (value == 0) { | ||
generatedCountThreadLocal.remove(); | ||
} else { | ||
this.generatedCountThreadLocal.set(value); | ||
} | ||
} | ||
|
||
@Override | ||
public AtomicInteger getGeneratedCountAtomic() { | ||
return this.generatedCountAtomic; | ||
public ThreadLocal<Integer> c2me$getGeneratedCountThreadLocal() { | ||
return this.generatedCountThreadLocal; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 25 additions & 18 deletions
43
...shland/c2me/fixes/worldgen/threading_issues/mixin/threading/MixinStrongholdGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...me/fixes/worldgen/threading_issues/mixin/threading/MixinStrongholdGeneratorPieceData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.ishland.c2me.fixes.worldgen.threading_issues.mixin.threading; | ||
|
||
import com.ishland.c2me.fixes.worldgen.threading_issues.common.XPieceDataExtension; | ||
import net.minecraft.structure.StrongholdGenerator; | ||
import org.objectweb.asm.Opcodes; | ||
import org.spongepowered.asm.mixin.Dynamic; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(StrongholdGenerator.PieceData.class) | ||
public class MixinStrongholdGeneratorPieceData implements XPieceDataExtension { | ||
|
||
@Unique | ||
private final ThreadLocal<Integer> generatedCountThreadLocal = ThreadLocal.withInitial(() -> 0); | ||
|
||
@Dynamic | ||
@Redirect(method = "*", at = @At(value = "FIELD", target = "Lnet/minecraft/structure/StrongholdGenerator$PieceData;generatedCount:I", opcode = Opcodes.GETFIELD), require = 2) | ||
private int redirectGetGeneratedCount(StrongholdGenerator.PieceData pieceData) { | ||
return this.generatedCountThreadLocal.get(); | ||
} | ||
|
||
@SuppressWarnings("MixinAnnotationTarget") | ||
@Dynamic | ||
@Redirect(method = "*", at = @At(value = "FIELD", target = "Lnet/minecraft/structure/StrongholdGenerator$PieceData;generatedCount:I", opcode = Opcodes.PUTFIELD), require = 0, expect = 0) | ||
private void redirectSetGeneratedCount(StrongholdGenerator.PieceData pieceData, int value) { | ||
if (value == 0) { | ||
generatedCountThreadLocal.remove(); | ||
} else { | ||
this.generatedCountThreadLocal.set(value); | ||
} | ||
} | ||
|
||
@Override | ||
public ThreadLocal<Integer> c2me$getGeneratedCountThreadLocal() { | ||
return this.generatedCountThreadLocal; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters