|
| 1 | +/* |
| 2 | + * This file is part of FalseTweaks. |
| 3 | + * |
| 4 | + * Copyright (C) 2022-2024 FalsePattern |
| 5 | + * All Rights Reserved |
| 6 | + * |
| 7 | + * The above copyright notice and this permission notice shall be included |
| 8 | + * in all copies or substantial portions of the Software. |
| 9 | + * |
| 10 | + * FalseTweaks is free software: you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU Lesser General Public License as published by |
| 12 | + * the Free Software Foundation, either version 3 of the License, or |
| 13 | + * (at your option) any later version. |
| 14 | + * |
| 15 | + * FalseTweaks is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU Lesser General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU Lesser General Public License |
| 21 | + * along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>. |
| 22 | + */ |
| 23 | + |
| 24 | +package com.falsepattern.falsetweaks.mixin.mixins.client.occlusion.optifastcraft; |
| 25 | + |
| 26 | +import com.falsepattern.falsetweaks.config.ModuleConfig; |
| 27 | +import com.falsepattern.falsetweaks.mixin.bridge.occlison.IRenderGlobalOptiFastcraft; |
| 28 | +import com.falsepattern.falsetweaks.modules.threadedupdates.ThreadSafeSettings; |
| 29 | +import lombok.val; |
| 30 | +import lombok.var; |
| 31 | +import org.spongepowered.asm.mixin.Mixin; |
| 32 | +import org.spongepowered.asm.mixin.Overwrite; |
| 33 | +import org.spongepowered.asm.mixin.Shadow; |
| 34 | +import org.spongepowered.asm.mixin.Unique; |
| 35 | + |
| 36 | +import net.minecraft.client.Minecraft; |
| 37 | +import net.minecraft.client.multiplayer.WorldClient; |
| 38 | +import net.minecraft.client.renderer.EntitySorter; |
| 39 | +import net.minecraft.client.renderer.RenderGlobal; |
| 40 | +import net.minecraft.client.renderer.WorldRenderer; |
| 41 | +import net.minecraft.entity.EntityLivingBase; |
| 42 | +import net.minecraft.init.Blocks; |
| 43 | +import net.minecraft.util.MathHelper; |
| 44 | + |
| 45 | +import java.nio.IntBuffer; |
| 46 | +import java.util.Arrays; |
| 47 | +import java.util.List; |
| 48 | + |
| 49 | +@Mixin(value = RenderGlobal.class, |
| 50 | + priority = -3) |
| 51 | +public abstract class RenderGlobal_DevMixin implements IRenderGlobalOptiFastcraft { |
| 52 | + @Shadow |
| 53 | + public WorldClient theWorld; |
| 54 | + |
| 55 | + @Shadow |
| 56 | + public int renderDistanceChunks; |
| 57 | + |
| 58 | + @Shadow |
| 59 | + public Minecraft mc; |
| 60 | + |
| 61 | + @Shadow |
| 62 | + public WorldRenderer[] worldRenderers; |
| 63 | + |
| 64 | + @Shadow |
| 65 | + public int renderChunksWide; |
| 66 | + |
| 67 | + @Shadow |
| 68 | + public int renderChunksTall; |
| 69 | + |
| 70 | + @Shadow |
| 71 | + public int renderChunksDeep; |
| 72 | + |
| 73 | + @Shadow |
| 74 | + public WorldRenderer[] sortedWorldRenderers; |
| 75 | + |
| 76 | + @Shadow |
| 77 | + public int minBlockX; |
| 78 | + |
| 79 | + @Shadow |
| 80 | + public int minBlockY; |
| 81 | + |
| 82 | + @Shadow |
| 83 | + public int minBlockZ; |
| 84 | + |
| 85 | + @Shadow |
| 86 | + public int maxBlockX; |
| 87 | + |
| 88 | + @Shadow |
| 89 | + public int maxBlockY; |
| 90 | + |
| 91 | + @Shadow |
| 92 | + public int maxBlockZ; |
| 93 | + |
| 94 | + @Shadow |
| 95 | + public List tileEntities; |
| 96 | + @SuppressWarnings("MissingUnique") |
| 97 | + public List worldRenderersToUpdate; |
| 98 | + |
| 99 | + @Shadow |
| 100 | + private boolean occlusionEnabled; |
| 101 | + |
| 102 | + @Shadow |
| 103 | + private int renderEntitiesStartupCounter; |
| 104 | + |
| 105 | + @Shadow |
| 106 | + private IntBuffer glOcclusionQueryBase; |
| 107 | + |
| 108 | + @Shadow |
| 109 | + private int glRenderListBase; |
| 110 | + |
| 111 | + @Shadow |
| 112 | + public abstract void onStaticEntitiesChanged(); |
| 113 | + |
| 114 | + @Shadow |
| 115 | + public abstract void markRenderersForNewPosition(int p_72722_1_, int p_72722_2_, int p_72722_3_); |
| 116 | + |
| 117 | + /** |
| 118 | + * @author FalsePattern |
| 119 | + * @reason Optifine Unpatch |
| 120 | + */ |
| 121 | + @Overwrite |
| 122 | + public void loadRenderers() { |
| 123 | + if (this.theWorld != null) { |
| 124 | + ft$updateLeafFancyGraphics(); |
| 125 | + |
| 126 | + this.renderDistanceChunks = this.mc.gameSettings.renderDistanceChunks; |
| 127 | + int i; |
| 128 | + |
| 129 | + if (this.worldRenderers != null) { |
| 130 | + for (i = 0; i < this.worldRenderers.length; ++i) { |
| 131 | + this.worldRenderers[i].stopRendering(); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + i = this.renderDistanceChunks * 2 + 1; |
| 136 | + this.renderChunksWide = i; |
| 137 | + this.renderChunksTall = 16; |
| 138 | + this.renderChunksDeep = i; |
| 139 | + this.worldRenderers = new WorldRenderer[this.renderChunksWide * this.renderChunksTall * this.renderChunksDeep]; |
| 140 | + this.sortedWorldRenderers = new WorldRenderer[this.renderChunksWide * this.renderChunksTall * this.renderChunksDeep]; |
| 141 | + int j = 0; |
| 142 | + int k = 0; |
| 143 | + this.minBlockX = 0; |
| 144 | + this.minBlockY = 0; |
| 145 | + this.minBlockZ = 0; |
| 146 | + this.maxBlockX = this.renderChunksWide; |
| 147 | + this.maxBlockY = this.renderChunksTall; |
| 148 | + this.maxBlockZ = this.renderChunksDeep; |
| 149 | + int l; |
| 150 | + |
| 151 | + for (l = 0; l < this.worldRenderersToUpdate.size(); ++l) { |
| 152 | + ((WorldRenderer) this.worldRenderersToUpdate.get(l)).needsUpdate = false; |
| 153 | + } |
| 154 | + |
| 155 | + this.worldRenderersToUpdate.clear(); |
| 156 | + this.tileEntities.clear(); |
| 157 | + this.onStaticEntitiesChanged(); |
| 158 | + |
| 159 | + for (l = 0; l < this.renderChunksWide; ++l) { |
| 160 | + for (int i1 = 0; i1 < this.renderChunksTall; ++i1) { |
| 161 | + for (int j1 = 0; j1 < this.renderChunksDeep; ++j1) { |
| 162 | + this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l] = |
| 163 | + new WorldRenderer(this.theWorld, this.tileEntities, l * 16, i1 * 16, j1 * 16, this.glRenderListBase + j); |
| 164 | + |
| 165 | + if (this.occlusionEnabled) { |
| 166 | + this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].glOcclusionQuery = this.glOcclusionQueryBase.get(k); |
| 167 | + } |
| 168 | + |
| 169 | + this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].isWaitingOnOcclusionQuery = false; |
| 170 | + this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].isVisible = true; |
| 171 | + this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].isInFrustum = true; |
| 172 | + this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].chunkIndex = k++; |
| 173 | + this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].markDirty(); |
| 174 | + this.sortedWorldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l] = |
| 175 | + this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l]; |
| 176 | + this.worldRenderersToUpdate.add(this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l]); |
| 177 | + j += 3; |
| 178 | + } |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + if (this.theWorld != null) { |
| 183 | + EntityLivingBase entitylivingbase = this.mc.renderViewEntity; |
| 184 | + |
| 185 | + if (entitylivingbase != null) { |
| 186 | + this.markRenderersForNewPosition(MathHelper.floor_double(entitylivingbase.posX), MathHelper.floor_double(entitylivingbase.posY), |
| 187 | + MathHelper.floor_double(entitylivingbase.posZ)); |
| 188 | + Arrays.sort(this.sortedWorldRenderers, new EntitySorter(entitylivingbase)); |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + this.renderEntitiesStartupCounter = 2; |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + @Unique |
| 197 | + private void ft$updateLeafFancyGraphics() { |
| 198 | + val gameSettings = mc.gameSettings; |
| 199 | + var fancyGraphics = false; |
| 200 | + if (ModuleConfig.THREADED_CHUNK_UPDATES()) { |
| 201 | + fancyGraphics = ((ThreadSafeSettings) gameSettings).ft$fancyGraphics(); |
| 202 | + } else { |
| 203 | + // This field does not exist if threaded chunk updates are used. |
| 204 | + fancyGraphics = mc.gameSettings.fancyGraphics; |
| 205 | + } |
| 206 | + Blocks.leaves.setGraphicsLevel(fancyGraphics); |
| 207 | + Blocks.leaves2.setGraphicsLevel(fancyGraphics); |
| 208 | + } |
| 209 | +} |
0 commit comments