Skip to content

Commit

Permalink
Fix biomes for turkey and add new supplier system for entity biomes
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeow committed Nov 12, 2019
1 parent 24b023b commit a57bc28
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 44 deletions.
25 changes: 24 additions & 1 deletion src/main/java/its_meow/betteranimalsplus/init/ModEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import its_meow.betteranimalsplus.common.entity.EntityBadger;
import its_meow.betteranimalsplus.common.entity.EntityBear;
Expand Down Expand Up @@ -31,6 +33,7 @@
import its_meow.betteranimalsplus.util.EntityContainer;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.BiomeDictionary.Type;
import net.minecraftforge.fml.common.registry.EntityEntry;
Expand Down Expand Up @@ -66,7 +69,7 @@ public class ModEntities {
add(EntityHorseshoeCrab.class, "horseshoecrab", EnumCreatureType.CREATURE, 0xba1111, 0x520807, BetterAnimalsPlusConfig.horseshoeCrabWeight, 1, 3, true, null, Type.BEACH);
add(EntityShark.class, "shark", EnumCreatureType.WATER_CREATURE, 0x787878, 0xbdbdbd, BetterAnimalsPlusConfig.sharkWeight, 1, 1, true, null, Type.OCEAN);
add(EntityMoose.class, "moose", EnumCreatureType.CREATURE, 0x46351c, 0x97866e, BetterAnimalsPlusConfig.mooseWeight, 1, 1, false, null, Type.SWAMP);
add(EntityTurkey.class, "turkey", EnumCreatureType.CREATURE, 0x857445, 0x5099ba, BetterAnimalsPlusConfig.turkeyWeight, 1, 3, false, null, Type.FOREST);
add(EntityTurkey.class, "turkey", EnumCreatureType.CREATURE, 0x857445, 0x5099ba, BetterAnimalsPlusConfig.turkeyWeight, 2, 5, false, null, () -> BiomeDictionary.getBiomes(Type.FOREST).stream().filter(biome -> !BiomeDictionary.getTypes(biome).contains(Type.SNOWY)).collect(Collectors.toList()).toArray(new Biome[0]));
}

/**
Expand All @@ -88,5 +91,25 @@ public static void add(Class<? extends EntityLiving> EntityClass, String entityN
entityList.add(cont);
entityMap.put(entityNameIn, cont);
}

/**
* Use this to add new entities to be registered
* @param EntityClass - The class of the entity
* @param entityNameIn - The name of the entity. Should be lower case.
* @param type - The type of the entity (EnumCreatureType). This is only used for spawning types. Typically use CREATURE.
* @param solidColorIn - The solid color if the egg (back color) in integer format. You can specify in decimal or hexadecimal form. (0 or 0x000000)
* @param spotColorIn - The spot color of the egg in integer format. See solid color for more.
* @param prob - The random selection spawning weight used at spawn time. E.g. a spawn weight of 20 is 20x more likely to spawn than a weight of 1, and 2x more than 10.
* @param min - The minimum amount of these that can spawn at once (in a group). Must be at least 1 and less than or equal to the maximum.
* @param max - The maximum amount of these that can spawn at once (in a group). Must be at least 1 and greater to or equal to the minimum.
* @param despawn - If the entity despawns by default
* @param tameItems - List of items to tame this animal or null/empty array
* @param biomeSupplier - A function providing a list of default spawn biomes.
*/
public static void add(Class<? extends EntityLiving> EntityClass, String entityNameIn, EnumCreatureType type, int solidColorIn, int spotColorIn, int prob, int min, int max, boolean despawn, String[] tameItems, Supplier<Biome[]> biomeSupplier) {
EntityContainer cont = new EntityContainer(EntityClass, entityNameIn, type, solidColorIn, spotColorIn, prob, min, max, despawn, tameItems, biomeSupplier);
entityList.add(cont);
entityMap.put(entityNameIn, cont);
}

}
114 changes: 71 additions & 43 deletions src/main/java/its_meow/betteranimalsplus/util/EntityContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EnumCreatureType;
Expand All @@ -11,50 +12,77 @@

