Skip to content

Commit

Permalink
v1.2 Sodium compat
Browse files Browse the repository at this point in the history
  • Loading branch information
someaddons committed Jan 8, 2022
1 parent e1c3f09 commit c378abd
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 7 deletions.
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ minecraft {
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

repositories{
repositories {
maven {
url "https://www.cursemaven.com"
url "https://cursemaven.com"
content {
includeGroup "curse.maven"
}
}
}

Expand All @@ -93,7 +96,7 @@ mixin {

dependencies {
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}" //21

implementation fg.deobf("curse.maven:magnesium-532724:3556734")
annotationProcessor "org.spongepowered:mixin:0.8.5:processor"
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G -Djava.net.preferIPv4Stack=true
org.gradle.daemon=false
mod_version=1.1
mod_version=1.2
modid=betterfpsdist
mc_version=1.18
forge_version=38.0.12
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 2 additions & 1 deletion src/main/java/com/betterfpsdist/BetterfpsdistMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
Expand All @@ -28,7 +29,7 @@ public class BetterfpsdistMod
public BetterfpsdistMod()
{
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> "", (c, b) -> true));

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, config.getCommonConfig().ForgeConfigSpecBuilder);
Mod.EventBusSubscriber.Bus.MOD.bus().get().register(ModEventHandler.class);
Mod.EventBusSubscriber.Bus.FORGE.bus().get().register(EventHandler.class);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/com/betterfpsdist/mixin/MixinConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.betterfpsdist.mixin;

import net.minecraftforge.fml.loading.FMLLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class MixinConfig implements IMixinConfigPlugin
{
@Override
public void onLoad(final String mixinPackage)
{

}

@Override
public String getRefMapperConfig()
{
return null;
}

@Override
public boolean shouldApplyMixin(final String targetClassName, final String mixinClassName)
{
if (targetClassName.equals("net.minecraft.client.renderer.LevelRenderer"))
{
return FMLLoader.getLoadingModList().getModFileById("magnesium") == null &&
FMLLoader.getLoadingModList().getModFileById("sodium") == null;
}

return FMLLoader.getLoadingModList().getModFileById("magnesium") != null ||
FMLLoader.getLoadingModList().getModFileById("sodium") != null;
}

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

}

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

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

}

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

}
}
45 changes: 45 additions & 0 deletions src/main/java/com/betterfpsdist/mixin/Sodiummixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.betterfpsdist.mixin;

import com.betterfpsdist.config.ConfigurationCache;
import me.jellysquid.mods.sodium.client.render.chunk.RenderSection;
import me.jellysquid.mods.sodium.client.render.chunk.RenderSectionManager;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Direction;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static org.spongepowered.asm.mixin.injection.At.Shift.AFTER;

@Mixin(RenderSectionManager.class)
public class Sodiummixin
{
@Shadow(remap = false)
private float cameraX;

@Shadow(remap = false)
private float cameraY;

@Shadow(remap = false)
private float cameraZ;

@Inject(method = "addVisible", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/graph/ChunkGraphIterationQueue;add(Lme/jellysquid/mods/sodium/client/render/chunk/RenderSection;Lnet/minecraft/core/Direction;)V", remap = false, shift = AFTER), remap = false, cancellable = true)
private void isWithinRenderDistance(final RenderSection render, final Direction flow, final CallbackInfo ci)
{
if (distSqr(render.getOriginX(), render.getOriginY(), render.getOriginZ(), cameraX, cameraY, cameraZ) > (Minecraft.getInstance().options.renderDistance * 16) * (
Minecraft.getInstance().options.renderDistance * 16))
{
ci.cancel();
}
}

private double distSqr(float fromX, float fromY, float fromZ, float toX, float toY, float toZ)
{
double d0 = fromX - toX;
double d1 = fromY - toY;
double d2 = fromZ - toZ;
return d0 * d0 + ConfigurationCache.stretch * (d1 * d1) + d2 * d2;
}
}
4 changes: 3 additions & 1 deletion src/main/resources/betterfpsdist.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"package": "com.betterfpsdist.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "betterfpsdist.refmap.json",
"plugin": "com.betterfpsdist.mixin.MixinConfig",
"mixins": [
],
"client": [
"LevelRendererMixin"
"LevelRendererMixin",
"Sodiummixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit c378abd

Please sign in to comment.