| 1 | package net.minecraft.world.gen.structure;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.Map;
|
| 5 | import net.minecraft.nbt.NBTTagCompound;
|
| 6 | import net.minecraft.world.World;
|
| 7 | import org.apache.logging.log4j.LogManager;
|
| 8 | import org.apache.logging.log4j.Logger;
|
| 9 |
|
| 10 | public class MapGenStructureIO
|
| 11 | {
|
| 12 | private static final Logger logger = LogManager.getLogger();
|
| 13 | private static Map < String, Class <? extends StructureStart >> startNameToClassMap = Maps. < String, Class <? extends StructureStart >> newHashMap();
|
| 14 | private static Map < Class <? extends StructureStart > , String > startClassToNameMap = Maps. < Class <? extends StructureStart > , String > newHashMap();
|
| 15 | private static Map < String, Class <? extends StructureComponent >> componentNameToClassMap = Maps. < String, Class <? extends StructureComponent >> newHashMap();
|
| 16 | private static Map < Class <? extends StructureComponent > , String > componentClassToNameMap = Maps. < Class <? extends StructureComponent > , String > newHashMap();
|
| 17 |
|
| 18 | private static void registerStructure(Class <? extends StructureStart > startClass, String structureName)
|
| 19 | {
|
| 20 | startNameToClassMap.put(structureName, startClass);
|
| 21 | startClassToNameMap.put(startClass, structureName);
|
| 22 | }
|
| 23 |
|
| 24 | static void registerStructureComponent(Class <? extends StructureComponent > componentClass, String componentName)
|
| 25 | {
|
| 26 | componentNameToClassMap.put(componentName, componentClass);
|
| 27 | componentClassToNameMap.put(componentClass, componentName);
|
| 28 | }
|
| 29 |
|
| 30 | public static String getStructureStartName(StructureStart start)
|
| 31 | {
|
| 32 | return (String)startClassToNameMap.get(start.getClass());
|
| 33 | }
|
| 34 |
|
| 35 | public static String getStructureComponentName(StructureComponent component)
|
| 36 | {
|
| 37 | return (String)componentClassToNameMap.get(component.getClass());
|
| 38 | }
|
| 39 |
|
| 40 | public static StructureStart getStructureStart(NBTTagCompound tagCompound, World worldIn)
|
| 41 | {
|
| 42 | StructureStart structurestart = null;
|
| 43 |
|
| 44 | try
|
| 45 | {
|
| 46 | Class <? extends StructureStart > oclass = (Class)startNameToClassMap.get(tagCompound.getString("id"));
|
| 47 |
|
| 48 | if (oclass != null)
|
| 49 | {
|
| 50 | structurestart = (StructureStart)oclass.newInstance();
|
| 51 | }
|
| 52 | }
|
| 53 | catch (Exception exception)
|
| 54 | {
|
| 55 | logger.warn("Failed Start with id " + tagCompound.getString("id"));
|
| 56 | exception.printStackTrace();
|
| 57 | }
|
| 58 |
|
| 59 | if (structurestart != null)
|
| 60 | {
|
| 61 | structurestart.readStructureComponentsFromNBT(worldIn, tagCompound);
|
| 62 | }
|
| 63 | else
|
| 64 | {
|
| 65 | logger.warn("Skipping Structure with id " + tagCompound.getString("id"));
|
| 66 | }
|
| 67 |
|
| 68 | return structurestart;
|
| 69 | }
|
| 70 |
|
| 71 | public static StructureComponent getStructureComponent(NBTTagCompound tagCompound, World worldIn)
|
| 72 | {
|
| 73 | StructureComponent structurecomponent = null;
|
| 74 |
|
| 75 | try
|
| 76 | {
|
| 77 | Class <? extends StructureComponent > oclass = (Class)componentNameToClassMap.get(tagCompound.getString("id"));
|
| 78 |
|
| 79 | if (oclass != null)
|
| 80 | {
|
| 81 | structurecomponent = (StructureComponent)oclass.newInstance();
|
| 82 | }
|
| 83 | }
|
| 84 | catch (Exception exception)
|
| 85 | {
|
| 86 | logger.warn("Failed Piece with id " + tagCompound.getString("id"));
|
| 87 | exception.printStackTrace();
|
| 88 | }
|
| 89 |
|
| 90 | if (structurecomponent != null)
|
| 91 | {
|
| 92 | structurecomponent.readStructureBaseNBT(worldIn, tagCompound);
|
| 93 | }
|
| 94 | else
|
| 95 | {
|
| 96 | logger.warn("Skipping Piece with id " + tagCompound.getString("id"));
|
| 97 | }
|
| 98 |
|
| 99 | return structurecomponent;
|
| 100 | }
|
| 101 |
|
| 102 | static
|
| 103 | {
|
| 104 | registerStructure(StructureMineshaftStart.class, "Mineshaft");
|
| 105 | registerStructure(MapGenVillage.Start.class, "Village");
|
| 106 | registerStructure(MapGenNetherBridge.Start.class, "Fortress");
|
| 107 | registerStructure(MapGenStronghold.Start.class, "Stronghold");
|
| 108 | registerStructure(MapGenScatteredFeature.Start.class, "Temple");
|
| 109 | registerStructure(StructureOceanMonument.StartMonument.class, "Monument");
|
| 110 | StructureMineshaftPieces.registerStructurePieces();
|
| 111 | StructureVillagePieces.registerVillagePieces();
|
| 112 | StructureNetherBridgePieces.registerNetherFortressPieces();
|
| 113 | StructureStrongholdPieces.registerStrongholdPieces();
|
| 114 | ComponentScatteredFeaturePieces.registerScatteredFeaturePieces();
|
| 115 | StructureOceanMonumentPieces.registerOceanMonumentPieces();
|
| 116 | }
|
| 117 | }
|
| 118 |
|