From 4c44bf23a5a73e5664dcecb317bd8caac86ab630 Mon Sep 17 00:00:00 2001 From: dhyces <10985914+dhyces@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:36:48 -0500 Subject: [PATCH] Simplify RenderStateExtensions --- .../renderstate/RenderStateExtensions.java | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/client/renderstate/RenderStateExtensions.java b/src/main/java/net/neoforged/neoforge/client/renderstate/RenderStateExtensions.java index 63d684c8ac..c4e68082dd 100644 --- a/src/main/java/net/neoforged/neoforge/client/renderstate/RenderStateExtensions.java +++ b/src/main/java/net/neoforged/neoforge/client/renderstate/RenderStateExtensions.java @@ -5,6 +5,7 @@ package net.neoforged.neoforge.client.renderstate; +import com.google.common.collect.ImmutableList; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; @@ -37,31 +38,24 @@ private RenderStateExtensions() {} public static void onUpdateEntityRenderState(EntityRenderer renderer, E entity, S renderState) { renderState.resetRenderData(); var modifiers = (Collection>) (Object) ENTITY_CACHE.computeIfAbsent((Class>) renderer.getClass(), aClass -> { - var list = new ObjectArrayList>(); + var builder = ImmutableList.>builder(); for (var entry : ENTITY.entrySet()) { if (aClass.isAssignableFrom(entry.getKey())) { - list.addAll(entry.getValue()); + builder.addAll(entry.getValue()); } } - if (list.isEmpty()) { - return List.of(); - } - return list; + return builder.build(); }); - if (!modifiers.isEmpty()) { - for (BiConsumer modifier : modifiers) { - modifier.accept(entity, renderState); - } + for (BiConsumer modifier : modifiers) { + modifier.accept(entity, renderState); } } @ApiStatus.Internal public static void onUpdateMapRenderState(MapItemSavedData mapItemSavedData, MapRenderState renderState) { renderState.resetRenderData(); - if (!MAP.isEmpty()) { - for (BiConsumer modifier : MAP) { - modifier.accept(mapItemSavedData, renderState); - } + for (BiConsumer modifier : MAP) { + modifier.accept(mapItemSavedData, renderState); } } @@ -69,10 +63,8 @@ public static void onUpdateMapRenderState(MapItemSavedData mapItemSavedData, Map public static MapRenderState.MapDecorationRenderState onUpdateMapDecorationRenderState(Holder mapDecorationTypeHolder, MapItemSavedData mapItemSavedData, MapRenderState mapRenderState, MapRenderState.MapDecorationRenderState mapDecorationRenderState) { mapDecorationRenderState.resetRenderData(); var modifiers = MAP_DECORATION.getOrDefault(mapDecorationTypeHolder.getKey(), List.of()); - if (!modifiers.isEmpty()) { - for (var modifier : modifiers) { - modifier.accept(mapItemSavedData, mapRenderState, mapDecorationRenderState); - } + for (var modifier : modifiers) { + modifier.accept(mapItemSavedData, mapRenderState, mapDecorationRenderState); } return mapDecorationRenderState; }