fabric-rendering-v1-16.2.0+bee81f016f.jar

Download file
    package net.fabricmc.fabric.mixin.client.rendering;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.buffers.GpuBuffer;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.systems.RenderPass;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat.class_5596;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.impl.client.rendering.GuiRendererExtensions;
import net.fabricmc.fabric.impl.client.rendering.SpecialGuiElementRegistryImpl;
import net.fabricmc.fabric.impl.client.rendering.SpecialGuiElementRendererPool;
import net.minecraft.class_11228;
import net.minecraft.class_11239;
import net.minecraft.class_11246;
import net.minecraft.class_11256;
import net.minecraft.class_11659;
import net.minecraft.class_11661;
import net.minecraft.class_11684;
import net.minecraft.class_310;
import net.minecraft.class_4597;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
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.Coerce;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Environment(EnvType.CLIENT)
@Mixin({class_11228.class})
abstract class GuiRendererMixin implements GuiRendererExtensions {
   @Shadow
   @Final
   @Mutable
   private Map<Class<? extends class_11256>, class_11239<?>> field_59918;
   @Shadow
   @Final
   private class_4597.class_4598 field_59917;
   @Unique
   private boolean hasFabricInitialized = false;
   @Unique
   private final Map<Class<? extends class_11256>, SpecialGuiElementRendererPool<?>> rendererPools = new HashMap();
   @Unique
   private class_11659 orderedRenderCommandQueue = null;

   @Inject(
      method = {"<init>(Lnet/minecraft/class_11246;Lnet/minecraft/class_4597$class_4598;Lnet/minecraft/class_11659;Lnet/minecraft/class_11684;Ljava/util/List;)V"},
      at = {@At("RETURN")}
   )
   private void mutableSpecialElementRenderers(class_11246 state, class_4597.class_4598 vertexConsumers, class_11659 orderedRenderCommandQueue, class_11684 renderDispatcher, List list, CallbackInfo ci) {
      this.field_59918 = new IdentityHashMap(this.field_59918);
   }

   public void fabric_onReady(class_11661 entityRenderDispatcher) {
      this.orderedRenderCommandQueue = entityRenderDispatcher;
      SpecialGuiElementRegistryImpl.onReady(class_310.method_1551(), this.field_59917, entityRenderDispatcher, this.field_59918);
      this.hasFabricInitialized = true;
   }

   @Inject(
      method = {"method_70893()V"},
      at = {@At("HEAD")}
   )
   private void prePrepareSpecialElements(CallbackInfo ci) {
      this.rendererPools.values().forEach(SpecialGuiElementRendererPool::newFrame);
   }

   @Inject(
      method = {"method_70893()V"},
      at = {@At("RETURN")}
   )
   private void postPrepareSpecialElements(CallbackInfo ci) {
      this.rendererPools.values().forEach(SpecialGuiElementRendererPool::cleanUpUnusedRenderers);
   }

   @ModifyVariable(
      method = {"method_70888(Lnet/minecraft/class_11256;I)V"},
      at = @At("STORE")
   )
   private <T extends class_11256> class_11239<T> substituteSpecialElementRenderer(class_11239<T> original, T elementState) {
      if (original != null && this.hasFabricInitialized) {
         SpecialGuiElementRendererPool<T> rendererPool = (SpecialGuiElementRendererPool)this.rendererPools.computeIfAbsent(original.method_70903(), (k) -> new SpecialGuiElementRendererPool());
         return rendererPool.substitute(original, elementState, class_310.method_1551(), this.field_59917, (class_11659)Objects.requireNonNull(this.orderedRenderCommandQueue, "renderDispatcher"));
      } else {
         return original;
      }
   }

   @Inject(
      method = {"close()V"},
      at = {@At("RETURN")}
   )
   private void closeRendererPools(CallbackInfo ci) {
      this.rendererPools.values().forEach(SpecialGuiElementRendererPool::close);
   }

   @WrapOperation(
      method = {"method_70886(Lnet/minecraft/class_11228$class_11230;Lcom/mojang/blaze3d/systems/RenderPass;Lcom/mojang/blaze3d/buffers/GpuBuffer;Lcom/mojang/blaze3d/vertex/VertexFormat$class_5595;)V"},
      at = {@At(
   value = "INVOKE",
   target = "Lcom/mojang/blaze3d/systems/RenderPass;setIndexBuffer(Lcom/mojang/blaze3d/buffers/GpuBuffer;Lcom/mojang/blaze3d/vertex/VertexFormat$class_5595;)V"
)}
   )
   private void fixNonQuadIndexing(RenderPass instance, GpuBuffer buffer, VertexFormat.class_5595 indexType, Operation<Void> original, @Coerce DrawAccessor draw) {
      RenderPipeline pipeline = draw.fabric$pipeline();
      if (pipeline.usePipelineDrawModeForGui() && pipeline.getVertexFormatMode() != class_5596.field_27382) {
         RenderSystem.class_5590 shapeIndexBuffer = RenderSystem.getSequentialBuffer(pipeline.getVertexFormatMode());
         buffer = shapeIndexBuffer.method_68274(draw.fabric$indexCount());
         indexType = shapeIndexBuffer.method_31924();
      }

      original.call(new Object[]{instance, buffer, indexType});
   }
}
    
Download file