From 25e62d70abfa418f9e7401d376e04fb08d625d99 Mon Sep 17 00:00:00 2001 From: Marcel Konrad Date: Thu, 15 Nov 2018 11:21:55 +0100 Subject: [PATCH] Fix IllegalStateException: Duplicate key --- .../worldhandler/helper/EntityHelper.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/exopandora/worldhandler/helper/EntityHelper.java b/src/main/java/exopandora/worldhandler/helper/EntityHelper.java index 7c5401b..4cacd02 100644 --- a/src/main/java/exopandora/worldhandler/helper/EntityHelper.java +++ b/src/main/java/exopandora/worldhandler/helper/EntityHelper.java @@ -1,13 +1,14 @@ package exopandora.worldhandler.helper; +import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import java.util.stream.Collectors; import javax.annotation.Nullable; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.registry.EntityEntry; import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -15,8 +16,8 @@ import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class EntityHelper { - private static final Map RESOURCELOCATION_TO_NAME; - private static final Map, ResourceLocation> CLASS_TO_RESOURCELOCATION; + private static final Map RESOURCELOCATION_TO_NAME = new HashMap(); + private static final Map, ResourceLocation> CLASS_TO_RESOURCELOCATION = new HashMap, ResourceLocation>(); static { @@ -25,8 +26,11 @@ public class EntityHelper throw new RuntimeException("Accessed Entities before register!"); } - RESOURCELOCATION_TO_NAME = ForgeRegistries.ENTITIES.getEntries().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getName())); - CLASS_TO_RESOURCELOCATION = ForgeRegistries.ENTITIES.getEntries().stream().collect(Collectors.toMap(entry -> entry.getValue().getEntityClass(), Entry::getKey)); + for(Entry entity : ForgeRegistries.ENTITIES.getEntries()) + { + RESOURCELOCATION_TO_NAME.put(entity.getKey(), entity.getValue().getName()); + CLASS_TO_RESOURCELOCATION.put(entity.getValue().getEntityClass(), entity.getKey()); + } } @Nullable