Compare commits

..
39 changed files with 1039 additions and 469 deletions

No files matched your search

-2
View File
@@ -98,8 +98,6 @@ dependencies {
compileOnly("com.github.GTNewHorizons:NotEnoughIds-Legacy:1.4.7:dev") // ASM Version
compileOnly(rfg.deobf("curse.maven:campfirebackport-387444:4611675"))
// HMMMMM
compileOnly(rfg.deobf("curse.maven:journeymap-32274:2367915"))
compileOnly(rfg.deobf("curse.maven:xaeros-minimap-263420:5060684"))
compileOnly("com.github.GTNewHorizons:HoloInventory:2.4.12-GTNH:dev")
@@ -107,26 +107,6 @@ public class AngelicaConfig {
@Config.RequiresMcRestart
public static boolean optimizeTextureLoading;
@Config.Comment("Fix thread-safety in lotrs rendering")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixLotrSodiumCompat;
@Config.Comment("Fix thread-safety in Extra Utilities rendering")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixExtraUtilsSodiumCompat;
@Config.Comment("Fix thread-safety in Stacks on Stacks rendering")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixStacksOnStacksSodiumCompat;
@Config.Comment("Fix thread-safety issues in MineFactory Reloaded")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixMineFactoryReloadedSodiumCompat;
@Config.Comment("Fix RenderBlockFluid reading the block type from the world access multiple times")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
@@ -152,4 +132,9 @@ public class AngelicaConfig {
@Config.DefaultBoolean(false)
@Config.RequiresMcRestart
public static boolean enableDebugLogging;
@Config.Comment("Enable Zoom")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean enableZoom;
}
@@ -0,0 +1,42 @@
package com.gtnewhorizons.angelica.config;
import com.gtnewhorizon.gtnhlib.config.Config;
@Config(modid = "angelica", filename = "angelica-compat")
public class CompatConfig {
@Config.Comment("Apply fixes to the LOTR mod")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixLotr;
@Config.Comment("Apply fixes to Extra Utilities")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixExtraUtils;
@Config.Comment("Apply fixes to Stacks on Stacks")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixStacksOnStacks;
@Config.Comment("Apply fixes to Minefactory Reloaded")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixMinefactoryReloaded;
@Config.Comment("Apply fixes to Thaumcraft")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixThaumcraft;
@Config.Comment("Apply fixes to ThaumicHorizons")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixThaumicHorizons;
@Config.Comment("Apply fixes to Immersive Engineering")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean fixImmersiveEngineering;
}
@@ -19,9 +19,7 @@ import org.lwjgl.opengl.GL30;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiIngame;
@@ -29,9 +27,7 @@ import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.client.GuiIngameForge;
import thaumcraft.common.Thaumcraft;
import xaero.common.core.XaeroMinimapCore;
@@ -70,31 +66,6 @@ public class HUDCaching {
private HUDCaching() {}
/* TODO START REMOVE DEBUG STUFF */
private final List<Long> updateTimeList = new ArrayList<>(21);
private static boolean isEnabled = true;
// moved initialization to when its registered to avoid an empty Debug category, which can cause crashes when
// opening the controls menu and hudcaching is disabled in the config
private static KeyBinding toggle;
public static void registerKeyBindings() {
toggle = new KeyBinding("Toggle HUDCaching", 0, "Debug");
ClientRegistry.registerKeyBinding(toggle);
}
@SubscribeEvent
public void onKeypress(InputEvent.KeyInputEvent event) {
if (toggle != null && toggle.isPressed()) {
isEnabled = !isEnabled;
final String msg = isEnabled ? "Enabled HUDCaching" : "Disabled HUDCaching";
if (mc.thePlayer != null) mc.thePlayer.addChatMessage(new ChatComponentText(msg));
}
}
/* TODO END REMOVE DEBUG STUFF */
// highest so it runs before the GLSM load event
@SubscribeEvent(priority = EventPriority.HIGH)
public void onJoinWorld(WorldEvent.Load event) {
@@ -112,7 +83,7 @@ public class HUDCaching {
XaeroMinimapCore.beforeIngameGuiRender(partialTicks);
}
if (!OpenGlHelper.isFramebufferEnabled() || !isEnabled || framebuffer == null) {
if (!OpenGlHelper.isFramebufferEnabled() || framebuffer == null) {
ingame.renderGameOverlay(partialTicks, hasScreen, mouseX, mouseY);
return;
}
@@ -244,13 +215,14 @@ public class HUDCaching {
// moved to here due to the method being called from a mixin
public static void disableHoloInventory() {
if (ModStatus.isHoloInventoryLoaded){
Renderer.INSTANCE.angelicaOverride = isEnabled;
if (ModStatus.isHoloInventoryLoaded) {
Renderer.INSTANCE.angelicaOverride = true;
}
}
@SuppressWarnings("unused") // called via ASM
public static class HUDCachingHooks {
public static boolean shouldReturnEarly(){
public static boolean shouldReturnEarly() {
return renderingCacheOverride;
}
}
@@ -6,9 +6,12 @@ import com.gtnewhorizon.gtnhlib.config.ConfigException;
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;
import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.config.CompatConfig;
import com.gtnewhorizons.angelica.mixins.Mixins;
import com.gtnewhorizons.angelica.mixins.TargetedMod;
import com.gtnewhorizons.angelica.transform.compat.CompatASMTransformers;
import com.gtnewhorizons.angelica.transform.compat.GenericCompatTransformer;
import com.gtnewhorizons.angelica.transform.compat.handlers.CompatHandler;
import com.gtnewhorizons.angelica.transform.compat.handlers.CompatHandlers;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import jss.notfine.asm.AsmTransformers;
import jss.notfine.asm.mappings.Namer;
@@ -52,6 +55,7 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
try {
// Angelica Config
ConfigurationManager.registerConfig(AngelicaConfig.class);
ConfigurationManager.registerConfig(CompatConfig.class);
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
@@ -76,10 +80,24 @@ public class AngelicaTweaker implements IFMLLoadingPlugin, IEarlyMixinLoader {
mixinTweakClasses.add(MixinCompatHackTweaker.class.getName());
}
if (transformerClasses == null) {
final List<String> transformers = new ArrayList<>(CompatASMTransformers.getTransformers());
final List<String> transformers = new ArrayList<>();
// Regsiter compat handlers, and add extra specific transformers, then build and register the generic transformer
for (CompatHandler handler : CompatHandlers.getHandlers()) {
GenericCompatTransformer.register(handler);
if (handler.extraTransformers() != null) {
transformers.addAll(handler.extraTransformers());
}
}
GenericCompatTransformer.build();
transformers.add(GenericCompatTransformer.class.getName());
// Add NotFine transformers
final List<String> notFineTransformers = AsmTransformers.getTransformers();
if (!notFineTransformers.isEmpty()) Namer.initNames();
transformers.addAll(notFineTransformers);
transformerClasses = transformers.toArray(new String[0]);
}
return transformerClasses;
@@ -4,15 +4,24 @@ import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.transform.BlockTransformer;
import com.gtnewhorizons.angelica.transform.RedirectorTransformer;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.relauncher.CoreModManager;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
import org.spongepowered.asm.launch.platform.MixinContainer;
import org.spongepowered.asm.launch.platform.MixinPlatformManager;
import org.spongepowered.asm.launch.platform.container.IContainerHandle;
import org.spongepowered.asm.mixin.transformer.Config;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.gtnewhorizons.angelica.loading.AngelicaTweaker.LOGGER;
@@ -23,8 +32,8 @@ public class MixinCompatHackTweaker implements ITweaker {
verifyDependencies();
if(DISABLE_OPTIFINE_FASTCRAFT_BETTERFPS) {
LOGGER.info("Disabling Optifine, Fastcraft, and BetterFPS (if present)");
disableOptifineFastcraftAndBetterFPS();
LOGGER.info("Disabling Optifine, Fastcraft, BetterFPS, and other incompatible mods (if present)");
disableIncompatibleMods();
}
if (AngelicaConfig.enableHudCaching){
@@ -40,8 +49,8 @@ public class MixinCompatHackTweaker implements ITweaker {
private void disableXaerosMinimapWaypointTransformer(){
try {
LaunchClassLoader lcl = Launch.classLoader;
Field xformersField = lcl.getClass().getDeclaredField("transformers");
final LaunchClassLoader lcl = Launch.classLoader;
final Field xformersField = lcl.getClass().getDeclaredField("transformers");
xformersField.setAccessible(true);
@SuppressWarnings("unchecked")
List<IClassTransformer> xformers = (List<IClassTransformer>) xformersField.get(lcl);
@@ -57,14 +66,14 @@ public class MixinCompatHackTweaker implements ITweaker {
}
}
private void disableOptifineFastcraftAndBetterFPS() {
// Remove Optifine, Fastcraft, and BetterFPS transformers & Mod Containers
@SuppressWarnings("unchecked")
private void disableIncompatibleMods() {
// Remove transformers, Mod Containers, and mixins for Optifine, Fastcraft, BetterFPS and other incompatible mods
try {
LaunchClassLoader lcl = Launch.classLoader;
Field xformersField = lcl.getClass().getDeclaredField("transformers");
final LaunchClassLoader lcl = Launch.classLoader;
final Field xformersField = lcl.getClass().getDeclaredField("transformers");
xformersField.setAccessible(true);
@SuppressWarnings("unchecked")
List<IClassTransformer> xformers = (List<IClassTransformer>) xformersField.get(lcl);
final List<IClassTransformer> xformers = (List<IClassTransformer>) xformersField.get(lcl);
for (int idx = xformers.size() - 1; idx >= 0; idx--) {
final String name = xformers.get(idx).getClass().getName();
if (name.startsWith("optifine") || name.startsWith("fastcraft") || name.startsWith("me.guichaguri.betterfps")) {
@@ -76,17 +85,72 @@ public class MixinCompatHackTweaker implements ITweaker {
throw new RuntimeException(e);
}
try {
Field injectedContainersField = Loader.class.getDeclaredField("injectedContainers");
final Field injectedContainersField = Loader.class.getDeclaredField("injectedContainers");
injectedContainersField.setAccessible(true);
@SuppressWarnings("unchecked")
List<String> containers = (List<String> ) injectedContainersField.get(Loader.class);
final List<String> containers = (List<String> ) injectedContainersField.get(Loader.class);
for (int idx = containers.size() - 1; idx >= 0; idx--) {
final String name = containers.get(idx);
final String name = containers.get(idx);
if (name.startsWith("optifine") || name.startsWith("fastcraft")) {
LOGGER.info("Removing mod container " + name);
containers.remove(idx);
}
}
final Field reparsedCoremodsField = CoreModManager.class.getDeclaredField("reparsedCoremods");
final Field loadedCoremodsField = CoreModManager.class.getDeclaredField("loadedCoremods");
reparsedCoremodsField.setAccessible(true);
loadedCoremodsField.setAccessible(true);
final ArrayList<String> reparsedCoremods = (ArrayList<String>) reparsedCoremodsField.get(CoreModManager.class);
final ArrayList<String> loadedCoremods = (ArrayList<String>) loadedCoremodsField.get(CoreModManager.class);
for (int idx = reparsedCoremods.size() - 1; idx >= 0; idx--) {
final String coreMod = reparsedCoremods.get(idx);
if (coreMod.startsWith("optimizationsandtweaks")) {
LOGGER.info("Removing reparsed coremod " + coreMod);
// Fool the CoreModManager into not checking for a mod container again later
loadedCoremods.add(reparsedCoremods.remove(idx));
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
try {
final ArrayList<String> mixinConfigsDefault = (ArrayList<String>) Launch.blackboard.get("mixin.configs.default");
if (mixinConfigsDefault != null) {
for (int idx = mixinConfigsDefault.size() - 1; idx >= 0; idx--) {
final String name = mixinConfigsDefault.get(idx);
if (name != null && name.contains("optimizationsandtweaks")) {
LOGGER.info("Removing mixin config " + name);
mixinConfigsDefault.remove(idx);
}
}
}
final Set<Config> mixinConfigs = (Set<Config>) Launch.blackboard.get("mixin.configs.queue");
final Set<Config> toRemove = new HashSet<>();
if (mixinConfigs != null) {
for (Config config : mixinConfigs) {
final String name = config.getName();
if (name != null && name.contains("optimizationsandtweaks")) {
LOGGER.info("Removing queued mixin config " + config.getName());
toRemove.add(config);
}
}
mixinConfigs.removeAll(toRemove);
}
final MixinPlatformManager platformManager = (MixinPlatformManager) Launch.blackboard.get("mixin.platform");
if (platformManager != null) {
final Field containersField = platformManager.getClass().getDeclaredField("containers");
containersField.setAccessible(true);
final Map<IContainerHandle, MixinContainer> containers = (Map<IContainerHandle, MixinContainer>) containersField.get(platformManager);
for (Map.Entry<IContainerHandle, MixinContainer> entry : containers.entrySet()) {
final String attribute = entry.getKey().getAttribute("MixinConfigs");
if(attribute != null && attribute.contains("optimizationsandtweaks")) {
LOGGER.info("Removing mixin container " + entry.getKey().toString());
containers.remove(entry.getKey());
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -2,6 +2,7 @@ package com.gtnewhorizons.angelica.mixins;
import com.gtnewhorizons.angelica.AngelicaMod;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.config.CompatConfig;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import jss.notfine.config.MCPatcherForgeConfig;
@@ -170,6 +171,14 @@ public enum Mixins {
,"angelica.textures.MixinTextureUtil"
)),
ANGELICA_ZOOM(new Builder("Zoom").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT)
.setPhase(Phase.EARLY).setApplyIf(() -> AngelicaConfig.enableZoom)
.addMixinClasses(
"angelica.zoom.MixinEntityRenderer_Zoom",
"angelica.zoom.MixinMinecraft_Zoom",
"angelica.zoom.MixinMouseFilter"
)),
HUD_CACHING(new Builder("Renders the HUD elements 20 times per second maximum to improve performance")
.addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT).setPhase(Phase.EARLY)
.setApplyIf(() -> AngelicaConfig.enableHudCaching).addMixinClasses(
@@ -204,7 +213,7 @@ public enum Mixins {
EXTRA_UTILITIES_THREAD_SAFETY(new Builder("Enable thread safety fixes in Extra Utilities").setPhase(Phase.LATE)
.addTargetedMod(TargetedMod.EXTRAUTILS).setSide(Side.CLIENT)
.setApplyIf(() -> AngelicaConfig.fixExtraUtilsSodiumCompat)
.setApplyIf(() -> CompatConfig.fixExtraUtils)
.addMixinClasses(
"client.extrautils.MixinRenderBlockConnectedTextures",
"client.extrautils.MixinRenderBlockConnectedTexturesEthereal",
@@ -212,7 +221,7 @@ public enum Mixins {
MFR_THREAD_SAFETY(new Builder("Enable thread safety fixes for MineFactory Reloaded").setPhase(Phase.LATE)
.addTargetedMod(TargetedMod.MINEFACTORY_RELOADED).setSide(Side.CLIENT)
.setApplyIf(() -> AngelicaConfig.fixMineFactoryReloadedSodiumCompat)
.setApplyIf(() -> CompatConfig.fixMinefactoryReloaded)
.addMixinClasses("client.minefactoryreloaded.MixinRedNetCableRenderer")),
SPEEDUP_CAMPFIRE_BACKPORT_ANIMATIONS(new Builder("Add animation speedup support to Campfire Backport").setPhase(Phase.LATE)
@@ -6,6 +6,7 @@ import com.gtnewhorizon.gtnhlib.client.renderer.vertex.VertexFormat;
import com.gtnewhorizons.angelica.compat.ModStatus;
import com.gtnewhorizons.angelica.compat.bettercrashes.BetterCrashesCompat;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.config.CompatConfig;
import com.gtnewhorizons.angelica.dynamiclights.DynamicLights;
import com.gtnewhorizons.angelica.glsm.GLStateManager;
import com.gtnewhorizons.angelica.glsm.debug.OpenGLDebugging;
@@ -14,6 +15,7 @@ import com.gtnewhorizons.angelica.models.VanillaModels;
import com.gtnewhorizons.angelica.render.CloudRenderer;
import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry;
import com.gtnewhorizons.angelica.utils.AssetLoader;
import com.gtnewhorizons.angelica.zoom.Zoom;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
@@ -95,8 +97,7 @@ public class ClientProxy extends CommonProxy {
if (AngelicaConfig.enableHudCaching) {
FMLCommonHandler.instance().bus().register(HUDCaching.INSTANCE);
MinecraftForge.EVENT_BUS.register(HUDCaching.INSTANCE); // TODO remove debug stuff, unused registration}
HUDCaching.registerKeyBindings();
MinecraftForge.EVENT_BUS.register(HUDCaching.INSTANCE);
}
if (AngelicaConfig.enableSodium) {
MinecraftForge.EVENT_BUS.register(SodiumDebugScreenHandler.INSTANCE);
@@ -129,7 +130,7 @@ public class ClientProxy extends CommonProxy {
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);
glsmKeyBinding = new KeyBinding("Print GLSM Debug", Keyboard.KEY_NONE, "Angelica Keybinds");
glsmKeyBinding = new KeyBinding("Print GLSM Debug", Keyboard.KEY_NONE, "Angelica");
ClientRegistry.registerKeyBinding(glsmKeyBinding);
VanillaModels.init();
@@ -137,6 +138,9 @@ public class ClientProxy extends CommonProxy {
if (ModStatus.isBetterCrashesLoaded) {
BetterCrashesCompat.init();
}
if (AngelicaConfig.enableZoom) {
Zoom.init();
}
}
private boolean wasGLSMKeyPressed;
@@ -154,7 +158,7 @@ public class ClientProxy extends CommonProxy {
public void postInit(FMLPostInitializationEvent event) {
super.postInit(event);
if (ModStatus.isLotrLoaded && AngelicaConfig.enableSodium && AngelicaConfig.fixLotrSodiumCompat) {
if (ModStatus.isLotrLoaded && AngelicaConfig.enableSodium && CompatConfig.fixLotr) {
try {
Class<?> lotrRendering = Class.forName("lotr.common.coremod.LOTRReplacedMethods$BlockRendering");
ReflectionHelper.setPrivateValue(lotrRendering, null, new ConcurrentHashMap<>(), "naturalBlockClassTable");
@@ -189,7 +193,7 @@ public class ClientProxy extends CommonProxy {
if (srv != null) {
String s = String.format("Integrated server @ %.0f ms ticks", lastIntegratedTickTime);
event.left.add(1, s);
event.left.add(Math.min(event.left.size(), 1), s);
}
}
if (AngelicaConfig.showBlockDebugInfo && mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
@@ -246,6 +250,8 @@ public class ClientProxy extends CommonProxy {
}
}
event.setCanceled(true);
// TODO don't cancel the event and render here,
// instead mixin into the vanilla code and add a background to it
/* render ourselves for modern background */
FontRenderer fontrenderer = mc.fontRenderer;
int fontColor = 0xe0e0e0;
@@ -0,0 +1,13 @@
package com.gtnewhorizons.angelica.transform;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
public class AsmUtil {
public static String obf(String deobf, String obf) {
if (AngelicaTweaker.isObfEnv()) {
return obf;
}
return deobf;
}
}
@@ -1,72 +0,0 @@
package com.gtnewhorizons.angelica.transform;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import net.minecraft.launchwrapper.IClassTransformer;
import org.spongepowered.asm.lib.ClassReader;
import org.spongepowered.asm.lib.ClassWriter;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.InsnList;
import org.spongepowered.asm.lib.tree.InsnNode;
import org.spongepowered.asm.lib.tree.JumpInsnNode;
import org.spongepowered.asm.lib.tree.LabelNode;
import org.spongepowered.asm.lib.tree.MethodInsnNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.transformers.MixinClassWriter;
import java.util.List;
import java.util.Map;
public class HUDCachingTransformer implements IClassTransformer, Opcodes {
private static final String HUDCaching = "com/gtnewhorizons/angelica/hudcaching/HUDCaching$HUDCachingHooks";
private static final Map<String, List<String>> ReturnEarlyMethods = ImmutableMap.of(
"thaumcraft.client.lib.RenderEventHandler", ImmutableList.of("renderOverlay"),
"com.kentington.thaumichorizons.client.lib.RenderEventHandler", ImmutableList.of("renderOverlay")
);
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if (basicClass == null) return null;
if (ReturnEarlyMethods.containsKey(transformedName)) {
ClassReader cr = new ClassReader(basicClass);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
for (String targetMethod : ReturnEarlyMethods.get(transformedName)) {
for (MethodNode method : cn.methods) {
if (!method.name.equals(targetMethod)) continue;
InsnList list = new InsnList();
LabelNode exitLabel = new LabelNode();
AngelicaTweaker.LOGGER.info("Injecting HUDCaching Conditional Return: " + transformedName + "#" + method.name);
list.add(new MethodInsnNode(INVOKESTATIC, HUDCaching, "shouldReturnEarly", "()Z", false));
list.add(new JumpInsnNode(IFEQ, exitLabel));
if (method.desc.endsWith("Z") || method.desc.endsWith("I")) {
list.add(new InsnNode(ICONST_0));
list.add(new InsnNode(IRETURN));
} else if (method.desc.endsWith("V")) {
list.add(new InsnNode(RETURN));
} else {
AngelicaTweaker.LOGGER.warn("HUDCaching Conditional Return - Unknown return type: " + transformedName + "#" + method.name + ":" + method.desc);
return basicClass;
}
list.add(exitLabel);
method.instructions.insert(list);
}
}
MixinClassWriter cw = new MixinClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cn.accept(cw);
final byte[] bytes = cw.toByteArray();
AngelicaTweaker.dumpClass(transformedName, basicClass, bytes, this);
return bytes;
}
return basicClass;
}
}
@@ -1,60 +0,0 @@
package com.gtnewhorizons.angelica.transform.compat;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
public enum CompatASMTransformers {
EXTRA_UTILITIES_ISBRH("RenderBlockColor Transformer", () -> AngelicaConfig.fixExtraUtilsSodiumCompat, Side.CLIENT,
"com.gtnewhorizons.angelica.transform.compat.ExtraUtilsTransformer"
),
STACKS_ON_STACKS_ISBRH("RenderTilePile Transformer", () -> AngelicaConfig.fixStacksOnStacksSodiumCompat, Side.CLIENT, "com.gtnewhorizons.angelica.transform.compat.StacksOnStacksTransformer"),
FIELD_LEVEL_TESSELLATOR("Field Level Tessellator Transformer", () -> AngelicaConfig.enableSodium, Side.CLIENT, "com.gtnewhorizons.angelica.transform.compat.FieldLevelTessellatorTransformer"),
HUD_CACHING("HUDCaching Early Return Transformer", () -> AngelicaConfig.enableHudCaching && AngelicaConfig.enableHudCachingEventTransformer, Side.CLIENT,
"com.gtnewhorizons.angelica.transform.HUDCachingTransformer")
;
private final Supplier<Boolean> applyIf;
private final Side side;
private final String[] transformerClasses;
CompatASMTransformers(String description, Supplier<Boolean> applyIf, Side side, String... transformers) {
this.applyIf = applyIf;
this.side = side;
this.transformerClasses = transformers;
}
private boolean shouldBeLoaded() { return applyIf.get() && shouldLoadSide(); }
private boolean shouldLoadSide() {
return side == Side.BOTH || (side == Side.SERVER && FMLLaunchHandler.side()
.isServer())
|| (side == Side.CLIENT && FMLLaunchHandler.side()
.isClient());
}
public static List<String> getTransformers() {
final List<String> list = new ArrayList<>();
for (CompatASMTransformers transformer : values()) {
if (transformer.shouldBeLoaded()) {
AngelicaTweaker.LOGGER.info("Loading transformer {}", (Object[]) transformer.transformerClasses);
list.addAll(Arrays.asList(transformer.transformerClasses));
} else {
AngelicaTweaker.LOGGER.info("Not loading transformer {}", (Object[]) transformer.transformerClasses);
}
}
return list;
}
private enum Side {
BOTH,
CLIENT,
SERVER
}
}
@@ -1,75 +0,0 @@
package com.gtnewhorizons.angelica.transform.compat;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ExtraUtilsTransformer implements IClassTransformer {
private static final String RenderBlockColor = "com.rwtema.extrautils.block.render.RenderBlockColor";
private static final String RenderBlockConnectedTextures = "com.rwtema.extrautils.block.render.RenderBlockConnectedTextures";
private static final String RenderBlockConnectedTexturesEthereal = "com.rwtema.extrautils.block.render.RenderBlockConnectedTexturesEthereal";
private static final String RenderBlockFullBright = "com.rwtema.extrautils.block.render.RenderBlockFullBright";
private static final String RenderBlockSpike = "com.rwtema.extrautils.block.render.RenderBlockSpike";
private static final List<String> transformedClasses = Arrays.asList(RenderBlockColor, RenderBlockConnectedTextures, RenderBlockConnectedTexturesEthereal, RenderBlockFullBright, RenderBlockSpike);
private static final Map<String, Boolean> perThreadMap = new HashMap<>();
static {
perThreadMap.put(RenderBlockColor, false);
perThreadMap.put(RenderBlockConnectedTextures, true);
perThreadMap.put(RenderBlockConnectedTexturesEthereal, true);
perThreadMap.put(RenderBlockFullBright, false);
perThreadMap.put(RenderBlockSpike, false);
}
@Override
public byte[] transform(final String className, String transformedName, byte[] basicClass) {
if (basicClass == null) return null;
if (!transformedClasses.contains(transformedName)) {
return basicClass;
}
AngelicaTweaker.LOGGER.info("Adding ThreadSafeISBRH for Extra Utilities to: {}", transformedName);
final ClassReader cr = new ClassReader(basicClass);
final ClassNode cn = new ClassNode();
cr.accept(cn, 0);
addThreadSafeISBRHAnnotation(transformedName, cn);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
final byte[] bytes = cw.toByteArray();
AngelicaTweaker.dumpClass(transformedName, basicClass, bytes, this);
return bytes;
}
public void addThreadSafeISBRHAnnotation(String transformedName, ClassNode cn) {
AnnotationNode isbrhAnnotation = new AnnotationNode("Lcom/gtnewhorizons/angelica/api/ThreadSafeISBRH;");
Boolean perThread = perThreadMap.get(transformedName);
if (perThread == null) {
perThread = false;
AngelicaTweaker.LOGGER.info("Tried to add ThreadSafeISBRH annotation to {} which is missing from perThreadMap. Using false for perThread.", transformedName);
}
isbrhAnnotation.values = Arrays.asList("perThread", perThread);
if (cn.visibleAnnotations == null) {
cn.visibleAnnotations = new ArrayList<>();
}
cn.visibleAnnotations.add(isbrhAnnotation);
}
}
@@ -1,107 +0,0 @@
package com.gtnewhorizons.angelica.transform.compat;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import net.minecraft.launchwrapper.IClassTransformer;
import org.spongepowered.asm.lib.ClassReader;
import org.spongepowered.asm.lib.ClassWriter;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.FieldInsnNode;
import org.spongepowered.asm.lib.tree.InsnList;
import org.spongepowered.asm.lib.tree.LabelNode;
import org.spongepowered.asm.lib.tree.LocalVariableNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.lib.tree.VarInsnNode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class FieldLevelTessellatorTransformer implements IClassTransformer {
private static final Map<String, List<String>> patchMethods = ImmutableMap.of(
"com.tierzero.stacksonstacks.util.ClientUtils", ImmutableList.of("drawQuad", "drawRectangularPrism")
);
public byte[] transform(final String className, String transformedName, byte[] basicClass) {
if (basicClass == null) return null;
if (!patchMethods.containsKey(transformedName)) {
return basicClass;
}
ClassReader cr = new ClassReader(basicClass);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
for (String targetMethod : patchMethods.get(transformedName)) {
for (MethodNode method : cn.methods) {
if (!method.name.equals(targetMethod)) continue;
injectLocalTessellatorAndReplaceFieldUsage(method);
}
}
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cn.accept(cw);
final byte[] bytes = cw.toByteArray();
AngelicaTweaker.dumpClass(transformedName, basicClass, bytes, this);
return bytes;
}
public static void injectLocalTessellatorAndReplaceFieldUsage(MethodNode mn) {
// This part searches the instructions to see if there is any usage of a Tessellator field
// which is NOT owned by Minecraft itself. This means anyone that caches it into a field will get caught
// but not direct usage of Tessellator.instance.whatever()
List<String> fields = new ArrayList<>();
for (int i = 0; i < mn.instructions.size(); i++) {
AbstractInsnNode in = mn.instructions.get(i);
if (in instanceof FieldInsnNode fin) {
if (
(fin.getOpcode() == Opcodes.GETSTATIC || fin.getOpcode() == Opcodes.GETFIELD)
&& fin.desc.equals("Lnet/minecraft/client/renderer/Tessellator;")
&& !fin.owner.equals("net/minecraft/client/renderer/Tessellator")
) {
fields.add(fin.owner + ";" + fin.name);
}
}
}
if (fields.isEmpty()) return;
// Injects a new local to store our new local Tessellator in
int localIndex = mn.maxLocals;
LabelNode startLabel = new LabelNode();
LabelNode endLabel = new LabelNode();
LocalVariableNode tesNode = new LocalVariableNode("tes", "Lnet/minecraft/client/renderer/Tessellator;", null, startLabel, endLabel, localIndex);
mn.localVariables.add(tesNode);
// Actually initialize the new local Tessellator
InsnList list = new InsnList();
list.add(startLabel);
list.add(new FieldInsnNode(Opcodes.GETSTATIC, "net/minecraft/client/renderer/Tessellator", AngelicaTweaker.isObfEnv() ? "field_78398_a" : "instance", "Lnet/minecraft/client/renderer/Tessellator;"));
list.add(new VarInsnNode(Opcodes.ASTORE, localIndex));
mn.instructions.insert(list);
// This searches through all the instructions and finds usage of the previously discovered fields, then it replaces them
// with an ALOAD for our new local instead of the GETSTATIC/GETFIELD
for (int i = 0; i < mn.instructions.size(); i++) {
AbstractInsnNode in = mn.instructions.get(i);
if (in instanceof FieldInsnNode fin) {
String hash = fin.owner + ";" + fin.name;
if (
(fin.getOpcode() == Opcodes.GETSTATIC || fin.getOpcode() == Opcodes.GETFIELD)
&& fin.desc.equals("Lnet/minecraft/client/renderer/Tessellator;")
&& fields.contains(hash)
) {
mn.instructions.insertBefore(in, new VarInsnNode(Opcodes.ALOAD, localIndex));
mn.instructions.remove(in);
}
}
}
mn.instructions.add(endLabel);
}
}
@@ -0,0 +1,80 @@
package com.gtnewhorizons.angelica.transform.compat;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import com.gtnewhorizons.angelica.transform.compat.handlers.CompatHandler;
import com.gtnewhorizons.angelica.transform.compat.transformers.generic.FieldLevelTessellatorTransformer;
import com.gtnewhorizons.angelica.transform.compat.transformers.generic.HUDCachingEarlyReturnTransformer;
import com.gtnewhorizons.angelica.transform.compat.transformers.generic.ThreadSafeISBRHAnnotationTransformer;
import com.gtnewhorizons.angelica.transform.compat.transformers.generic.TileEntityNullGuardTransformer;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.minecraft.launchwrapper.IClassTransformer;
import org.spongepowered.asm.lib.ClassReader;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.transformers.MixinClassWriter;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class GenericCompatTransformer implements IClassTransformer {
private static final Map<String, List<String>> fieldLevelTessellator = new Object2ObjectOpenHashMap<>();
private static final Map<String, List<String>> tileEntityNullGuard = new Object2ObjectOpenHashMap<>();
private static final Map<String, Boolean> threadSafeIBSRH = new Object2BooleanOpenHashMap<>();
private static final Map<String, List<String>> hudCachingEarlyReturn = new Object2ObjectOpenHashMap<>();
private static final Set<String> transformedClasses = new ObjectOpenHashSet<>();
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if (basicClass == null) return null;
if (!transformedClasses.contains(transformedName)) return basicClass;
ClassReader cr = new ClassReader(basicClass);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
if (fieldLevelTessellator.containsKey(transformedName)) {
FieldLevelTessellatorTransformer.transform(cn, fieldLevelTessellator.get(transformedName));
}
if (tileEntityNullGuard.containsKey(transformedName)) {
TileEntityNullGuardTransformer.transform(cn, tileEntityNullGuard.get(transformedName));
}
if (threadSafeIBSRH.containsKey(transformedName)) {
ThreadSafeISBRHAnnotationTransformer.transform(cn, threadSafeIBSRH.get(transformedName));
}
if (hudCachingEarlyReturn.containsKey(transformedName)) {
HUDCachingEarlyReturnTransformer.transform(cn, hudCachingEarlyReturn.get(transformedName));
}
MixinClassWriter cw = new MixinClassWriter(MixinClassWriter.COMPUTE_MAXS | MixinClassWriter.COMPUTE_FRAMES);
cn.accept(cw);
final byte[] bytes = cw.toByteArray();
AngelicaTweaker.dumpClass(transformedName, basicClass, bytes, this);
return bytes;
}
public static void register(CompatHandler handler) {
if (handler.getFieldLevelTessellator() != null)
fieldLevelTessellator.putAll(handler.getFieldLevelTessellator());
if (handler.getTileEntityNullGuard() != null)
tileEntityNullGuard.putAll(handler.getTileEntityNullGuard());
if (handler.getThreadSafeISBRHAnnotations() != null)
threadSafeIBSRH.putAll(handler.getThreadSafeISBRHAnnotations());
if (handler.getHUDCachingEarlyReturn() != null)
hudCachingEarlyReturn.putAll(handler.getHUDCachingEarlyReturn());
}
public static void build() {
transformedClasses.addAll(fieldLevelTessellator.keySet());
transformedClasses.addAll(tileEntityNullGuard.keySet());
transformedClasses.addAll(threadSafeIBSRH.keySet());
transformedClasses.addAll(hudCachingEarlyReturn.keySet());
}
}
@@ -0,0 +1,28 @@
package com.gtnewhorizons.angelica.transform.compat.handlers;
import java.util.List;
import java.util.Map;
public interface CompatHandler {
default Map<String, List<String>> getFieldLevelTessellator() {
return null;
}
default Map<String, List<String>> getTileEntityNullGuard() {
return null;
}
default Map<String, Boolean> getThreadSafeISBRHAnnotations() {
return null;
}
default Map<String, List<String>> getHUDCachingEarlyReturn() {
return null;
}
default List<String> extraTransformers() {
return null;
}
}
@@ -0,0 +1,40 @@
package com.gtnewhorizons.angelica.transform.compat.handlers;
import com.gtnewhorizons.angelica.config.CompatConfig;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
public enum CompatHandlers {
STACKS_ON_STACKS(() -> CompatConfig.fixStacksOnStacks, new StacksOnStacksCompatHandler()),
EXTRA_UTILS(() -> CompatConfig.fixExtraUtils, new ExtraUtilsCompatHandler()),
IMMERSIVE_ENGINEERING(() -> CompatConfig.fixImmersiveEngineering, new ImmersiveEngineeringCompatHandler()),
THAUMCRAFT(() -> CompatConfig.fixThaumcraft, new ThaumcraftCompatHandler()),
THAUMIC_HORIZONS(() -> CompatConfig.fixThaumicHorizons, new ThaumicHorizonsCompatHandler());
private final Supplier<Boolean> applyIf;
private final CompatHandler handler;
CompatHandlers(Supplier<Boolean> applyIf, CompatHandler handler) {
this.applyIf = applyIf;
this.handler = handler;
}
private static List<CompatHandler> compatHandlers = null;
public static List<CompatHandler> getHandlers() {
if (compatHandlers != null) {
return compatHandlers;
}
compatHandlers = new ArrayList<>();
for (CompatHandlers value : values()) {
if (value.applyIf.get()) {
compatHandlers.add(value.handler);
}
}
return compatHandlers;
}
}
@@ -0,0 +1,24 @@
package com.gtnewhorizons.angelica.transform.compat.handlers;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
public class ExtraUtilsCompatHandler implements CompatHandler {
@Override
public Map<String, Boolean> getThreadSafeISBRHAnnotations() {
return ImmutableMap.of(
"com.rwtema.extrautils.block.render.RenderBlockColor",
false,
"com.rwtema.extrautils.block.render.RenderBlockConnectedTextures",
true,
"com.rwtema.extrautils.block.render.RenderBlockConnectedTexturesEthereal",
true,
"com.rwtema.extrautils.block.render.RenderBlockFullBright",
false,
"com.rwtema.extrautils.block.render.RenderBlockSpike",
false);
}
}
@@ -0,0 +1,44 @@
package com.gtnewhorizons.angelica.transform.compat.handlers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.gtnewhorizons.angelica.transform.compat.transformers.specific.ImmersiveEngineeringTransformer;
import java.util.List;
import java.util.Map;
public class ImmersiveEngineeringCompatHandler implements CompatHandler {
@Override
public Map<String, List<String>> getTileEntityNullGuard() {
final List<String> renderWorldBlockExclusive = ImmutableList.of("renderWorldBlock");
return ImmutableMap.<String, List<String>>builder()
.put("blusunrize.immersiveengineering.client.render.BlockRenderClothDevices", renderWorldBlockExclusive)
.put("blusunrize.immersiveengineering.client.render.BlockRenderMetalDecoration", renderWorldBlockExclusive)
.put("blusunrize.immersiveengineering.client.render.BlockRenderMetalDevices", renderWorldBlockExclusive)
.put("blusunrize.immersiveengineering.client.render.BlockRenderMetalDevices2", renderWorldBlockExclusive)
.put("blusunrize.immersiveengineering.client.render.BlockRenderWoodenDecoration", renderWorldBlockExclusive)
.put("blusunrize.immersiveengineering.client.render.BlockRenderWoodenDevices", renderWorldBlockExclusive)
.build();
}
@Override
public Map<String, Boolean> getThreadSafeISBRHAnnotations() {
return ImmutableMap.<String, Boolean>builder()
.put("blusunrize.immersiveengineering.client.render.BlockRenderClothDevices", false)
.put("blusunrize.immersiveengineering.client.render.BlockRenderMetalDecoration", false)
.put("blusunrize.immersiveengineering.client.render.BlockRenderMetalDevices", false)
.put("blusunrize.immersiveengineering.client.render.BlockRenderMetalDevices2", false)
.put("blusunrize.immersiveengineering.client.render.BlockRenderMetalMultiblocks", false)
.put("blusunrize.immersiveengineering.client.render.BlockRenderStoneDevices", false)
.put("blusunrize.immersiveengineering.client.render.BlockRenderWoodenDecoration", false)
.put("blusunrize.immersiveengineering.client.render.BlockRenderWoodenDevices", false)
.build();
}
@Override
public List<String> extraTransformers() {
return ImmutableList.of(ImmersiveEngineeringTransformer.class.getName());
}
}
@@ -0,0 +1,33 @@
package com.gtnewhorizons.angelica.transform.compat.handlers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.gtnewhorizons.angelica.transform.compat.transformers.specific.StacksOnStacksTransformer;
import java.util.List;
import java.util.Map;
public class StacksOnStacksCompatHandler implements CompatHandler {
@Override
public Map<String, List<String>> getFieldLevelTessellator() {
return ImmutableMap
.of("com.tierzero.stacksonstacks.util.ClientUtils", ImmutableList.of("drawQuad", "drawRectangularPrism"));
}
@Override
public Map<String, List<String>> getTileEntityNullGuard() {
return ImmutableMap
.of("com.tierzero.stacksonstacks.client.render.RenderTilePile", ImmutableList.of("renderWorldBlock"));
}
@Override
public Map<String, Boolean> getThreadSafeISBRHAnnotations() {
return ImmutableMap.of("com.tierzero.stacksonstacks.client.render.RenderTilePile", true);
}
@Override
public List<String> extraTransformers() {
return ImmutableList.of(StacksOnStacksTransformer.class.getName());
}
}
@@ -0,0 +1,15 @@
package com.gtnewhorizons.angelica.transform.compat.handlers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.List;
import java.util.Map;
public class ThaumcraftCompatHandler implements CompatHandler {
@Override
public Map<String, List<String>> getHUDCachingEarlyReturn() {
return ImmutableMap.of("thaumcraft.client.lib.RenderEventHandler", ImmutableList.of("renderOverlay"));
}
}
@@ -0,0 +1,16 @@
package com.gtnewhorizons.angelica.transform.compat.handlers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.List;
import java.util.Map;
public class ThaumicHorizonsCompatHandler implements CompatHandler {
@Override
public Map<String, List<String>> getHUDCachingEarlyReturn() {
return ImmutableMap
.of("com.kentington.thaumichorizons.client.lib.RenderEventHandler", ImmutableList.of("renderOverlay"));
}
}
@@ -0,0 +1,88 @@
package com.gtnewhorizons.angelica.transform.compat.transformers.generic;
import com.gtnewhorizons.angelica.transform.AsmUtil;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.FieldInsnNode;
import org.spongepowered.asm.lib.tree.InsnList;
import org.spongepowered.asm.lib.tree.LabelNode;
import org.spongepowered.asm.lib.tree.LocalVariableNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.lib.tree.VarInsnNode;
import java.util.ArrayList;
import java.util.List;
public class FieldLevelTessellatorTransformer {
public static void transform(ClassNode cn, List<String> patchMethods) {
for (MethodNode method : cn.methods) {
if (patchMethods.contains(method.name)) {
injectLocalTessellatorAndReplaceFieldUsage(method);
}
}
}
private static void injectLocalTessellatorAndReplaceFieldUsage(MethodNode mn) {
// This part searches the instructions to see if there is any usage of a Tessellator field
// which is NOT owned by Minecraft itself. This means anyone that caches it into a field will get caught
// but not direct usage of Tessellator.instance.whatever()
List<String> fields = new ArrayList<>();
for (int i = 0; i < mn.instructions.size(); i++) {
AbstractInsnNode in = mn.instructions.get(i);
if (in instanceof FieldInsnNode fin) {
if ((fin.getOpcode() == Opcodes.GETSTATIC || fin.getOpcode() == Opcodes.GETFIELD)
&& fin.desc.equals("Lnet/minecraft/client/renderer/Tessellator;")
&& !fin.owner.equals("net/minecraft/client/renderer/Tessellator")) {
fields.add(fin.owner + ";" + fin.name);
}
}
}
if (fields.isEmpty()) return;
// Injects a new local to store our new local Tessellator in
int localIndex = mn.maxLocals;
LabelNode startLabel = new LabelNode();
LabelNode endLabel = new LabelNode();
LocalVariableNode tesNode = new LocalVariableNode(
"tes",
"Lnet/minecraft/client/renderer/Tessellator;",
null,
startLabel,
endLabel,
localIndex);
mn.localVariables.add(tesNode);
// Actually initialize the new local Tessellator
InsnList list = new InsnList();
list.add(startLabel);
list.add(
new FieldInsnNode(
Opcodes.GETSTATIC,
"net/minecraft/client/renderer/Tessellator",
AsmUtil.obf("instance", "field_78398_a"),
"Lnet/minecraft/client/renderer/Tessellator;"));
list.add(new VarInsnNode(Opcodes.ASTORE, localIndex));
mn.instructions.insert(list);
// This searches through all the instructions and finds usage of the previously discovered fields, then it
// replaces them
// with an ALOAD for our new local instead of the GETSTATIC/GETFIELD
for (int i = 0; i < mn.instructions.size(); i++) {
AbstractInsnNode in = mn.instructions.get(i);
if (in instanceof FieldInsnNode fin) {
String hash = fin.owner + ";" + fin.name;
if ((fin.getOpcode() == Opcodes.GETSTATIC || fin.getOpcode() == Opcodes.GETFIELD)
&& fin.desc.equals("Lnet/minecraft/client/renderer/Tessellator;")
&& fields.contains(hash)) {
mn.instructions.insertBefore(in, new VarInsnNode(Opcodes.ALOAD, localIndex));
mn.instructions.remove(in);
}
}
}
mn.instructions.add(endLabel);
}
}
@@ -0,0 +1,42 @@
package com.gtnewhorizons.angelica.transform.compat.transformers.generic;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.InsnList;
import org.spongepowered.asm.lib.tree.InsnNode;
import org.spongepowered.asm.lib.tree.JumpInsnNode;
import org.spongepowered.asm.lib.tree.LabelNode;
import org.spongepowered.asm.lib.tree.MethodInsnNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import java.util.List;
public class HUDCachingEarlyReturnTransformer {
private static final String HUDCaching = "com/gtnewhorizons/angelica/hudcaching/HUDCaching$HUDCachingHooks";
public static void transform(ClassNode cn, List<String> patchMethods) {
for (MethodNode method : cn.methods) {
if (patchMethods.contains(method.name)) {
InsnList list = new InsnList();
LabelNode exitLabel = new LabelNode();
list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, HUDCaching, "shouldReturnEarly", "()Z", false));
list.add(new JumpInsnNode(Opcodes.IFEQ, exitLabel));
if (method.desc.endsWith("Z") || method.desc.endsWith("I")) {
list.add(new InsnNode(Opcodes.ICONST_0));
list.add(new InsnNode(Opcodes.IRETURN));
} else if (method.desc.endsWith("V")) {
list.add(new InsnNode(Opcodes.RETURN));
} else {
AngelicaTweaker.LOGGER.warn(
"HUDCaching Conditional Return - Unknown return type: {}#{}:{}", cn.name, method.name, method.desc
);
return;
}
list.add(exitLabel);
method.instructions.insert(list);
}
}
}
}
@@ -0,0 +1,20 @@
package com.gtnewhorizons.angelica.transform.compat.transformers.generic;
import org.spongepowered.asm.lib.tree.AnnotationNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import java.util.ArrayList;
import java.util.Arrays;
public class ThreadSafeISBRHAnnotationTransformer {
public static void transform(ClassNode cn, boolean perThread) {
if (cn.visibleAnnotations == null) {
cn.visibleAnnotations = new ArrayList<>();
}
AnnotationNode isbrhAnnotation = new AnnotationNode("Lcom/gtnewhorizons/angelica/api/ThreadSafeISBRH;");
isbrhAnnotation.values = Arrays.asList("perThread", perThread);
cn.visibleAnnotations.add(isbrhAnnotation);
}
}
@@ -0,0 +1,95 @@
package com.gtnewhorizons.angelica.transform.compat.transformers.generic;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import com.gtnewhorizons.angelica.transform.AsmUtil;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.InsnList;
import org.spongepowered.asm.lib.tree.InsnNode;
import org.spongepowered.asm.lib.tree.JumpInsnNode;
import org.spongepowered.asm.lib.tree.LabelNode;
import org.spongepowered.asm.lib.tree.MethodInsnNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.lib.tree.TypeInsnNode;
import org.spongepowered.asm.lib.tree.VarInsnNode;
import java.util.List;
public class TileEntityNullGuardTransformer {
public static void transform(ClassNode cn, List<String> patchMethods) {
for (MethodNode method : cn.methods) {
if (patchMethods.contains(method.name)) {
injectGetTileEntityNullGuard(method);
}
}
}
public static void injectGetTileEntityNullGuard(MethodNode mn) {
/*
* Searching for the following pattern:
* L0 {
* ...
* INVOKEINTERFACE net/minecraft/world/IBlockAccess.getTileEntity(III)Lnet/minecraft/tileentity/TileEntity;
* CHECKCAST *
* ASTORE x
* }
* L1 {...
* Then injecting the following after the ASTORE such that we get
* L0 {
* ASTORE x
* ALOAD x
* IFNONNULL L1
* ICONST_0
* IRETURN
* }
* L1 {...
* Ultimately this converts:
* MyTileEntity tile = (MyTileEntity) world.getTileEntity(x, y, z);
* doSomethingWithTileEntity(tile);
* into:
* MyTileEntity tile = (MyTileEntity) world.getTileEntity(x, y, z);
* if (tile == null) {
* return false;
* } else {
* doSomethingWithTileEntity(tile);
* }
*/
for (int i = 0; i < mn.instructions.size(); i++) {
AbstractInsnNode in = mn.instructions.get(i);
if (in instanceof MethodInsnNode min) {
if (min.getOpcode() == Opcodes.INVOKEINTERFACE
&& min.name.equals(AsmUtil.obf("getTileEntity", "func_147438_o"))
&& min.owner.equals("net/minecraft/world/IBlockAccess")) {
AbstractInsnNode castNodeAbstract = min.getNext();
if (castNodeAbstract instanceof TypeInsnNode castNodeType) {
if (castNodeType.getOpcode() == Opcodes.CHECKCAST) {
AbstractInsnNode astoreNodeAbstract = castNodeType.getNext();
if (astoreNodeAbstract instanceof VarInsnNode astoreNodeVar) {
if (astoreNodeVar.getOpcode() == Opcodes.ASTORE) {
InsnList list = new InsnList();
LabelNode exit = new LabelNode();
list.add(new VarInsnNode(Opcodes.ALOAD, astoreNodeVar.var));
list.add(new JumpInsnNode(Opcodes.IFNONNULL, exit));
if (mn.desc.endsWith("Z") || mn.desc.endsWith("I")) {
list.add(new InsnNode(Opcodes.ICONST_0));
list.add(new InsnNode(Opcodes.IRETURN));
} else if (mn.desc.endsWith("V")) {
list.add(new InsnNode(Opcodes.RETURN));
} else {
AngelicaTweaker.LOGGER.warn("TileEntityNullGuard - Unknown Return Type: {}:{}", mn.name, mn.desc);
return;
}
list.add(exit);
mn.instructions.insert(astoreNodeVar, list);
}
}
}
}
}
}
}
}
}
@@ -0,0 +1,108 @@
package com.gtnewhorizons.angelica.transform.compat.transformers.specific;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import net.minecraft.launchwrapper.IClassTransformer;
import org.spongepowered.asm.lib.ClassReader;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.FieldInsnNode;
import org.spongepowered.asm.lib.tree.InsnNode;
import org.spongepowered.asm.lib.tree.JumpInsnNode;
import org.spongepowered.asm.lib.tree.MethodInsnNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.transformers.MixinClassWriter;
import java.util.ArrayList;
import java.util.List;
public class ImmersiveEngineeringTransformer implements IClassTransformer {
private static final String BlockRenderClothDevices = "blusunrize.immersiveengineering.client.render.BlockRenderClothDevices";
private static final String BlockRenderMetalDevices2 = "blusunrize.immersiveengineering.client.render.BlockRenderMetalDevices2";
private static final String BlockRenderStoneDevices = "blusunrize.immersiveengineering.client.render.BlockRenderStoneDevices";
private static final String ClientUtils = "blusunrize.immersiveengineering.client.ClientUtils";
private static final List<String> transformedClasses = new ArrayList<>();
private static final List<String> staticRenderPassPatches = new ArrayList<>();
static {
transformedClasses.add(BlockRenderClothDevices);
transformedClasses.add(BlockRenderMetalDevices2);
transformedClasses.add(BlockRenderStoneDevices);
transformedClasses.add(ClientUtils);
staticRenderPassPatches.add(BlockRenderClothDevices);
staticRenderPassPatches.add(BlockRenderMetalDevices2);
staticRenderPassPatches.add(BlockRenderStoneDevices);
}
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if (basicClass == null) return null;
if (!transformedClasses.contains(transformedName)) return basicClass;
final ClassReader cr = new ClassReader(basicClass);
final ClassNode cn = new ClassNode();
cr.accept(cn, 0);
if (transformedName.equals(ClientUtils)) {
transformClientUtils(cn);
}
if (staticRenderPassPatches.contains(transformedName)) {
staticRenderPassPatcher(cn);
}
MixinClassWriter cw = new MixinClassWriter(MixinClassWriter.COMPUTE_FRAMES);
cn.accept(cw);
final byte[] bytes = cw.toByteArray();
AngelicaTweaker.LOGGER.info("[AngelicaCompat]Extra Transformers: Applied ImmersiveEngineeringTransformer");
AngelicaTweaker.dumpClass(transformedName, basicClass, bytes, this);
return bytes;
}
private void staticRenderPassPatcher(ClassNode cn) {
for (MethodNode mn : cn.methods) {
if (mn.name.equals("renderWorldBlock")) {
for (int i = 0; i < mn.instructions.size(); i++) {
AbstractInsnNode ain = mn.instructions.get(i);
// So far every one of these has been named renderPass, eventually might need to make the name dynamic and possibly care about owner?
// Maybe this is common in other mods, possibly could generalize this transformation further if it comes up more.
if (ain instanceof FieldInsnNode fin && fin.getOpcode() == Opcodes.GETSTATIC && fin.name.equals("renderPass")) {
MethodInsnNode getRenderPass = new MethodInsnNode(Opcodes.INVOKESTATIC, "net/minecraftforge/client/ForgeHooksClient", "getWorldRenderPass", "()I");
mn.instructions.insert(fin, getRenderPass);
mn.instructions.remove(fin);
}
}
}
}
}
private void transformClientUtils(ClassNode cn) {
for (MethodNode mn : cn.methods) {
// This patches an if (world != null) check to just be if (false) in order to make the block of code not run
// The block of code in question calls OpenGL to update the lightmap texture coordinates, which is illegal from an ISBRH
// in Angelica. It doesn't seem to make anything not work by causing this to not happen.
if (mn.name.equals("renderStaticWavefrontModelWithIcon") || mn.name.equals("renderStaticWavefrontModel")) {
if (
mn.desc.equals("(Lnet/minecraft/world/IBlockAccess;IIILnet/minecraftforge/client/model/obj/WavefrontObject;Lnet/minecraft/util/IIcon;Lnet/minecraft/client/renderer/Tessellator;Lblusunrize/immersiveengineering/common/util/chickenbones/Matrix4;Lblusunrize/immersiveengineering/common/util/chickenbones/Matrix4;IZFFF[Ljava/lang/String;)V")
|| mn.desc.equals("(Lnet/minecraft/world/IBlockAccess;IIILnet/minecraftforge/client/model/obj/WavefrontObject;Lnet/minecraft/client/renderer/Tessellator;Lblusunrize/immersiveengineering/common/util/chickenbones/Matrix4;Lblusunrize/immersiveengineering/common/util/chickenbones/Matrix4;IZFFF[Ljava/lang/String;)V")
) {
for (int i = 0; i < mn.instructions.size(); i++) {
AbstractInsnNode ain = mn.instructions.get(i);
if (ain instanceof JumpInsnNode jump && jump.getOpcode() == Opcodes.IFNULL) {
InsnNode iconst = new InsnNode(Opcodes.ICONST_0);
jump.setOpcode(Opcodes.IFEQ);
mn.instructions.insertBefore(jump, iconst);
break;
}
}
}
}
}
}
}
@@ -1,26 +1,23 @@
package com.gtnewhorizons.angelica.transform.compat;
package com.gtnewhorizons.angelica.transform.compat.transformers.specific;
import com.google.common.collect.ImmutableList;
import com.gtnewhorizons.angelica.loading.AngelicaTweaker;
import net.minecraft.launchwrapper.IClassTransformer;
import org.spongepowered.asm.lib.ClassWriter;
import org.spongepowered.asm.lib.ClassReader;
import org.spongepowered.asm.lib.ClassWriter;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.AnnotationNode;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.lib.tree.FieldInsnNode;
import org.spongepowered.asm.lib.tree.FieldNode;
import org.spongepowered.asm.lib.tree.InsnList;
import org.spongepowered.asm.lib.tree.InsnNode;
import org.spongepowered.asm.lib.tree.JumpInsnNode;
import org.spongepowered.asm.lib.tree.LabelNode;
import org.spongepowered.asm.lib.tree.MethodInsnNode;
import org.spongepowered.asm.lib.tree.MethodNode;
import org.spongepowered.asm.lib.tree.TypeInsnNode;
import org.spongepowered.asm.lib.tree.VarInsnNode;
import java.util.ArrayList;
import java.util.List;
public class StacksOnStacksTransformer implements IClassTransformer {
@@ -49,6 +46,7 @@ public class StacksOnStacksTransformer implements IClassTransformer {
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
final byte[] bytes = cw.toByteArray();
AngelicaTweaker.LOGGER.info("[AngelicaCompat]Extra Transformers: Applied StacksOnStacksTransformer");
AngelicaTweaker.dumpClass(transformedName, basicClass, bytes, this);
return bytes;
}
@@ -56,7 +54,7 @@ public class StacksOnStacksTransformer implements IClassTransformer {
/**
* Injects initializers for the field level PileRender objects which used to be static into the <init>
*/
private InsnList injectPileRenderInitializer(MethodNode mn, String type) {
private static InsnList buildPilerRenderInitializer(String type) {
LabelNode start = new LabelNode();
LabelNode end = new LabelNode();
InsnList list = new InsnList();
@@ -64,13 +62,23 @@ public class StacksOnStacksTransformer implements IClassTransformer {
list.add(new VarInsnNode(Opcodes.ALOAD, 0));
list.add(new TypeInsnNode(Opcodes.NEW, "com/tierzero/stacksonstacks/client/render/PileRender" + type));
list.add(new InsnNode(Opcodes.DUP));
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "com/tierzero/stacksonstacks/client/render/PileRender" + type, "<init>", "()V"));
list.add(new FieldInsnNode(Opcodes.PUTFIELD, "com/tierzero/stacksonstacks/client/render/RenderTilePile", type.toLowerCase() + "Render", "Lcom/tierzero/stacksonstacks/client/render/PileRender;"));
list.add(
new MethodInsnNode(
Opcodes.INVOKESPECIAL,
"com/tierzero/stacksonstacks/client/render/PileRender" + type,
"<init>",
"()V"));
list.add(
new FieldInsnNode(
Opcodes.PUTFIELD,
"com/tierzero/stacksonstacks/client/render/RenderTilePile",
type.toLowerCase() + "Render",
"Lcom/tierzero/stacksonstacks/client/render/PileRender;"));
list.add(end);
return list;
}
private void transformRenderTilePile(ClassNode cn) {
private static void transformRenderTilePile(ClassNode cn) {
MethodNode clinit = null;
for (MethodNode mn : cn.methods) {
// Handles injecting field initializers for the various PileRender fields which used to be static
@@ -83,11 +91,12 @@ public class StacksOnStacksTransformer implements IClassTransformer {
if (ain.getOpcode() == Opcodes.RETURN) mn.instructions.remove(ain);
if (ain.getOpcode() == Opcodes.INVOKESPECIAL) objectInsn = mn.instructions.get(i);
}
// Build the initializer InsnLists and then insert them in reverse order, such that the dustRender comes last
// Build the initializer InsnLists and then insert them in reverse order, such that the dustRender comes
// last
// because we are adding the return opcode back in as part of that one's InsnList
InsnList ingotRender = injectPileRenderInitializer(mn, "Ingot");
InsnList gemRender = injectPileRenderInitializer(mn, "Gem");
InsnList dustRender = injectPileRenderInitializer(mn, "Dust");
InsnList ingotRender = buildPilerRenderInitializer("Ingot");
InsnList gemRender = buildPilerRenderInitializer("Gem");
InsnList dustRender = buildPilerRenderInitializer("Dust");
dustRender.add(new InsnNode(Opcodes.RETURN));
mn.instructions.insert(objectInsn, dustRender);
mn.instructions.insert(objectInsn, gemRender);
@@ -100,33 +109,26 @@ public class StacksOnStacksTransformer implements IClassTransformer {
if (mn.name.equals("renderWorldBlock")) {
for (int i = 0; i < mn.instructions.size(); i++) {
AbstractInsnNode in = mn.instructions.get(i);
// This part removes the GETSTATIC for the field level PileRender objects which used to be static, and replaces them with
// This part removes the GETSTATIC for the field level PileRender objects which used to be static,
// and replaces them with
// a non-static GETFIELD
if (in instanceof FieldInsnNode fin) {
if (fin.getOpcode() == Opcodes.GETSTATIC && staticRemovers.contains(fin.name)) {
FieldInsnNode nonStatic = new FieldInsnNode(Opcodes.GETFIELD, "com/tierzero/stacksonstacks/client/render/RenderTilePile", fin.name, "Lcom/tierzero/stacksonstacks/client/render/PileRender;");
FieldInsnNode nonStatic = new FieldInsnNode(
Opcodes.GETFIELD,
"com/tierzero/stacksonstacks/client/render/RenderTilePile",
fin.name,
"Lcom/tierzero/stacksonstacks/client/render/PileRender;");
mn.instructions.insertBefore(fin, new VarInsnNode(Opcodes.ALOAD, 0));
mn.instructions.insertBefore(fin, nonStatic);
mn.instructions.remove(fin);
}
}
// Adds a null guard for the IBlockAccess.getTileEntity call
if (in instanceof VarInsnNode vin) {
if (vin.getOpcode() == Opcodes.ASTORE && vin.var == 8) {
InsnList list = new InsnList();
LabelNode exit = new LabelNode();
list.add(new VarInsnNode(Opcodes.ALOAD, 8));
list.add(new JumpInsnNode(Opcodes.IFNONNULL, exit));
list.add(new InsnNode(Opcodes.ICONST_0));
list.add(new InsnNode(Opcodes.IRETURN));
list.add(exit);
mn.instructions.insert(vin, list);
}
}
}
}
}
// Remove clinit after iterating. Nothing else happens in here besides the field initialization, so no reason to drill down
// Remove clinit after iterating. Nothing else happens in here besides the field initialization, so no reason to
// drill down
// into the instructions
if (clinit != null) cn.methods.remove(clinit);
@@ -136,17 +138,9 @@ public class StacksOnStacksTransformer implements IClassTransformer {
fn.access = fn.access & (~Opcodes.ACC_STATIC);
}
}
// Add a ThreadSafeISBRH annotation
AnnotationNode isbrhAnnotation = new AnnotationNode("Lcom/gtnewhorizons/angelica/api/ThreadSafeISBRH;");
isbrhAnnotation.values = ImmutableList.of("perThread", true);
if (cn.visibleAnnotations == null) {
cn.visibleAnnotations = new ArrayList<>();
}
cn.visibleAnnotations.add(isbrhAnnotation);
}
private void transformClientUtils(ClassNode cn) {
private static void transformClientUtils(ClassNode cn) {
// Various things throughout the ISBRH call these functions which in turn call GL11.glPush/PopMatrix
// Upon checking, these aren't called anywhere but in the ISBRH, and they're entirely unnecessary in there.
// This just makes the methods no-op, since they aren't required by any other part of the mod to be working.
@@ -0,0 +1,5 @@
package com.gtnewhorizons.angelica.zoom;
public interface IMouseFilterExt {
void angelica$reset();
}
@@ -0,0 +1,53 @@
package com.gtnewhorizons.angelica.zoom;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.MathHelper;
import org.lwjgl.input.Keyboard;
public class Zoom {
@Getter
private static float zoom = 4.0F;
@Getter
private static final KeyBinding zoomKey = new KeyBinding("Zoom", 0, "key.categories.misc");
public static final float ZOOM_MIN = 1.0F;
public static final float ZOOM_MAX = 64.0F;
public static final float ZOOM_STEP = 1.2F;
private static boolean lastSmoothCameraState = false;
public static void init() {
ClientRegistry.registerKeyBinding(zoomKey);
FMLCommonHandler.instance().bus().register(new Zoom());
}
public static void modifyZoom(int eventDWheel) {
if (eventDWheel == 0) return;
zoom = MathHelper.clamp_float((float) (zoom * Math.pow(ZOOM_STEP, Integer.signum(eventDWheel))), ZOOM_MIN, ZOOM_MAX);
}
@SubscribeEvent
public void onKeyPress(InputEvent.KeyInputEvent e) {
final int keyCode = zoomKey.getKeyCode();
if (keyCode == 0 || Keyboard.getEventKey() != keyCode || Keyboard.isRepeatEvent()) return;
final Minecraft mc = Minecraft.getMinecraft();
if (Keyboard.getEventKeyState()) {
lastSmoothCameraState = mc.gameSettings.smoothCamera;
mc.gameSettings.smoothCamera = true;
} else {
zoom = 4.0F;
if (mc.gameSettings.smoothCamera != lastSmoothCameraState) {
((IMouseFilterExt) mc.entityRenderer.mouseFilterXAxis).angelica$reset();
((IMouseFilterExt) mc.entityRenderer.mouseFilterYAxis).angelica$reset();
}
mc.gameSettings.smoothCamera = lastSmoothCameraState;
}
}
}
@@ -17,7 +17,7 @@ public class SodiumDebugScreenHandler {
public void onRenderGameOverlayTextEvent(RenderGameOverlayEvent.Text event) {
final Minecraft mc = Minecraft.getMinecraft();
if (mc.gameSettings.showDebugInfo) {
event.right.add(2, "Off-Heap: +" + ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed() / 1024L / 1024L + "MB");
event.right.add(Math.min(event.right.size(), 2), "Off-Heap: +" + ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed() / 1024L / 1024L + "MB");
event.right.add("");
event.right.add("Sodium (Embeddium) Renderer");
@@ -2,7 +2,6 @@ package net.coderbot.iris.client;
import com.gtnewhorizons.angelica.AngelicaMod;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.mitchej123.hodgepodge.client.HodgepodgeClient;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.coderbot.iris.Iris;
@@ -39,7 +38,7 @@ public class IrisDebugScreenHandler {
public void onRenderGameOverlayTextEvent(RenderGameOverlayEvent.Text event) {
final Minecraft mc = Minecraft.getMinecraft();
if (mc.gameSettings.showDebugInfo) {
event.right.add(2, "Direct Buffers: +" + iris$humanReadableByteCountBin(iris$directPool.getMemoryUsed()));
event.right.add(Math.min(event.right.size(), 2), "Direct Buffers: +" + iris$humanReadableByteCountBin(iris$directPool.getMemoryUsed()));
event.right.add("");
@@ -49,8 +48,8 @@ public class IrisDebugScreenHandler {
} else {
event.right.add("[" + Iris.MODNAME + "] Shaders are disabled");
}
if(AngelicaConfig.speedupAnimations) {
event.right.add(9, "animationsMode: " + AngelicaMod.animationsMode);
if (AngelicaConfig.speedupAnimations) {
event.right.add(Math.min(event.right.size(), 9), "animationsMode: " + AngelicaMod.animationsMode);
}
Iris.getPipelineManager().getPipeline().ifPresent(pipeline -> pipeline.addDebugText(event.left));
@@ -6,8 +6,13 @@ import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.shader.ShaderType;
import net.coderbot.iris.pipeline.transform.parameter.Parameters;
import net.coderbot.iris.pipeline.transform.parameter.AttributeParameters;
import org.antlr.v4.runtime.BailErrorStrategy;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ConsoleErrorListener;
import org.antlr.v4.runtime.DefaultErrorStrategy;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.taumc.glsl.Util;
@@ -130,6 +135,18 @@ public class ShaderTransformer {
}
}
private static void configureNoError(Parser parser) {
parser.setErrorHandler(new BailErrorStrategy());
parser.removeErrorListeners();
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
}
private static void configureError(Parser parser) {
parser.setErrorHandler(new DefaultErrorStrategy());
parser.addErrorListener(ConsoleErrorListener.INSTANCE);
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
}
private static <P extends Parameters> Map<PatchShaderType, String> transformInternal(EnumMap<PatchShaderType, String> inputs, Patch patchType, P parameters) {
EnumMap<PatchShaderType, String> result = new EnumMap<>(PatchShaderType.class);
EnumMap<PatchShaderType, GLSLParser.Translation_unitContext> types = new EnumMap<>(PatchShaderType.class);
@@ -186,28 +203,22 @@ public class ShaderTransformer {
GLSLLexer lexer = new GLSLLexer(CharStreams.fromString(input));
GLSLParser parser = new GLSLParser(new CommonTokenStream(lexer));
parser.setBuildParseTree(true);
var translationUnit = parser.translation_unit();
configureNoError(parser);
switch(patchType) {
case SODIUM_TERRAIN:
SodiumTransformer.transform(translationUnit, parameters);
break;
case COMPOSITE:
CompositeDepthTransformer.transform(translationUnit);
break;
case ATTRIBUTES:
AttributeTransformer.transform(translationUnit, (AttributeParameters) parameters, profile, versionInt);
break;
default:
throw new IllegalStateException("Unknown patch type: " + patchType.name());
GLSLParser.Translation_unitContext translationUnit;
try {
translationUnit = doTransform(parser, patchType, parameters, profile, versionInt);
} catch (Exception e) {
lexer.reset();
parser.reset();
configureError(parser);
translationUnit = doTransform(parser, patchType, parameters, profile, versionInt);
}
// Check if we need to patch in texture LOD extension enabling
if (versionInt <= 120 && (Util.containsCall(translationUnit, "texture2DLod") || Util.containsCall(translationUnit, "texture3DLod"))) {
textureLodExtensionPatches.add(translationUnit);
}
CompatibilityTransformer.transformEach(translationUnit, parameters);
types.put(type, translationUnit);
prepatched.put(type, profileString);
}
@@ -230,6 +241,25 @@ public class ShaderTransformer {
return result;
}
private static GLSLParser.Translation_unitContext doTransform(GLSLParser parser, Patch patchType, Parameters parameters, String profile, int versionInt) {
GLSLParser.Translation_unitContext translationUnit = parser.translation_unit();
switch (patchType) {
case SODIUM_TERRAIN:
SodiumTransformer.transform(translationUnit, parameters);
break;
case COMPOSITE:
CompositeDepthTransformer.transform(translationUnit);
break;
case ATTRIBUTES:
AttributeTransformer.transform(translationUnit, (AttributeParameters) parameters, profile, versionInt);
break;
default:
throw new IllegalStateException("Unknown patch type: " + patchType.name());
}
CompatibilityTransformer.transformEach(translationUnit, parameters);
return translationUnit;
}
public static void applyIntelHd4000Workaround(GLSLParser.Translation_unitContext translationUnit) {
Util.renameFunctionCall(translationUnit, "ftransform", "iris_ftransform");
}
@@ -8,6 +8,8 @@ public net.minecraft.client.renderer.EntityRenderer field_78503_V # cameraZoom
public net.minecraft.client.renderer.EntityRenderer field_78502_W # cameraYaw
public net.minecraft.client.renderer.EntityRenderer field_78509_X # cameraPitch
public net.minecraft.client.renderer.EntityRenderer field_78530_s # farPlaneDistance
public net.minecraft.client.renderer.EntityRenderer field_78527_v # mouseFilterXAxis
public net.minecraft.client.renderer.EntityRenderer field_78526_w # mouseFilterYAxis
public net.minecraft.client.renderer.RenderGlobal field_72765_l # worldRenderers
@@ -18,8 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class MixinRenderGlobal_DestroyBlock {
@Inject(
method = "drawBlockDamageTexture(Lnet/minecraft/client/renderer/Tessellator;Lnet/minecraft/entity/EntityLivingBase;F)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;startDrawingQuads()V"),
remap = false
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;startDrawingQuads()V")
)
private void iris$beginDrawBlockDamageTexture(Tessellator tessellator, EntityLivingBase entity, float partialTicks, CallbackInfo ci, @Share("lastMin") LocalIntRef lastMin, @Share("lastMag") LocalIntRef lastMag) {
TextureInfo info = TextureInfoCache.INSTANCE.getInfo(GLStateManager.getBoundTexture());
@@ -0,0 +1,30 @@
package com.gtnewhorizons.angelica.mixins.early.angelica.zoom;
import com.gtnewhorizons.angelica.zoom.Zoom;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import net.minecraft.client.renderer.EntityRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
@Mixin(EntityRenderer.class)
public class MixinEntityRenderer_Zoom {
@ModifyReturnValue(method = "getFOVModifier", at = @At("RETURN"))
private float angelica$modifyFOV(float original) {
if (Zoom.getZoomKey().getIsKeyPressed()) {
return original / Zoom.getZoom();
}
return original;
}
@ModifyConstant(method = "updateCameraAndRender", constant = @Constant(floatValue = 8.0F))
private float angelica$modifyMouseSensitivity(float original) {
if (Zoom.getZoomKey().getIsKeyPressed()) {
return original / (1.0F + 0.2F * (Zoom.getZoom() - Zoom.ZOOM_MIN));
}
return original;
}
}
@@ -0,0 +1,21 @@
package com.gtnewhorizons.angelica.mixins.early.angelica.zoom;
import com.gtnewhorizons.angelica.zoom.Zoom;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(Minecraft.class)
public class MixinMinecraft_Zoom {
@ModifyExpressionValue(method = "runTick", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I", remap = false))
private int angelica$captureMouseWheel(int original) {
if (Zoom.getZoomKey().getIsKeyPressed()) {
Zoom.modifyZoom(original);
return 0;
}
return original;
}
}
@@ -0,0 +1,26 @@
package com.gtnewhorizons.angelica.mixins.early.angelica.zoom;
import com.gtnewhorizons.angelica.zoom.IMouseFilterExt;
import net.minecraft.util.MouseFilter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(MouseFilter.class)
public class MixinMouseFilter implements IMouseFilterExt {
@Shadow
private float field_76336_a;
@Shadow
private float field_76334_b;
@Shadow
private float field_76335_c;
@Override
public void angelica$reset() {
this.field_76336_a = 0.0F;
this.field_76334_b = 0.0F;
this.field_76335_c = 0.0F;
}
}
@@ -46,7 +46,7 @@ public abstract class MixinEntityRenderer implements IResourceManagerReloadListe
pipeline.get().beginLevelRendering();
}
@Inject(method = "renderWorld(FJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;dispatchRenderLast(Lnet/minecraft/client/renderer/RenderGlobal;F)V"))
@Inject(method = "renderWorld(FJ)V", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;dispatchRenderLast(Lnet/minecraft/client/renderer/RenderGlobal;F)V", remap = false))
private void iris$endLevelRender(float partialTicks, long limitTime, CallbackInfo callback, @Share("pipeline") LocalRef<WorldRenderingPipeline> pipeline) {
// TODO: Iris
final Camera camera = new Camera(mc.renderViewEntity, partialTicks);
@@ -109,7 +109,7 @@ public abstract class MixinEntityRenderer implements IResourceManagerReloadListe
pipeline.get().setPhase(WorldRenderingPhase.NONE);
}
@WrapOperation(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;drawBlockDamageTexture(Lnet/minecraft/client/renderer/Tessellator;Lnet/minecraft/entity/EntityLivingBase;F)V"))
@WrapOperation(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;drawBlockDamageTexture(Lnet/minecraft/client/renderer/Tessellator;Lnet/minecraft/entity/EntityLivingBase;F)V", remap = false))
private void iris$blockDamageTexture(RenderGlobal instance, Tessellator tessellator, EntityLivingBase entity, float partialTicks, Operation<Void> original, @Share("pipeline") LocalRef<WorldRenderingPipeline> pipeline) {
pipeline.get().setPhase(WorldRenderingPhase.DESTROY);
original.call(instance, tessellator, entity, partialTicks);
@@ -1,15 +0,0 @@
package com.gtnewhorizons.angelica.mixins.late.client.journeymap;
import journeymap.client.render.map.TileDrawStep;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(TileDrawStep.class)
public class MixinTileDrawStep {
@Redirect(method = "*", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Ljourneymap/client/render/map/TileDrawStep;debug:Z", remap = false))
private boolean getDebug(TileDrawStep instance) {
return false;
}
}