Advertisement
Guest User

NecromodWorldEvents

a guest
Feb 5th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. @Mod.EventBusSubscriber(modid = Necromod.MODID)
  2. public class NecromodWorldEvents
  3. {  
  4.     private static Method GETCODEC_METHOD;
  5.    
  6.     @SubscribeEvent
  7.     public static void biomeLoadingEvent(final BiomeLoadingEvent event)
  8.     {      
  9.        
  10.         event.getGeneration().getStructures().add(() -> NecromodConfiguredStructures.CONFIGURED_SECRET_ROOM);
  11.         NecromodTreeGeneration.generateTrees(event);       
  12.     }
  13.    
  14.     @SuppressWarnings("unchecked")
  15.     @SubscribeEvent
  16.     public void addDimensionalSpacing(final WorldEvent.Load event)
  17.     {
  18.         if(event.getWorld() instanceof ServerWorld)
  19.         {
  20.             ServerWorld serverWorld = (ServerWorld)event.getWorld();
  21.  
  22.             try
  23.             {
  24.                 if(GETCODEC_METHOD == null) GETCODEC_METHOD = ObfuscationReflectionHelper.findMethod(ChunkGenerator.class, "func_230347_a_");
  25.                 ResourceLocation cgRL = Registry.CHUNK_GENERATOR.getKey((Codec<? extends ChunkGenerator>) GETCODEC_METHOD.invoke(serverWorld.getChunkSource().generator));
  26.                 if(cgRL != null && cgRL.getNamespace().equals("terraforged")) return;
  27.             }
  28.             catch(Exception e)
  29.             {
  30.                 Necromod.LOGGER.error("Was unable to check if " + serverWorld.dimension().location() + " is using Terraforged's ChunkGenerator.");
  31.             }
  32.  
  33.             if(serverWorld.getChunkSource().getGenerator() instanceof FlatChunkGenerator && serverWorld.dimension().equals(World.OVERWORLD))
  34.             {
  35.                 return;
  36.             }
  37.  
  38.             Map<Structure<?>, StructureSeparationSettings> tempMap = new HashMap<>(serverWorld.getChunkSource().generator.getSettings().structureConfig());
  39.             tempMap.putIfAbsent(NecromodStructures.SECRET_ROOM.get(), DimensionStructuresSettings.DEFAULTS.get(NecromodStructures.SECRET_ROOM.get()));
  40.             serverWorld.getChunkSource().generator.getSettings().structureConfig = tempMap;
  41.         }
  42.    }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement