Skip to content

Commit 88eba3b

Browse files
committed
Fix NPE when rendering llama without carpet
1 parent 505c895 commit 88eba3b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/java/de/bluecolored/bluemap/entities/renderer/LlamaRenderer.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@
3434
import de.bluecolored.bluemap.core.util.Key;
3535
import de.bluecolored.bluemap.core.world.Entity;
3636
import de.bluecolored.bluemap.core.world.block.BlockNeighborhood;
37+
import de.bluecolored.bluemap.entities.data.EquipmentData;
38+
import de.bluecolored.bluemap.entities.data.ItemStack;
3739
import de.bluecolored.bluemap.entities.entity.Llama;
3840

41+
import java.util.Optional;
42+
3943
public class LlamaRenderer extends CustomResourceModelRenderer {
4044

4145
private final ResourcePath<Model>
@@ -84,7 +88,13 @@ public void render(Entity entity, BlockNeighborhood block, Part part, TileModelV
8488
}
8589

8690
// decoration model
87-
ResourcePath<Model> decorationModel = switch (llama.getEquipment().getBody().id().getFormatted()) {
91+
ResourcePath<Model> decorationModel = switch (
92+
Optional.ofNullable(llama.getEquipment())
93+
.map(EquipmentData::getBody)
94+
.map(ItemStack::id)
95+
.map(Key::getFormatted)
96+
.orElse("")
97+
) {
8898
case "minecraft:black_carpet" -> LLAMA_CARPET_BLACK;
8999
case "minecraft:blue_carpet" -> LLAMA_CARPET_BLUE;
90100
case "minecraft:brown_carpet" -> LLAMA_CARPET_BROWN;
@@ -101,7 +111,6 @@ public void render(Entity entity, BlockNeighborhood block, Part part, TileModelV
101111
case "minecraft:red_carpet" -> LLAMA_CARPET_RED;
102112
case "minecraft:white_carpet" -> LLAMA_CARPET_WHITE;
103113
case "minecraft:yellow_carpet" -> LLAMA_CARPET_YELLOW;
104-
105114
default -> null;
106115
};
107116
if (decorationModel != null) {

0 commit comments

Comments
 (0)