use of com.teamresourceful.resourcefulbees.utils.RandomCollection in project ResourcefulBees by Resourceful-Bees.
the class ResourcefulBee method mutateEntity.
public boolean mutateEntity() {
AABB box = this.getMutationBoundingBox();
List<Entity> entityList = this.level.getEntities(this, box, entity -> getMutationData().getEntityMutations().get(entity.getType()) != null);
if (!entityList.isEmpty()) {
Map<EntityType<?>, RandomCollection<EntityOutput>> entityMutations = getMutationData().getEntityMutations();
RandomCollection<EntityOutput> output = entityMutations.get(entityList.get(0).getType());
if (output != null) {
EntityOutput entityOutput = output.next();
if (entityOutput.getChance() >= level.random.nextFloat()) {
CompoundTag nbt = new CompoundTag();
nbt.put("EntityTag", entityOutput.getCompoundNBT().orElse(null));
entityOutput.getEntityType().spawn((ServerLevel) level, nbt, null, null, entityList.get(0).blockPosition(), MobSpawnType.NATURAL, false, false);
entityList.get(0).remove();
level.levelEvent(2005, this.blockPosition().below(1), 0);
}
incrementNumCropsGrownSincePollination();
return true;
}
}
return false;
}
use of com.teamresourceful.resourcefulbees.utils.RandomCollection in project ResourcefulBees by Resourceful-Bees.
the class MutationData method createRandomItemCollection.
private RandomCollection<ItemOutput> createRandomItemCollection(Mutation mutation) {
RandomCollection<ItemOutput> randomCollection = new RandomCollection<>();
mutation.getOutputs().forEach(mutationOutput -> {
ItemStack output = new ItemStack(ForgeRegistries.ITEMS.getValue(mutationOutput.getOutput()), mutationOutput.getCount());
if (!output.equals(ItemStack.EMPTY)) {
output.setTag(mutationOutput.getNbt());
randomCollection.add(mutationOutput.getWeight(), new ItemOutput(output, mutationOutput.getWeight(), mutation.getChance()));
}
});
return randomCollection;
}
use of com.teamresourceful.resourcefulbees.utils.RandomCollection in project ResourcefulBees by Resourceful-Bees.
the class MutationData method createRandomBlockCollection.
private RandomCollection<BlockOutput> createRandomBlockCollection(Mutation mutation) {
RandomCollection<BlockOutput> randomCollection = new RandomCollection<>();
mutation.getOutputs().forEach(mutationOutput -> {
Block output = ForgeRegistries.BLOCKS.getValue(mutationOutput.getOutput());
if (output != (Blocks.AIR)) {
randomCollection.add(mutationOutput.getWeight(), new BlockOutput(output, Optional.of(mutationOutput.getNbt()), mutationOutput.getWeight(), mutation.getChance()));
}
});
return randomCollection;
}
use of com.teamresourceful.resourcefulbees.utils.RandomCollection in project ResourcefulBees by Resourceful-Bees.
the class MutationData method addEntityMutation.
private void addEntityMutation(Mutation mutation) {
EntityType<?> input = mutation.getEntityInput().orElse(null);
RandomCollection<EntityOutput> randomCollection = new RandomCollection<>();
mutation.getOutputs().forEach(mutationOutput -> {
if (mutationOutput.getOutput() != null) {
EntityType<?> output = BeeInfoUtils.getEntityType(mutationOutput.getOutput());
if (output != null) {
randomCollection.add(mutationOutput.getWeight(), new EntityOutput(output, Optional.of(mutationOutput.getNbt()), mutationOutput.getWeight(), mutation.getChance()));
}
}
});
if (input != null && !randomCollection.isEmpty()) {
entityMutations.put(input, randomCollection);
}
}
Aggregations