-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically modify the render distance for dropped items entities to …
…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
1 parent
8c5f4d2
commit 6cf119d
Showing
12 changed files
with
176 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ain/java/me/jellysquid/mods/sodium/client/gui/options/storage/AngelicaOptionsStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...rizons/angelica/mixins/early/angelica/optimizations/MixinRenderGlobal_ItemRenderDist.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
|
||
} |
24 changes: 0 additions & 24 deletions
24
src/mixin/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinEntity.java
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
...mixin/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinEntityItem_RenderDist.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/mixin/java/com/gtnewhorizons/angelica/mixins/early/sodium/MixinEntity_RenderDist.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |