Skip to content

Commit

Permalink
Dynamically modify the render distance for dropped items entities to …
Browse files Browse the repository at this point in the history
…preserve performance (#653)

* change sodium EntityMixin to use modify arg instead of @Inject that cancels all the time

* restore the 16 block render distance for dropped items

* set EntityItem render distance to 32 blocks

* dynamically reduce the render distance for dropped Item entities when there is too many

* Add dropped item limit setting to video settings

Add some missing notfine tooltip entries while I was in there

* set maximum of dropped items to 2048

---------

Co-authored-by: Jason Mitchell <mitchej@gmail.com>
  • Loading branch information
Alexdoru and mitchej123 authored Oct 16, 2024
1 parent 8c5f4d2 commit 6cf119d
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ public class AngelicaConfig {
@Config.RequiresMcRestart
public static boolean fixFluidRendererCheckingBlockAgain;

@Config.Comment("Dynamically modifies the render distance of dropped items entities to preserve performance."
+ " It starts reducing the render distance when exceeding the threshold set below.")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean dynamicItemRenderDistance;

@Config.Comment("Max amount of dropped item rendered")
@Config.DefaultInt(256)
@Config.RangeInt(min = 32, max = 2048)
public static int droppedItemLimit;

@Config.Comment("Enable Debug Logging")
@Config.DefaultBoolean(false)
@Config.RequiresMcRestart
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/gtnewhorizons/angelica/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public enum Mixins {
.setApplyIf(() -> AngelicaConfig.fixFluidRendererCheckingBlockAgain)
.addTargetedMod(TargetedMod.VANILLA)),

ANGELICA_LIMIT_DROPPED_ITEM_ENTITIES(new Builder("Dynamically modifies the render distance of dropped items entities to preserve performance")
.setPhase(Phase.EARLY).addMixinClasses("angelica.optimizations.MixinRenderGlobal_ItemRenderDist").setSide(Side.CLIENT)
.setApplyIf(() -> AngelicaConfig.dynamicItemRenderDistance)
.addTargetedMod(TargetedMod.VANILLA)),

// Not compatible with the lwjgl debug callbacks, so disable if that's enabled
ARCHAIC_SPLASH(new Builder("ArchaicFix Splash").addTargetedMod(TargetedMod.VANILLA).setSide(Side.CLIENT)
.setPhase(Phase.EARLY).setApplyIf(() -> AngelicaConfig.showSplashMemoryBar && !AngelicaMod.lwjglDebug).addMixinClasses(
Expand Down Expand Up @@ -108,7 +113,8 @@ public enum Mixins {
,"sodium.MixinChunk"
,"sodium.MixinChunkProviderServer"
,"sodium.MixinClientRegistry"
,"sodium.MixinEntity"
,"sodium.MixinEntity_RenderDist"
,"sodium.MixinEntityItem_RenderDist"
,"sodium.MixinRenderManager"
,"sodium.MixinExtendedBlockStorage"
,"sodium.MixinEntityRenderer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import me.jellysquid.mods.sodium.client.gui.options.named.GraphicsQuality;
import me.jellysquid.mods.sodium.client.gui.options.named.LightingQuality;
import me.jellysquid.mods.sodium.client.gui.options.named.ParticleMode;
import me.jellysquid.mods.sodium.client.gui.options.storage.AngelicaOptionsStorage;
import me.jellysquid.mods.sodium.client.gui.options.storage.MinecraftOptionsStorage;
import me.jellysquid.mods.sodium.client.gui.options.storage.SodiumOptionsStorage;
import me.jellysquid.mods.sodium.client.render.chunk.backends.multidraw.MultidrawChunkRenderBackend;
Expand All @@ -36,6 +37,7 @@
public class SodiumGameOptionPages {
private static final SodiumOptionsStorage sodiumOpts = new SodiumOptionsStorage();
private static final MinecraftOptionsStorage vanillaOpts = new MinecraftOptionsStorage();
private static final AngelicaOptionsStorage angelicaOpts = new AngelicaOptionsStorage();

public static OptionPage general() {
final List<OptionGroup> groups = new ArrayList<>();
Expand Down Expand Up @@ -153,6 +155,15 @@ else if(Minecraft.getMinecraft().currentScreen instanceof SodiumOptionsGUI oldGu
.add(Settings.DYNAMIC_FOV.option)
.add(Settings.MODE_WATER.option)
.add(Settings.MODE_DROPPED_ITEMS.option)
.add(
OptionImpl.createBuilder(int.class, angelicaOpts)
.setName(I18n.format("options.angelica.droppedItemLimit"))
.setTooltip(I18n.format("options.angelica.droppedItemLimit.tooltip"))
.setControl(option -> new SliderControl(option, 32, 2048, 32, ControlValueFormatter.droppedItemLimitLimit()))
.setBinding((options, value) -> AngelicaConfig.droppedItemLimit = value, options -> AngelicaConfig.droppedItemLimit)
.setImpact(OptionImpact.MEDIUM)
.build()
)
.build());

return new OptionPage(I18n.format("stat.generalButton"), ImmutableList.copyOf(groups));
Expand Down Expand Up @@ -246,7 +257,7 @@ public static OptionPage quality() {
.build())
.build());
groups.add(OptionGroup.createBuilder()
.add(Settings.MODE_GLINT_INV.option)
.add(Settings.MODE_GLINT_INV.option)
.add(Settings.MODE_GLINT_WORLD.option)
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ static ControlValueFormatter guiScale() {
static ControlValueFormatter fpsLimit() {
return (v) -> (v == 260) ? I18n.format("options.framerateLimit.max") : I18n.format("options.framerate", v);
}
static ControlValueFormatter droppedItemLimitLimit() {
return (v) -> (v == 2048) ? I18n.format("options.droppedItems.max") : I18n.format("options.droppedItems", v);
}

static ControlValueFormatter brightness() {
return (v) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.jellysquid.mods.sodium.client.gui.options.storage;

import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import me.jellysquid.mods.sodium.client.SodiumClientMod;

public class AngelicaOptionsStorage implements OptionStorage<AngelicaConfig> {

public AngelicaOptionsStorage() {

}

@Override
public AngelicaConfig getData() {
return null;
}

@Override
public void save() {
ConfigurationManager.save(AngelicaConfig.class);
SodiumClientMod.logger().info("Flushed changes to Angelica configuration");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public void save() {
throw new RuntimeException("Couldn't save configuration changes", e);
}

SodiumClientMod.logger().info("Flushed changes to Rubidium configuration");
SodiumClientMod.logger().info("Flushed changes to Angelica configuration");
}
}
5 changes: 5 additions & 0 deletions src/main/resources/assets/angelica/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ options.button.shader=Shaders...

options.chunks=%s chunks
options.entityShadows=Entity Shadows
options.droppedItems=%s items
options.droppedItems.max=Unlimited
sodium.option_impact.low=Low
sodium.option_impact.medium=Medium
sodium.option_impact.high=High
Expand Down Expand Up @@ -124,12 +126,15 @@ options.iris.setToDefault=Set option to default value?
options.iris.profile=Profile
options.iris.profile.custom=Custom
options.iris.shadowDistance=Max Shadow Distance
options.iris.shadowDistance.sodium_tooltip=Max Shadow Distance
options.iris.shadowDistance.enabled=Allows you to change the maximum distance for shadows. Terrain and entities beyond this distance will not cast shadows. Lowering the shadow distance can significantly increase performance.
options.iris.shadowDistance.disabled=Your current shader pack has already set a render distance for shadows; you cannot change it.
options.iris.gui.hide=Hide GUI
options.iris.gui.show=Show GUI
options.dynamic_lights=Dynamic Lights
options.dynamic_lights.tooltip=Enables dynamic lights. Modes: OFF - off, FASTEST - 500ms delay, FAST - 250ms delay, FANCY - no delay. Disabled if shaders are in use.
options.angelica.droppedItemLimit=Dropped Item Render Limit
options.angelica.droppedItemLimit.tooltip=The maximum number of dropped items that will be rendered. Lower values can improve performance.
pack.iris.select.title=Select
pack.iris.configure.title=Configure
label.iris.true=On
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/assets/notfine/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,52 @@ options.graphics.ultra=Ultra
options.off=Off
options.on=On
options.cloud_height=Cloud Elevation
options.cloud_height.tooltip=Cloud Elevation
options.cloud_scale=Cloud Scale
options.cloud_scale.tooltip=Cloud Scale
options.gui_background=Background
options.downfall_distance=Weather Effects
options.dynamic_fov=Dynamic FOV
options.dynamic_fov.tooltip=If enabled, the game's field of view will change based on the player's speed.
options.fog_near_distance=Near Fog Distance
options.fog_near_distance.tooltip=Near Fog Distance
options.mode_cloud_translucency=Cloud Translucency
options.mode_cloud_translucency.tooltip=Cloud Translucency
options.mode_clouds=Clouds
options.mode_clouds.tooltip=Clouds
options.mode_dropped_items=Dropped Items
options.mode_dropped_items.tooltip=Dropped Items Rendering Quality
options.mode_glint_inv=GUI Enchant VFX
options.mode_glint_inv.tooltip=GUI Enchant VFX
options.mode_glint_world=World Enchant VFX
options.mode_glint_world.tooltip=World Enchant VFX
options.mode_gui_background=Menu Backgrounds
options.mode_leaves=Foliage
options.mode_light_flicker=Light Flicker
options.mode_light_flicker.tooltip=Light Flicker
options.mode_shadows=Entity Shadows
options.mode_sky=Sky
options.mode_sky.tooltip=Render the Sky
options.mode_sun_moon=Sun & Moon
options.mode_sun_moon.tooltip=Render Sun & Moon
options.mode_stars=Stars
options.mode_stars.tooltip=Render Stars
options.mode_water=Water
options.mode_water.tooltip=Water
options.mode_vignette=Vignette
options.mode_vignette.tooltip=Vignette
options.particles_enc_table=Enchantment Particles
options.particles_enc_table.tooltip=Enchantment Particles
options.particles_void=Void Particles
options.particles_void.tooltip=Void Particles
options.render_distance_clouds=Minimum Cloud Distance
options.render_distance_clouds.tooltip=Minimum Cloud Distance
options.title.detail=Detail Settings
options.title.other=Other Settings
options.title.particle=Particle Settings
options.title.sky=Atmosphere Settings
options.title.video=Video Settings
options.total_stars=Star Density
options.total_stars.tooltip=Star Density
options.void_fog=Void Fog
options.void_fog.tooltip=Void Fog
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.gtnewhorizons.angelica.mixins.early.angelica.optimizations;

import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(RenderGlobal.class)
public class MixinRenderGlobal_ItemRenderDist {

@Unique private static final int[] sodium$entityItemCount = new int[256];
@Unique private static int sodium$itemRenderDist = 255;

@Inject(method = "renderEntities", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/RenderGlobal;countEntitiesRendered:I", ordinal = 0))
private void sodium$resetEntitycount(CallbackInfo ci) {
int entityCount = 0;
boolean reachedLimit = false;
final int itemLimit = AngelicaConfig.droppedItemLimit == 2048 ? Integer.MAX_VALUE : AngelicaConfig.droppedItemLimit;
for (int i = 0; i < sodium$entityItemCount.length; i++) {
entityCount += sodium$entityItemCount[i];
sodium$entityItemCount[i] = 0;
if (!reachedLimit && entityCount > itemLimit) {
reachedLimit = true;
sodium$itemRenderDist = i == 0 ? 1 : i;
}
}
if (!reachedLimit) {
sodium$itemRenderDist = 255;
}
}

@ModifyVariable(method = "renderEntities", at = @At(value = "STORE", ordinal = 0), ordinal = 0, name = "flag")
private boolean sodium$renderEntityItems(boolean flag,
@Local(ordinal = 0, name = "entity") Entity entity,
@Local(ordinal = 0, name = "d0") double d0,
@Local(ordinal = 1, name = "d1") double d1,
@Local(ordinal = 2, name = "d2") double d2) {
if (flag && entity instanceof EntityItem) {
final int i = Math.min((int) (entity.getDistanceSq(d0, d1, d2) / 4.0D), 255);
sodium$entityItemCount[i]++;
return i <= sodium$itemRenderDist;
}
return flag;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.gtnewhorizons.angelica.mixins.early.sodium;

import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(EntityItem.class)
public abstract class MixinEntityItem_RenderDist extends Entity {

public MixinEntityItem_RenderDist(World worldIn) {
super(worldIn);
}

@Override
public boolean isInRangeToRender3d(double x, double y, double z) {
double d3 = this.posX - x;
double d4 = this.posY - y;
double d5 = this.posZ - z;
double d6 = d3 * d3 + d4 * d4 + d5 * d5;
// set render distance to 32 blocks
return this.isInRangeToRenderDist(d6 / 4.0D);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.gtnewhorizons.angelica.mixins.early.sodium;

import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Mixin(Entity.class)
public abstract class MixinEntity_RenderDist {

@ModifyArg(method = "isInRangeToRender3d", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isInRangeToRenderDist(D)Z"))
private double sodium$afterDistCalc(double d6) {
final double mult = SodiumGameOptions.EntityRenderDistance.entityRenderDistanceMultiplier;
return d6 / (mult * mult);
}
}

0 comments on commit 6cf119d

Please sign in to comment.