Search in sources :

Example 1 with RandomCollection

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;
}
Also used : TieredBeehiveTileEntity(com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) ApiaryTileEntity(com.teamresourceful.resourcefulbees.tileentity.multiblocks.apiary.ApiaryTileEntity) RandomCollection(com.teamresourceful.resourcefulbees.utils.RandomCollection) EntityOutput(com.teamresourceful.resourcefulbees.api.beedata.outputs.EntityOutput) AABB(net.minecraft.world.phys.AABB) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 2 with RandomCollection

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;
}
Also used : ItemOutput(com.teamresourceful.resourcefulbees.api.beedata.outputs.ItemOutput) RandomCollection(com.teamresourceful.resourcefulbees.utils.RandomCollection) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with 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;
}
Also used : RandomCollection(com.teamresourceful.resourcefulbees.utils.RandomCollection) Block(net.minecraft.world.level.block.Block) BlockOutput(com.teamresourceful.resourcefulbees.api.beedata.outputs.BlockOutput)

Example 4 with 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);
    }
}
Also used : RandomCollection(com.teamresourceful.resourcefulbees.utils.RandomCollection) EntityOutput(com.teamresourceful.resourcefulbees.api.beedata.outputs.EntityOutput)

Aggregations

RandomCollection (com.teamresourceful.resourcefulbees.utils.RandomCollection)4 EntityOutput (com.teamresourceful.resourcefulbees.api.beedata.outputs.EntityOutput)2 BlockOutput (com.teamresourceful.resourcefulbees.api.beedata.outputs.BlockOutput)1 ItemOutput (com.teamresourceful.resourcefulbees.api.beedata.outputs.ItemOutput)1 TieredBeehiveTileEntity (com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity)1 ApiaryTileEntity (com.teamresourceful.resourcefulbees.tileentity.multiblocks.apiary.ApiaryTileEntity)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 ItemStack (net.minecraft.world.item.ItemStack)1 Block (net.minecraft.world.level.block.Block)1 BeehiveBlockEntity (net.minecraft.world.level.block.entity.BeehiveBlockEntity)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 AABB (net.minecraft.world.phys.AABB)1