add config

This commit is contained in:
Ellpeck 2018-10-22 20:18:54 +02:00
parent 6f66c40036
commit 0b1036009e
3 changed files with 49 additions and 5 deletions

View file

@ -0,0 +1,26 @@
package de.ellpeck.naturesaura;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.RangeDouble;
@Config(modid = NaturesAura.MOD_ID, category = "")
public final class ModConfig {
public static General general = new General();
public static Client client = new Client();
public static class General {
}
public static class Client {
@Comment("The percentage of particles that should be displayed, where 1 is 100% and 0 is 0%.")
@RangeDouble(min = 0, max = 1)
public double particleAmount = 1;
@Comment("If particle spawning should respect the particle setting in Minecraft's video settings screen")
public boolean respectVanillaParticleSettings = true;
}
}

View file

@ -7,8 +7,11 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
@ -45,4 +48,11 @@ public class CommonEvents {
PacketHandler.sendTo(event.getPlayer(), auraChunk.makePacket());
}
}
@SubscribeEvent
public void onConfigChanged(OnConfigChangedEvent event) {
if (NaturesAura.MOD_ID.equals(event.getModID())) {
ConfigManager.sync(NaturesAura.MOD_ID, Config.Type.INSTANCE);
}
}
}

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.particles;
import de.ellpeck.naturesaura.ModConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.ActiveRenderInfo;
@ -25,12 +26,19 @@ public final class ParticleHandler {
public static void spawnParticle(Supplier<Particle> particle, double x, double y, double z, int range) {
if (Minecraft.getMinecraft().player.getDistanceSq(x, y, z) <= range * range) {
Minecraft mc = Minecraft.getMinecraft();
int setting = mc.gameSettings.particleSetting;
if (setting == 0 ||
setting == 1 && mc.world.rand.nextInt(3) == 0 ||
setting == 2 && mc.world.rand.nextInt(10) == 0) {
PARTICLES.add(particle.get());
if (ModConfig.client.respectVanillaParticleSettings) {
int setting = mc.gameSettings.particleSetting;
if (setting != 0 &&
(setting != 1 || mc.world.rand.nextInt(3) != 0) &&
(setting != 2 || mc.world.rand.nextInt(10) != 0)) {
return;
}
}
double setting = ModConfig.client.particleAmount;
if (setting < 1 && mc.world.rand.nextDouble() > setting) {
return;
}
PARTICLES.add(particle.get());
}
}