diff --git a/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java b/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java index 33b79e54c7..1c992cc516 100644 --- a/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java +++ b/src/main/java/net/minecraftforge/client/model/pipeline/LightUtil.java @@ -19,15 +19,15 @@ package net.minecraftforge.client.model.pipeline; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.model.BakedQuad; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormatElement; import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage; import net.minecraft.util.EnumFacing; import net.minecraftforge.client.ForgeHooksClient; - import org.apache.commons.lang3.tuple.Pair; import java.util.concurrent.ConcurrentHashMap; @@ -120,8 +120,14 @@ public class LightUtil } } + private static final VertexFormat DEFAULT_FROM = VertexLighterFlat.withNormal(DefaultVertexFormats.BLOCK); + private static final VertexFormat DEFAULT_TO = DefaultVertexFormats.ITEM; + private static final int[] DEFAULT_MAPPING = generateMapping(DEFAULT_FROM, DEFAULT_TO); public static int[] mapFormats(VertexFormat from, VertexFormat to) { + //Speedup: in 99.99% this is the mapping, no need to go make a pair, and go through the slower hash map + if (from.equals(DEFAULT_FROM) && to.equals(DEFAULT_TO)) + return DEFAULT_MAPPING; return formatMaps.computeIfAbsent(Pair.of(from, to), pair -> generateMapping(pair.getLeft(), pair.getRight())); } diff --git a/src/main/java/net/minecraftforge/client/model/pipeline/VertexLighterFlat.java b/src/main/java/net/minecraftforge/client/model/pipeline/VertexLighterFlat.java index c66d39a9b3..138655a59d 100644 --- a/src/main/java/net/minecraftforge/client/model/pipeline/VertexLighterFlat.java +++ b/src/main/java/net/minecraftforge/client/model/pipeline/VertexLighterFlat.java @@ -25,6 +25,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.color.BlockColors; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormatElement; import net.minecraft.util.EnumFacing; @@ -107,7 +108,16 @@ public class VertexLighterFlat extends QuadGatheringTransformer updateIndices(); } - private static VertexFormat withNormal(VertexFormat format) + private static final VertexFormat BLOCK_WITH_NORMAL = withNormalUncached(DefaultVertexFormats.BLOCK); + static VertexFormat withNormal(VertexFormat format) + { + //This is the case in 99.99%. Cache the value, so we don't have to redo it every time, and the speed up the equals check in LightUtil + if (format == DefaultVertexFormats.BLOCK) + return BLOCK_WITH_NORMAL; + return withNormalUncached(format); + } + + private static VertexFormat withNormalUncached(VertexFormat format) { if (format == null || format.hasNormal()) return format; return new VertexFormat(format).addElement(NORMAL_4F);