public class EntityContainer {

public Class<? extends EntityLiving> entityClazz;
public String entityName;
public EnumCreatureType type;
public int eggColorSolid;
public int eggColorSpot;
public int weight;
public int minGroup;
public int maxGroup;
public Biome[] spawnBiomes = {};
public boolean doSpawning = true;
public BiomeDictionary.Type[] types = {};
public String[] tameItems;
public Class<? extends EntityLiving> entityClazz;
public String entityName;
public EnumCreatureType type;
public int eggColorSolid;
public int eggColorSpot;
public int weight;
public int minGroup;
public int maxGroup;
public Biome[] spawnBiomes = {};
public boolean doSpawning = true;
public BiomeDictionary.Type[] types = {};
public String[] tameItems;
public boolean despawn;
public Supplier<Biome[]> biomeSupplier;

@SafeVarargs
public EntityContainer(Class<? extends EntityLiving> EntityClass, String entityNameIn, EnumCreatureType type, int solidColorIn, int spotColorIn, int prob, int min, int max, boolean despawn, String[] tameItems, BiomeDictionary.Type... types) {
this.entityClazz = EntityClass;
this.entityName = entityNameIn;
this.eggColorSolid = solidColorIn;
this.eggColorSpot = spotColorIn;
this.weight = prob;
this.minGroup = min;
this.maxGroup = max;
this.type = type;
if(tameItems == null) {
this.tameItems = new String[0];
} else {
this.tameItems = tameItems;
}

this.types = types;
this.despawn = despawn;
}

public void populateBiomes() {
Set<Biome> biomesetAdd = new HashSet<>();
for(Type type : types) {
biomesetAdd.addAll(BiomeDictionary.getBiomes(type));
}
try {
this.spawnBiomes = biomesetAdd.toArray(this.spawnBiomes);
} catch(NullPointerException e) {
this.spawnBiomes = new Biome[0];
}
}
@SafeVarargs
public EntityContainer(Class<? extends EntityLiving> EntityClass, String entityNameIn, EnumCreatureType type, int solidColorIn, int spotColorIn, int prob, int min, int max, boolean despawn, String[] tameItems, BiomeDictionary.Type... types) {
this.entityClazz = EntityClass;
this.entityName = entityNameIn;
this.eggColorSolid = solidColorIn;
this.eggColorSpot = spotColorIn;
this.weight = prob;
this.minGroup = min;
this.maxGroup = max;
this.type = type;
if(tameItems == null) {
this.tameItems = new String[0];
} else {
this.tameItems = tameItems;
}

this.types = types;
this.despawn = despawn;
}

public EntityContainer(Class<? extends EntityLiving> EntityClass, String entityNameIn, EnumCreatureType type, int solidColorIn, int spotColorIn, int prob, int min, int max, boolean despawn, String[] tameItems, Supplier<Biome[]> getBiomes) {
this.entityClazz = EntityClass;
this.entityName = entityNameIn;
this.eggColorSolid = solidColorIn;
this.eggColorSpot = spotColorIn;
this.weight = prob;
this.minGroup = min;
this.maxGroup = max;
this.type = type;
if(tameItems == null) {
this.tameItems = new String[0];
} else {
this.tameItems = tameItems;
}

this.types = null;
this.biomeSupplier = getBiomes;
this.despawn = despawn;
}

public void populateBiomes() {
if(this.types != null) {
Set<Biome> biomesetAdd = new HashSet<>();
for(Type type : types) {
biomesetAdd.addAll(BiomeDictionary.getBiomes(type));
}
try {
this.spawnBiomes = biomesetAdd.toArray(this.spawnBiomes);
} catch(NullPointerException e) {
this.spawnBiomes = new Biome[0];
}
} else if(this.biomeSupplier != null) {
this.spawnBiomes = biomeSupplier.get();
} else {
this.spawnBiomes = new Biome[0];
}
}

}

0 comments on commit a57bc28

Please sign in to comment.