Skip to content

Commit

Permalink
Expand void fog tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed May 13, 2024
1 parent 229101f commit 4e94ff0
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import mod.acgaming.universaltweaks.tweaks.performance.autosave.UTAutoSaveOFCompat;
import mod.acgaming.universaltweaks.tweaks.performance.craftingcache.UTCraftingCache;
import mod.acgaming.universaltweaks.tweaks.performance.entityradiuscheck.UTEntityRadiusCheck;
import mod.acgaming.universaltweaks.tweaks.world.voidfog.UTVoidFog;
import mod.acgaming.universaltweaks.util.UTKeybindings;
import mod.acgaming.universaltweaks.util.UTPacketHandler;
import mod.acgaming.universaltweaks.util.compat.UTObsoleteModsHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

import java.util.HashMap;
import java.util.Map;

import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import com.cleanroommc.configanytime.ConfigAnytime;
import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.core.UTLoadingPlugin;
Expand All @@ -22,6 +15,11 @@
import mod.acgaming.universaltweaks.tweaks.misc.swingthroughgrass.UTSwingThroughGrassLists;
import mod.acgaming.universaltweaks.tweaks.performance.autosave.UTAutoSaveOFCompat;
import mod.acgaming.universaltweaks.tweaks.performance.entityradiuscheck.UTEntityRadiusCheck;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Config(modid = UniversalTweaks.MODID, name = UniversalTweaks.NAME + " - Tweaks")
public class UTConfigTweaks
Expand Down Expand Up @@ -2019,6 +2017,10 @@ public static class WorldCategory
@Config.Name("Dimension Unload")
public final DimensionUnloadCategory DIMENSION_UNLOAD = new DimensionUnloadCategory();

@Config.LangKey("cfg.universaltweaks.tweaks.world.voidfog")
@Config.Name("Void Fog")
public final VoidFogCategory VOID_FOG = new VoidFogCategory();

@Config.RequiresMcRestart
@Config.Name("Sea Level")
@Config.Comment
Expand Down Expand Up @@ -2046,11 +2048,6 @@ public static class WorldCategory
})
public int utVillageDistance = 32;

@Config.RequiresMcRestart
@Config.Name("Void Fog")
@Config.Comment("Re-implements pre-1.8 void fog and void particles")
public boolean utVoidFogToggle = false;

public static class ChunkGenLimitCategory
{
@Config.RequiresMcRestart
Expand Down Expand Up @@ -2090,6 +2087,59 @@ public static class DimensionUnloadCategory
"overworld"
};
}

public static class VoidFogCategory
{
@Config.RequiresMcRestart
@Config.Name("[1] Void Fog Toggle")
@Config.Comment("Re-implements pre-1.8 void fog and void particles")
public boolean utVoidFogToggle = false;

@Config.Name("[2] Dimension List")
@Config.Comment
({
"List of dimensions concerning void fog and particles",
"Behavior depends on the list mode",
"Can be dimension name or ID"
})
public String[] utVoidFogDimensionList = new String[] {"overworld"};

@Config.Name("[3] Dimension List Mode")
@Config.Comment
({
"Blacklist Mode: Dimensions that don't have void fog and particles enabled, others do",
"Whitelist Mode: Dimensions that have void fog and particles enabled, others don't"
})
public EnumLists utVoidFogDimensionListMode = EnumLists.WHITELIST;

@Config.Name("[4] Fog In Creative/Spectator")
@Config.Comment("Renders void fog in creative and spectator mode")
public boolean utVoidFogCreativeSpectator = false;

@Config.Name("[5] Fog In Superflat")
@Config.Comment("Renders void fog in the superflat world type")
public boolean utVoidFogSuperflat = false;

@Config.Name("[6] Fog On Night Vision")
@Config.Comment("Renders void fog when the player has night vision")
public boolean utVoidFogNightVision = false;

@Config.Name("[7] Particles In Creative/Spectator")
@Config.Comment("Renders void particles in creative and spectator mode")
public boolean utVoidParticlesCreativeSpectator = true;

@Config.Name("[8] Particles In Superflat")
@Config.Comment("Renders void particles in the superflat world type")
public boolean utVoidParticlesSuperflat = false;

@Config.Name("[9] Particle Spawn Y Level")
@Config.Comment("Determines the maximum Y level of the player at which void particles are spawned")
public int utVoidParticleSpawnYLevel = 8;

@Config.Name("[10] Particle Spawn Iterations")
@Config.Comment("Determines the amount of iterations for checking void particle spawns per animate tick")
public int utVoidParticleSpawnIterations = 1000;
}
}

