-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed spawn config back to BiomeDictionary, as it got re-added to F…
…orge Added config option for spawn block, Closes #25
- Loading branch information
1 parent
39198e8
commit 787d8a2
Showing
7 changed files
with
94 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ build | |
# other | ||
eclipse | ||
run | ||
libs | ||
libs | ||
logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
minecraft_version=1.16.3 | ||
forge_version=34.0.7 | ||
mappings=20200723-1.16.1 | ||
mod_version=0.8.9 | ||
minecraft_version=1.16.4 | ||
forge_version=35.0.15 | ||
mappings=20201028-1.16.3 | ||
mod_version=0.8.10 | ||
|
||
org.gradle.jvmargs=-Xmx4G | ||
org.gradle.daemon=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
package com.girafi.waddles.init; | ||
|
||
import com.girafi.waddles.Waddles; | ||
import com.girafi.waddles.utils.BiomeDictionaryHelper; | ||
import com.girafi.waddles.utils.ConfigurationHandler; | ||
import net.minecraft.entity.EntityClassification; | ||
import net.minecraft.util.RegistryKey; | ||
import net.minecraft.util.registry.WorldGenRegistries; | ||
import net.minecraft.world.biome.Biome; | ||
import net.minecraft.world.biome.MobSpawnInfo; | ||
import net.minecraftforge.common.BiomeDictionary; | ||
import net.minecraftforge.event.world.BiomeLoadingEvent; | ||
import net.minecraftforge.eventbus.api.EventPriority; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@Mod.EventBusSubscriber(modid = Waddles.MOD_ID) | ||
public class PenguinSpawn { | ||
|
||
@SubscribeEvent(priority = EventPriority.HIGH) | ||
@SubscribeEvent(priority = EventPriority.HIGH) | ||
public static void addSpawn(BiomeLoadingEvent event) { | ||
Biome biome = ForgeRegistries.BIOMES.getValue(event.getName()); | ||
if (biome != null && (ConfigurationHandler.SPAWN.biomeCategoryBiomes.get().contains(biome.getCategory().getName()) || ConfigurationHandler.SPAWN.additionalBiomes.get().contains(event.getName().toString()))) { | ||
event.getSpawns().getSpawner(EntityClassification.CREATURE).add(new MobSpawnInfo.Spawners(PenguinRegistry.ADELIE_PENGUIN, ConfigurationHandler.SPAWN.weight.get(), ConfigurationHandler.SPAWN.min.get(), ConfigurationHandler.SPAWN.max.get())); | ||
if (event.getName() != null) { | ||
Biome biome = ForgeRegistries.BIOMES.getValue(event.getName()); | ||
if (biome != null && WorldGenRegistries.BIOME.containsKey(event.getName())) { | ||
RegistryKey<Biome> biomeKey = RegistryKey.getOrCreateKey(ForgeRegistries.Keys.BIOMES, event.getName()); | ||
List<BiomeDictionary.Type> includeList = Arrays.asList(BiomeDictionaryHelper.toBiomeTypeArray(ConfigurationHandler.SPAWN.include.get())); | ||
List<BiomeDictionary.Type> excludeList = Arrays.asList(BiomeDictionaryHelper.toBiomeTypeArray(ConfigurationHandler.SPAWN.exclude.get())); | ||
if (!includeList.isEmpty()) { | ||
Set<BiomeDictionary.Type> biomeTypes = BiomeDictionary.getTypes(biomeKey); | ||
if (biomeTypes.stream().noneMatch(excludeList::contains) && biomeTypes.stream().anyMatch(includeList::contains)) { | ||
event.getSpawns().getSpawner(EntityClassification.CREATURE).add(new MobSpawnInfo.Spawners(PenguinRegistry.ADELIE_PENGUIN, ConfigurationHandler.SPAWN.weight.get(), ConfigurationHandler.SPAWN.min.get(), ConfigurationHandler.SPAWN.max.get())); | ||
} | ||
} else { | ||
throw new IllegalArgumentException("Do not leave the BiomeDictionary type inclusion list empty. If you wish to disable spawning of an entity, set the weight to 0 instead."); | ||
} | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/girafi/waddles/utils/BiomeDictionaryHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.girafi.waddles.utils; | ||
|
||
import net.minecraftforge.common.BiomeDictionary; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
public class BiomeDictionaryHelper { | ||
|
||
/** | ||
* Retrieves a #BiomeDictionary.Type | ||
* Based on {@link BiomeDictionary.Type#getType(String, BiomeDictionary.Type...)}, but doesn't create a new {@link BiomeDictionary.Type} if the input is not already a {@link BiomeDictionary.Type} | ||
* | ||
* @param name The name of this #BiomeDictionary.Type | ||
* @return An instance of this #BiomeDictionary.Type | ||
*/ | ||
public static BiomeDictionary.Type getType(String name) { | ||
Map<String, BiomeDictionary.Type> byName = BiomeDictionary.Type.getAll().stream().collect(Collectors.toMap(BiomeDictionary.Type::getName, Function.identity())); | ||
name = name.toUpperCase(); | ||
return byName.get(name); | ||
} | ||
|
||
/** | ||
* Converts a List <? extends String> to a {@link BiomeDictionary.Type} array | ||
* | ||
* @param strings string array containing valid #BiomeDictionary.Types | ||
* @return {@link BiomeDictionary.Type} based on the string input | ||
*/ | ||
public static BiomeDictionary.Type[] toBiomeTypeArray(List<? extends String> strings) { | ||
BiomeDictionary.Type[] types = new BiomeDictionary.Type[strings.size()]; | ||
for (int i = 0; i < strings.size(); i++) { | ||
String string = strings.get(i); | ||
types[i] = getType(string); | ||
} | ||
return types; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters