Search in sources :

Example 1 with BounceBugVariant

use of com.toadstoolstudios.sprout.entities.BounceBugVariant in project Sprout by ThatGravyBoat.

the class SpreadShroomOrGrowWartGoal method tick.

@Override
public void tick() {
    World world = bug.getWorld();
    BounceBugVariant variant = bug.getBounceBugVariant();
    if (!world.isClient)
        ((ServerWorld) world).spawnParticles(variant.particleEffect, bug.getX(), bug.getY(), bug.getZ(), 1, 0.1, 0.1, 0.1, 0);
    // noinspection ConstantConditions
    bug.lookAt(bug.getCommandSource().getEntityAnchor(), Vec3d.ofCenter(bug.getTargetPlant()));
    if (isShroom && growTimer % 15 == 1) {
        Box blocks = Box.from(Vec3d.ofCenter(shroomPos)).expand(2, 1, 2);
        BlockPos.stream(blocks).filter(blockPos -> world.getBlockState(blockPos).isAir()).filter(blockPos -> mushroomPredicate(world.getBlockState(shroomPos), world.getBlockState(blockPos.down()), world, blockPos)).forEach(blockPos -> {
            if (world.random.nextInt(30) == 1) {
                if (!world.isClient)
                    ((ServerWorld) world).spawnParticles(variant.particleEffect, blockPos.getX(), blockPos.getY(), blockPos.getZ(), 2, 0.1, 0.1, 0.1, 0.2);
                world.setBlockState(blockPos, world.getBlockState(shroomPos).getBlock().getDefaultState());
            }
        });
    } else if (!isShroom) {
        Box blocks = Box.from(Vec3d.ofCenter(shroomPos)).expand(1, 1, 1);
        BlockPos.stream(blocks).filter(blockPos -> world.getBlockState(blockPos).isOf(Blocks.NETHER_WART)).forEach(blockPos -> {
            BlockState state = world.getBlockState(blockPos);
            if (world.getRandom().nextInt(150) == 1) {
                int age = state.get(NetherWartBlock.AGE);
                if (age < NetherWartBlock.field_31199)
                    world.setBlockState(blockPos, state.with(NetherWartBlock.AGE, age + 1));
            }
        });
    }
    growTimer++;
}
Also used : BounceBugVariant(com.toadstoolstudios.sprout.entities.BounceBugVariant) BounceBugEntity(com.toadstoolstudios.sprout.entities.BounceBugEntity) Goal(net.minecraft.entity.ai.goal.Goal) Vec3d(net.minecraft.util.math.Vec3d) net.minecraft.block(net.minecraft.block) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) Box(net.minecraft.util.math.Box) BlockPos(net.minecraft.util.math.BlockPos) BlockTags(net.minecraft.tag.BlockTags) BounceBugVariant(com.toadstoolstudios.sprout.entities.BounceBugVariant) Box(net.minecraft.util.math.Box) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld)

Aggregations

BounceBugEntity (com.toadstoolstudios.sprout.entities.BounceBugEntity)1 BounceBugVariant (com.toadstoolstudios.sprout.entities.BounceBugVariant)1 net.minecraft.block (net.minecraft.block)1 Goal (net.minecraft.entity.ai.goal.Goal)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 BlockTags (net.minecraft.tag.BlockTags)1 BlockPos (net.minecraft.util.math.BlockPos)1 Box (net.minecraft.util.math.Box)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1