static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.performance.mobspawnerrender.json", () -> UTConfigTweaks.PERFORMANCE.utDisableMobSpawnerRendering);
put("mixins.tweaks.performance.resourcemanager.json", () -> UTConfigTweaks.PERFORMANCE.utCheckAnimatedModelsToggle);
put("mixins.tweaks.world.loading.client.json", () -> UTConfigTweaks.PERFORMANCE.utWorldLoadingToggle);
put("mixins.tweaks.world.voidfog.json", () -> UTConfigTweaks.WORLD.utVoidFogToggle);
put("mixins.tweaks.world.voidfog.json", () -> UTConfigTweaks.WORLD.VOID_FOG.utVoidFogToggle);
}
});
public static long launchTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package mod.acgaming.universaltweaks.tweaks.world.voidfog;

import java.util.Arrays;
import java.util.List;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import net.minecraft.world.DimensionType;
import net.minecraftforge.common.DimensionManager;

public abstract class UTVoidFog
{
public static boolean isEnabledForDimension(int dimension)
{
List<String> dimensionList = Arrays.asList(UTConfigTweaks.WORLD.VOID_FOG.utVoidFogDimensionList);
DimensionType dimensionType = DimensionManager.getProviderType(dimension);
String dimensionName = dimensionType == null ? null : dimensionType.getName();
boolean isWhitelist = UTConfigTweaks.WORLD.VOID_FOG.utVoidFogDimensionListMode == UTConfigTweaks.EnumLists.WHITELIST;
return isWhitelist == (dimensionList.contains(dimensionName) || dimensionList.contains(String.valueOf(dimension)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import mod.acgaming.universaltweaks.tweaks.world.voidfog.UTVoidFog;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.init.MobEffects;
import net.minecraft.world.WorldType;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.callback.CallbackInfo;
Expand All @@ -16,11 +20,31 @@
public abstract class UTVoidFogMixin
{
@Shadow @Final private Minecraft mc;
@Unique private boolean ut$shouldRender;

/**
* Injects ported 1.7.10 void fog code into the "setupFog" method of the EntityRenderer class.
*
* @param startCoords starting coordinates of fog effects
* @param partialTicks partial ticks for fog effects
* @param ci CallbackInfo object
* @param f1 float reference for the far plane distance
*/
@Inject(method = "setupFog", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;setFog(Lnet/minecraft/client/renderer/GlStateManager$FogMode;)V", ordinal = 4))
public void utVoidFog(int startCoords, float partialTicks, CallbackInfo ci, @Local(ordinal = 2) LocalFloatRef f1)
{
if (this.mc.world.provider.getDimension() != 0 || this.mc.world.getWorldInfo().getTerrainType() == WorldType.FLAT || this.mc.player.isCreative() || this.mc.player.isSpectator()) return;
// Only update conditions every second
if (this.mc.player.ticksExisted < 20 || this.mc.player.ticksExisted % 20 == 19)
{
ut$shouldRender = false;
if (!UTVoidFog.isEnabledForDimension(this.mc.player.dimension)) return;
if (!UTConfigTweaks.WORLD.VOID_FOG.utVoidFogSuperflat && this.mc.world.getWorldInfo().getTerrainType() == WorldType.FLAT) return;
if (!UTConfigTweaks.WORLD.VOID_FOG.utVoidFogCreativeSpectator && (this.mc.player.isCreative() || this.mc.player.isSpectator())) return;
if (!UTConfigTweaks.WORLD.VOID_FOG.utVoidFogNightVision && this.mc.player.isPotionActive(MobEffects.NIGHT_VISION)) return;
ut$shouldRender = true;
}

if (!ut$shouldRender) return;

double d0 = (double) ((this.mc.getRenderViewEntity().getBrightnessForRender() & 15728640) >> 20) / 16.0D + (this.mc.getRenderViewEntity().lastTickPosY + (this.mc.getRenderViewEntity().posY - this.mc.getRenderViewEntity().lastTickPosY) * (double) partialTicks + 4.0D) / 32.0D;

Expand All @@ -45,4 +69,4 @@ public void utVoidFog(int startCoords, float partialTicks, CallbackInfo ci, @Loc
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,68 @@
package mod.acgaming.universaltweaks.tweaks.world.voidfog.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import mod.acgaming.universaltweaks.tweaks.world.voidfog.UTVoidFog;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.profiler.Profiler;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldType;
import net.minecraft.world.storage.ISaveHandler;
import net.minecraft.world.storage.WorldInfo;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.callback.CallbackInfo;

@Mixin(WorldClient.class)
public abstract class UTVoidFogParticlesMixin extends World
{
@Shadow @Final private Minecraft mc;
@Unique private boolean ut$shouldRender;

protected UTVoidFogParticlesMixin(ISaveHandler saveHandlerIn, WorldInfo info, WorldProvider providerIn, Profiler profilerIn, boolean client)
{
super(saveHandlerIn, info, providerIn, profilerIn, client);
}

/**
* Injects ported 1.7.10 void fog particles into the game world based on configuration settings and player state.
*
* @param posX x-coordinate of the player position
* @param posY y-coordinate of the player position
* @param posZ z-coordinate of the player position
* @param ci CallbackInfo object
* @param mutableBlockPos mutable block position already used for barrier particles
*/
@Inject(method = "doVoidFogParticles", at = @At("TAIL"))
public void utVoidFogParticles(int posX, int posY, int posZ, CallbackInfo ci, @Local BlockPos.MutableBlockPos mutableBlockPos)
{
if (posY > 8) return;
// Only update conditions every second
if (this.mc.player.ticksExisted < 20 || this.mc.player.ticksExisted % 20 == 19)
{
ut$shouldRender = false;
if (!UTVoidFog.isEnabledForDimension(this.mc.player.dimension)) return;
if (!UTConfigTweaks.WORLD.VOID_FOG.utVoidParticlesSuperflat && this.mc.world.getWorldInfo().getTerrainType() == WorldType.FLAT) return;
if (!UTConfigTweaks.WORLD.VOID_FOG.utVoidParticlesCreativeSpectator && (this.mc.player.isCreative() || this.mc.player.isSpectator())) return;
if (posY > UTConfigTweaks.WORLD.VOID_FOG.utVoidParticleSpawnYLevel) return;
ut$shouldRender = true;
}

if (!ut$shouldRender) return;

byte b0 = 16;

for (int l = 0; l < 1000; ++l)
for (int l = 0; l < UTConfigTweaks.WORLD.VOID_FOG.utVoidParticleSpawnIterations; ++l)
{
int i1 = MathHelper.floor(posX) + this.rand.nextInt(b0) - this.rand.nextInt(b0);
int j1 = MathHelper.floor(posY) + this.rand.nextInt(b0) - this.rand.nextInt(b0);
Expand All @@ -45,4 +75,4 @@ public void utVoidFogParticles(int posX, int posY, int posZ, CallbackInfo ci, @L
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class UTObsoleteModsHandler
put("tramplestopper", () -> UTConfigTweaks.BLOCKS.utFarmlandTrample != UTConfigTweaks.TrampleOptions.DEFAULT);
put("unloader", () -> UTConfigTweaks.WORLD.DIMENSION_UNLOAD.utUnloaderToggle);
put("villagermantlefix", () -> UTConfigBugfixes.ENTITIES.utVillagerMantleToggle);
put("voidfog", () -> UTConfigTweaks.WORLD.utVoidFogToggle);
put("voidfog", () -> UTConfigTweaks.WORLD.VOID_FOG.utVoidFogToggle);
put("watercontrolextreme", () -> UTConfigTweaks.BLOCKS.FINITE_WATER.utFiniteWaterToggle);
}
});
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/universaltweaks/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,4 @@ cfg.universaltweaks.tweaks.misc.toastcontrol=Toast Control
cfg.universaltweaks.tweaks.performance.entityradiuscheck=Entity Radius Check
cfg.universaltweaks.tweaks.world.chunkgenlimit=Chunk Gen Limit
cfg.universaltweaks.tweaks.world.dimensionunload=Dimension Unload
cfg.universaltweaks.tweaks.world.voidfog=Void Fog

0 comments on commit 4e94ff0

Please sign in to comment.