generated from isXander/FabricKotlinTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fix data cache to fix compat with mixin squared
- Loading branch information
Showing
11 changed files
with
176 additions
and
65 deletions.
There are no files selected for viewing
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
42 changes: 42 additions & 0 deletions
42
src/gametest/java/dev/isxander/debugify/test/suites/MC100991.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,42 @@ | ||
package dev.isxander.debugify.test.suites; | ||
|
||
import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.gametest.framework.GameTestHelper; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.entity.projectile.FishingHook; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.level.GameType; | ||
|
||
public class MC100991 implements FabricGameTest { | ||
@GameTest(template = EMPTY_STRUCTURE) | ||
public void statTrackRodKill(GameTestHelper ctx) { | ||
Mob targetMob = ctx.spawnWithNoFreeWill(EntityType.CREEPER, new BlockPos(4, 0, 4)); | ||
|
||
Mob attacker = ctx.spawnWithNoFreeWill(EntityType.HUSK, new BlockPos(1, 0, 1)); | ||
ItemStack rodStack = new ItemStack(Items.FISHING_ROD); | ||
attacker.setItemInHand(InteractionHand.MAIN_HAND, rodStack); | ||
|
||
FishingHook hook = ctx.spawn(EntityType.FISHING_BOBBER, targetMob.blockPosition().above(1)); | ||
|
||
Player mockPlayer = ctx.makeMockPlayer(GameType.CREATIVE); | ||
mockPlayer.setItemInHand(InteractionHand.MAIN_HAND, rodStack); | ||
mockPlayer.setPos(attacker.position()); | ||
hook.setOwner(mockPlayer); | ||
|
||
ctx.runAfterDelay(20, () -> { | ||
// yank entity | ||
hook.retrieve(rodStack); | ||
|
||
ctx.runAfterDelay(5, () -> { | ||
System.out.println(targetMob.getCombatTracker().getDeathMessage().getString()); | ||
System.out.println(targetMob.getCombatTracker().getDeathMessage()); | ||
}); | ||
}); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/gametest/java/dev/isxander/debugify/test/suites/MC30391.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,34 @@ | ||
package dev.isxander.debugify.test.suites; | ||
|
||
import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.gametest.framework.GameTestHelper; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.Mob; | ||
|
||
public class MC30391 implements FabricGameTest { | ||
|
||
@GameTest(template = EMPTY_STRUCTURE) | ||
public void blaze(GameTestHelper ctx) { | ||
testWithEntity(ctx, EntityType.BLAZE); | ||
} | ||
|
||
@GameTest(template = EMPTY_STRUCTURE) | ||
public void chicken(GameTestHelper ctx) { | ||
testWithEntity(ctx, EntityType.CHICKEN); | ||
} | ||
|
||
@GameTest(template = EMPTY_STRUCTURE) | ||
public void wither(GameTestHelper ctx) { | ||
testWithEntity(ctx, EntityType.WITHER); | ||
} | ||
|
||
private <E extends Mob> void testWithEntity(GameTestHelper ctx, EntityType<E> entityType) { | ||
Mob mob = ctx.spawnWithNoFreeWill(entityType, new BlockPos(0, 4, 0)); | ||
|
||
// TODO: | ||
ctx.runAfterDelay(50, ctx::succeed); | ||
} | ||
} |
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
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
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
2 changes: 1 addition & 1 deletion
2
src/gametest/resources/data/debugify/gametest/structures/mc-8187.snbt
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
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
70 changes: 70 additions & 0 deletions
70
src/main/java/dev/isxander/debugify/mixinplugin/BugFixDataCache.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,70 @@ | ||
package dev.isxander.debugify.mixinplugin; | ||
|
||
import dev.isxander.debugify.fixes.BugFix; | ||
import dev.isxander.debugify.fixes.BugFixData; | ||
import dev.isxander.debugify.fixes.FixCategory; | ||
import dev.isxander.debugify.fixes.OS; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.objectweb.asm.tree.AnnotationNode; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.spongepowered.asm.service.MixinService; | ||
import org.spongepowered.asm.util.Annotations; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class BugFixDataCache { | ||
private static final Map<String, ResolvedBugFixData> bugFixDataByMixinClass = new HashMap<>(); | ||
|
||
static Optional<BugFixData> getOrResolve(String mixinClassName) { | ||
return Optional.ofNullable( | ||
bugFixDataByMixinClass.computeIfAbsent(mixinClassName, BugFixDataCache::resolve) | ||
.data() | ||
); | ||
} | ||
|
||
static Optional<BugFixData> getIfResolved(String mixinClassName) { | ||
return Optional.ofNullable(bugFixDataByMixinClass.get(mixinClassName)) | ||
.flatMap(resolved -> Optional.ofNullable(resolved.data())); | ||
} | ||
|
||
private static ResolvedBugFixData resolve(String mixinClassName) { | ||
ClassNode classNode = getClassNode(mixinClassName); | ||
if (classNode == null) { | ||
return new ResolvedBugFixData(null); | ||
} | ||
|
||
AnnotationNode annotationNode = Annotations.getVisible(classNode, BugFix.class); | ||
|
||
if (annotationNode == null) { | ||
return new ResolvedBugFixData(null); | ||
} | ||
|
||
String id = Annotations.getValue(annotationNode, "id"); | ||
FixCategory category = getAnnotationEnumValue(annotationNode, "category", FixCategory.class); | ||
BugFix.Env env = getAnnotationEnumValue(annotationNode, "env", BugFix.Env.class); | ||
boolean enabledByDefault = Annotations.getValue(annotationNode, "enabled", Boolean.valueOf(true)); | ||
List<String> conflicts = Annotations.getValue(annotationNode, "modConflicts", true); | ||
OS requiredOS = Annotations.getValue(annotationNode, "os", OS.class, OS.UNKNOWN); | ||
|
||
return new ResolvedBugFixData(new BugFixData(id, category, env, enabledByDefault, conflicts, requiredOS)); | ||
} | ||
|
||
private static ClassNode getClassNode(String className) { | ||
try { | ||
return MixinService.getService().getBytecodeProvider().getClassNode(className); | ||
} catch (ClassNotFoundException | IOException e) { | ||
return null; | ||
} | ||
} | ||
|
||
private static <T extends Enum<T>> T getAnnotationEnumValue(AnnotationNode annotation, String key, Class<T> enumClass) { | ||
String[] value = Annotations.getValue(annotation, key); | ||
return Enum.valueOf(enumClass, value[1]); | ||
} | ||
|
||
record ResolvedBugFixData(@Nullable BugFixData data) {} | ||
} |
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
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