Skip to content

Commit

Permalink
Improve compatibility with other mods
Browse files Browse the repository at this point in the history
 - Adjust priority for Valkyrien Warfare
 - Exclude Mixin library from mod identification
 - Preserve order when identifying mods
 - Disable ID limit removal when NEID is installed
  • Loading branch information
Runemoro committed Jun 7, 2018
1 parent 271c3ec commit 3ee4574
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
21 changes: 12 additions & 9 deletions src/main/java/org/dimdev/utils/ModIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,26 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;

public final class ModIdentifier { // TODO: non-forge mods too
private static final Logger log = LogManager.getLogger();

public static Set<ModContainer> identifyFromStacktrace(Throwable e) {
Map<File, Set<ModContainer>> modMap = makeModMap();

HashSet<String> classes = new HashSet<>();
// Get the set of classes
HashSet<String> classes = new LinkedHashSet<>();
while (e != null) {
for (StackTraceElement element : e.getStackTrace()) {
classes.add(element.getClassName());
}
e = e.getCause();
}

Set<ModContainer> mods = new HashSet<>();
Set<ModContainer> mods = new LinkedHashSet<>();
for (String className : classes) {
Set<ModContainer> classMods = identifyFromClass(className, modMap);
if (classMods != null) mods.addAll(classMods);
Expand All @@ -45,16 +42,22 @@ public static Set<ModContainer> identifyFromClass(String className) {
}

private static Set<ModContainer> identifyFromClass(String className, Map<File, Set<ModContainer>> modMap) {
// Skip identification for Mixin, one's mod copy of the library is shared with all other mods
if (className.startsWith("org.spongepowered.asm.mixin.")) return Collections.emptySet();

// Get the URL of the class
final String untrasformedName = untransformName(Launch.classLoader, className);
URL url = Launch.classLoader.getResource(untrasformedName.replace('.', '/') + ".class");
log.debug(className + " = " + untrasformedName + " = " + url);
if (url == null) {
log.warn("Failed to identify " + className + " (untransformed name: " + untrasformedName + ")");
return new HashSet<>();
return Collections.emptySet();
}

// Get the mod containing that class
try {
if (url.getProtocol().equals("jar")) url = new URL(url.getFile().substring(0, url.getFile().indexOf('!')));
return modMap.get((new File(url.toURI())).getCanonicalFile());
return modMap.get(new File(url.toURI()).getCanonicalFile());
} catch (URISyntaxException | IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.dimdev.vanillafix;

import com.google.common.collect.ImmutableSet;
import net.minecraft.launchwrapper.Launch;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
Expand All @@ -10,25 +9,15 @@
import java.util.List;
import java.util.Set;

/**
* Determines which mixins should not be loaded because of compatibility problems.
*/
public class ModCompatibilityMixinPlugin implements IMixinConfigPlugin {

private static final Set<String> NON_SPONGE_MIXINS = ImmutableSet.of(
"org.dimdev.vanillafix.profiler.mixins.MixinWorld"
);

private boolean spongeInstalled;
private boolean neidInstalled;

@Override
public void onLoad(String mixinPackage) {
spongeInstalled = isSpongeInstalled();
}

private boolean isSpongeInstalled() {
try {
return Launch.classLoader.getClassBytes("org.spongepowered.mod.SpongeCoremod") != null;
spongeInstalled = Launch.classLoader.getClassBytes("org.spongepowered.mod.SpongeCoremod") != null;
neidInstalled = Launch.classLoader.getClassBytes("ru.fewizz.neid.asm.Transformer") != null;
} catch (IOException e) {
throw new RuntimeException(e); // Should never happen
}
Expand All @@ -40,30 +29,32 @@ public String getRefMapperConfig() {
}

@Override
@SuppressWarnings("RedundantIfStatement")
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (NON_SPONGE_MIXINS.contains(mixinClassName)) {
return !spongeInstalled;
// Sponge
if (spongeInstalled) {
if (targetClassName.equals("org.dimdev.vanillafix.profiler.mixins.MixinWorld")) return false;
}

// NotEnoughIDs
if (neidInstalled) {
if (targetClassName.startsWith("org.dimdev.vanillafix.idlimit")) return false;
}

return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(EntityRenderer.class)
@Mixin(value = EntityRenderer.class, priority = 1500)
public class MixinEntityRenderer {
/** @reason Makes the third-person view camera pass through non-solid blocks (fixes https://bugs.mojang.com/browse/MC-30845) */
@Redirect(method = "orientCamera", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;rayTraceBlocks(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/RayTraceResult;"))
@Redirect(method = "orientCamera", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;rayTraceBlocks(Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/RayTraceResult;"), expect = 0)
private RayTraceResult rayTraceBlocks(WorldClient world, Vec3d from, Vec3d to) {
return world.rayTraceBlocks(from, to, false, true, true);
}
Expand Down

0 comments on commit 3ee4574

Please sign in to comment.