Skip to content

Commit

Permalink
Implement void fog tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed May 12, 2024
1 parent 79bfad6 commit f227d9e
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ All changes are toggleable via config files.
* **Burning:** Lets untamed undead horses burn in daylight
* **Taming:** Allows taming of undead horses
* **Village Distance:** Sets the village generation distance in chunks
* **Void Fog:** Re-implements pre-1.8 void fog and void particles
* **Water Fall Damage:** Re-implements an improved version of pre-1.4 fall damage in water
* **Weaken Wither Structure Requirements:** Allows creating Withers with non-air blocks in the bottom corners of the structure
* **XP Bottle Amount:** Sets the amount of experience spawned by bottles o' enchanting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,11 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,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);
}
});
public static long launchTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package mod.acgaming.universaltweaks.tweaks.world.voidfog.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
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.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EntityRenderer.class)
public abstract class UTVoidFogMixin
{
@Shadow @Final private Minecraft mc;

@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;

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;

if (d0 < 1.0D)
{
if (d0 < 0.0D)
{
d0 = 0.0D;
}

d0 *= d0;
float f2 = 100.0F * (float) d0;

if (f2 < 5.0F)
{
f2 = 5.0F;
}

if (f1.get() > f2)
{
f1.set(f2);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package mod.acgaming.universaltweaks.tweaks.world.voidfog.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
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.storage.ISaveHandler;
import net.minecraft.world.storage.WorldInfo;
import org.spongepowered.asm.mixin.Mixin;
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
{
protected UTVoidFogParticlesMixin(ISaveHandler saveHandlerIn, WorldInfo info, WorldProvider providerIn, Profiler profilerIn, boolean client)
{
super(saveHandlerIn, info, providerIn, profilerIn, client);
}

@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;

byte b0 = 16;

for (int l = 0; l < 1000; ++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);
int k1 = MathHelper.floor(posZ) + this.rand.nextInt(b0) - this.rand.nextInt(b0);
IBlockState blockState = this.getBlockState(mutableBlockPos);

if (blockState.getMaterial() == Material.AIR && this.rand.nextInt(8) > j1)
{
this.spawnParticle(EnumParticleTypes.SUSPENDED_DEPTH, (float) i1 + this.rand.nextFloat(), (float) j1 + this.rand.nextFloat(), (float) k1 + this.rand.nextFloat(), 0.0D, 0.0D, 0.0D);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,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("watercontrolextreme", () -> UTConfigTweaks.BLOCKS.FINITE_WATER.utFiniteWaterToggle);
}
});
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/mixins.tweaks.world.voidfog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mod.acgaming.universaltweaks.tweaks.world.voidfog.mixin",
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"client": ["UTVoidFogMixin", "UTVoidFogParticlesMixin"]
}

0 comments on commit f227d9e

Please sign in to comment.