| 1 | package net.minecraft.client;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.systems.RenderSystem;
|
| 4 | import com.mojang.renderpearl.api.device.GpuDevice;
|
| 5 | import com.mojang.serialization.Codec;
|
| 6 | import net.fabricmc.api.EnvType;
|
| 7 | import net.fabricmc.api.Environment;
|
| 8 | import net.minecraft.client.gui.screens.options.OptionsSubScreen;
|
| 9 | import net.minecraft.server.level.ParticleStatus;
|
| 10 | import net.minecraft.util.StringRepresentable;
|
| 11 | import org.jspecify.annotations.Nullable;
|
| 12 |
|
| 13 | @Environment(EnvType.CLIENT)
|
| 14 | public enum GraphicsPreset implements StringRepresentable {
|
| 15 | FAST("fast", "options.graphics.fast"),
|
| 16 | FANCY("fancy", "options.graphics.fancy"),
|
| 17 | FABULOUS("fabulous", "options.graphics.fabulous"),
|
| 18 | CUSTOM("custom", "options.graphics.custom");
|
| 19 |
|
| 20 | private final String serializedName;
|
| 21 | private final String key;
|
| 22 | public static final Codec<GraphicsPreset> CODEC = StringRepresentable.fromEnum(GraphicsPreset::values);
|
| 23 |
|
| 24 | GraphicsPreset(final String serializedName, final String key) {
|
| 25 | this.serializedName = serializedName;
|
| 26 | this.key = key;
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | public String getSerializedName() {
|
| 31 | return this.serializedName;
|
| 32 | }
|
| 33 |
|
| 34 | public String getKey() {
|
| 35 | return this.key;
|
| 36 | }
|
| 37 |
|
| 38 | public void apply(final Minecraft minecraft) {
|
| 39 | OptionsSubScreen screen = minecraft.gui != null && minecraft.gui.screen() instanceof OptionsSubScreen ? (OptionsSubScreen)minecraft.gui.screen() : null;
|
| 40 | GpuDevice device = RenderSystem.getDevice();
|
| 41 | switch (this) {
|
| 42 | case FAST: {
|
| 43 | int viewDistance = 8;
|
| 44 | set(screen, minecraft.options.biomeBlendRadius(), 1);
|
| 45 | set(screen, minecraft.options.renderDistance(), 8);
|
| 46 | set(screen, minecraft.options.prioritizeChunkUpdates(), PrioritizeChunkUpdates.NONE);
|
| 47 | set(screen, minecraft.options.simulationDistance(), 6);
|
| 48 | set(screen, minecraft.options.ambientOcclusion(), false);
|
| 49 | set(screen, minecraft.options.cloudStatus(), CloudStatus.FAST);
|
| 50 | set(screen, minecraft.options.particles(), ParticleStatus.DECREASED);
|
| 51 | set(screen, minecraft.options.mipmapLevels(), 2);
|
| 52 | set(screen, minecraft.options.entityShadows(), false);
|
| 53 | set(screen, minecraft.options.entityDistanceScaling(), 0.75);
|
| 54 | set(screen, minecraft.options.menuBackgroundBlurriness(), 2);
|
| 55 | set(screen, minecraft.options.cloudRange(), 32);
|
| 56 | set(screen, minecraft.options.cutoutLeaves(), false);
|
| 57 | set(screen, minecraft.options.improvedTransparency(), false);
|
| 58 | set(screen, minecraft.options.weatherRadius(), 5);
|
| 59 | set(screen, minecraft.options.maxAnisotropyBit(), 1);
|
| 60 | set(screen, minecraft.options.textureFiltering(), TextureFilteringMethod.NONE);
|
| 61 | break;
|
| 62 | }
|
| 63 | case FANCY: {
|
| 64 | int viewDistance = 16;
|
| 65 | set(screen, minecraft.options.biomeBlendRadius(), 2);
|
| 66 | set(screen, minecraft.options.renderDistance(), 16);
|
| 67 | set(screen, minecraft.options.prioritizeChunkUpdates(), PrioritizeChunkUpdates.PLAYER_AFFECTED);
|
| 68 | set(screen, minecraft.options.simulationDistance(), 12);
|
| 69 | set(screen, minecraft.options.ambientOcclusion(), true);
|
| 70 | set(screen, minecraft.options.cloudStatus(), CloudStatus.FANCY);
|
| 71 | set(screen, minecraft.options.particles(), ParticleStatus.ALL);
|
| 72 | set(screen, minecraft.options.mipmapLevels(), 4);
|
| 73 | set(screen, minecraft.options.entityShadows(), true);
|
| 74 | set(screen, minecraft.options.entityDistanceScaling(), 1.0);
|
| 75 | set(screen, minecraft.options.menuBackgroundBlurriness(), 5);
|
| 76 | set(screen, minecraft.options.cloudRange(), 64);
|
| 77 | set(screen, minecraft.options.cutoutLeaves(), true);
|
| 78 | set(screen, minecraft.options.improvedTransparency(), false);
|
| 79 | set(screen, minecraft.options.weatherRadius(), 10);
|
| 80 | set(screen, minecraft.options.maxAnisotropyBit(), 1);
|
| 81 | set(screen, minecraft.options.textureFiltering(), TextureFilteringMethod.RGSS);
|
| 82 | break;
|
| 83 | }
|
| 84 | case FABULOUS: {
|
| 85 | int viewDistance = 32;
|
| 86 | set(screen, minecraft.options.biomeBlendRadius(), 2);
|
| 87 | set(screen, minecraft.options.renderDistance(), 32);
|
| 88 | set(screen, minecraft.options.prioritizeChunkUpdates(), PrioritizeChunkUpdates.PLAYER_AFFECTED);
|
| 89 | set(screen, minecraft.options.simulationDistance(), 12);
|
| 90 | set(screen, minecraft.options.ambientOcclusion(), true);
|
| 91 | set(screen, minecraft.options.cloudStatus(), CloudStatus.FANCY);
|
| 92 | set(screen, minecraft.options.particles(), ParticleStatus.ALL);
|
| 93 | set(screen, minecraft.options.mipmapLevels(), 4);
|
| 94 | set(screen, minecraft.options.entityShadows(), true);
|
| 95 | set(screen, minecraft.options.entityDistanceScaling(), 1.25);
|
| 96 | set(screen, minecraft.options.menuBackgroundBlurriness(), 5);
|
| 97 | set(screen, minecraft.options.cloudRange(), 128);
|
| 98 | set(screen, minecraft.options.cutoutLeaves(), true);
|
| 99 | set(screen, minecraft.options.improvedTransparency(), true);
|
| 100 | set(screen, minecraft.options.weatherRadius(), 10);
|
| 101 | set(screen, minecraft.options.maxAnisotropyBit(), 2);
|
| 102 | if (device.getDeviceInfo().hintsAndWorkarounds().anisotropyHasKnownIssues()) {
|
| 103 | set(screen, minecraft.options.textureFiltering(), TextureFilteringMethod.RGSS);
|
| 104 | } else {
|
| 105 | set(screen, minecraft.options.textureFiltering(), TextureFilteringMethod.ANISOTROPIC);
|
| 106 | }
|
| 107 | }
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | private static <T> void set(final @Nullable OptionsSubScreen screen, final OptionInstance<T> option, final T value) {
|
| 112 | if (option.get() != value) {
|
| 113 | option.set(value);
|
| 114 | if (screen != null) {
|
| 115 | screen.resetOption(option);
|
| 116 | }
|
| 117 | }
|
| 118 | }
|
| 119 | }
|
| 120 |
|